Two new words in crates/compiler/stdlib/imath.seq: #452

Merged
navicore merged 2 commits from bits-fmt into main 2026-05-04 20:07:54 +00:00
Owner

Two new words in crates/compiler/stdlib/imath.seq:

  • int->bits-fmt-8 ( Int -- String ) — 40 int->bits-fmt-8 → "0010 1000"
  • int->bits-fmt-16 ( Int -- String ) — 40 int->bits-fmt-16 → "0000 0000 0010 1000"

Built on int->bits-padded + string.substring — slice into 4-char nibbles, glue back
with single-space separators. Header doc + Examples block updated; test cases cover
zero, the example value (40), all-ones in 8 bits (255 / 0xFF), the alternating
pattern in 16 bits (43690 / 0xAAAA), low bit only, and the high+low corner case
(32769 = 0x8001).

Two new words in crates/compiler/stdlib/imath.seq: - int->bits-fmt-8 ( Int -- String ) — 40 int->bits-fmt-8 → "0010 1000" - int->bits-fmt-16 ( Int -- String ) — 40 int->bits-fmt-16 → "0000 0000 0010 1000" Built on int->bits-padded + string.substring — slice into 4-char nibbles, glue back with single-space separators. Header doc + Examples block updated; test cases cover zero, the example value (40), all-ones in 8 bits (255 / 0xFF), the alternating pattern in 16 bits (43690 / 0xAAAA), low bit only, and the high+low corner case (32769 = 0x8001).
Two new words in crates/compiler/stdlib/imath.seq:
Some checks failed
CI - Linux / CI - Linux x86_64 (pull_request) Failing after 48s
e67fde0027
- int->bits-fmt-8 ( Int -- String ) — 40 int->bits-fmt-8 → "0010 1000"
  - int->bits-fmt-16 ( Int -- String ) — 40 int->bits-fmt-16 → "0000 0000 0010 1000"

  Built on int->bits-padded + string.substring — slice into 4-char nibbles, glue back
  with single-space separators. Header doc + Examples block updated; test cases cover
  zero, the example value (40), all-ones (255 / 43690 = 0xAAAA), low bit only, and the
  high+low corner case (32769 = 0x8001).
Author
Owner

Nits (none blocking)

  1. PR description has a small factual error: it says "all-ones (255 / 43690 = 0xAAAA)". 43690 = 0xAAAA is the
    alternating pattern (1010 1010 1010 1010), not all-ones (that would be 65535 / 0xFFFF). The test values
    themselves are correct — only the prose mislabels what the value represents. Worth fixing in the PR description
    but not in code.
  2. Negative-input behavior is inherited from int->bits-padded (truncates to low N bits, with the lossy-shr
    footnote already on file). Not tested or documented for the new words. Defensible: the new words are pure
    formatters built on int->bits-padded, so anyone hitting a confusing result with a negative will land on the
    existing header note. Optional one-liner cross-reference if you want belt-and-suspenders.
  3. No shared helper between fmt-8 and fmt-16. Could factor out a ( s nibble-index --
    s+nibble-with-trailing-space ) helper, but with only two consumers the duplication is fine and the explicit
    shape is easier to debug.
  4. Wider variants (-32, -63) not added. YAGNI — easy to add later if a use case shows up. The 8/16 split matches
    the natural inspection widths for the bitwise stdlib.

Style

  • Header doc + Examples block updated in lockstep with the new words. ✓
  • Stack-effect comments at each step inside the word body. ✓
  • Naming consistent with int->bits / int->bits-padded. ✓

Nothing in scope to change. Optional: tweak the PR description's "all-ones" wording.

Nits (none blocking) 1. PR description has a small factual error: it says "all-ones (255 / 43690 = 0xAAAA)". 43690 = 0xAAAA is the alternating pattern (1010 1010 1010 1010), not all-ones (that would be 65535 / 0xFFFF). The test values themselves are correct — only the prose mislabels what the value represents. Worth fixing in the PR description but not in code. 2. Negative-input behavior is inherited from int->bits-padded (truncates to low N bits, with the lossy-shr footnote already on file). Not tested or documented for the new words. Defensible: the new words are pure formatters built on int->bits-padded, so anyone hitting a confusing result with a negative will land on the existing header note. Optional one-liner cross-reference if you want belt-and-suspenders. 3. No shared helper between fmt-8 and fmt-16. Could factor out a ( s nibble-index -- s+nibble-with-trailing-space ) helper, but with only two consumers the duplication is fine and the explicit shape is easier to debug. 4. Wider variants (-32, -63) not added. YAGNI — easy to add later if a use case shows up. The 8/16 split matches the natural inspection widths for the bitwise stdlib. Style - Header doc + Examples block updated in lockstep with the new words. ✓ - Stack-effect comments at each step inside the word body. ✓ - Naming consistent with int->bits / int->bits-padded. ✓ Nothing in scope to change. Optional: tweak the PR description's "all-ones" wording.
fix linux tests
All checks were successful
CI - Linux / CI - Linux x86_64 (pull_request) Successful in 4m24s
45bfa044bb
navicore deleted branch bits-fmt 2026-05-04 20:07:54 +00:00
Sign in to join this conversation.
No description provided.