Skip to content

Add core.fs stdlib: comparison, range, numeric helpers#28

Open
sigilante wants to merge 1 commit into
masterfrom
sigilante/core-stdlib
Open

Add core.fs stdlib: comparison, range, numeric helpers#28
sigilante wants to merge 1 commit into
masterfrom
sigilante/core-stdlib

Conversation

@sigilante
Copy link
Copy Markdown
Owner

Summary

First cut of North's Forth-defined standard library, layered on top of the interpreter primitives.

desk/lib/core.fs — 9 words across three groups:

  • Comparison shorthands: <=, >=, 0<>, U<=, U>= — defined in terms of existing primitives (>, <, 0=, NOT, U<, U>).
  • Range test: WITHIN ( n lo hi -- f ) — true iff lo <= n < hi, standard semantics.
  • Numeric helpers: SQUARED, CUBED.
  • Debug: ? — fetch-and-print (@ .).

Uses paren comments throughout so the file can be flattened to a single line for tooling that does not preserve newlines (notably the test harness).

Test harness wiring

tests/test-north.sh now reads core.fs, escapes it into a CORE_SRC shell variable, and prepends it to each core-stdlib test's Forth source. This exercises both the parse/compile path (the : definitions) and the runtime behavior on every run — unlike the existing token-list tests, which bypass parsing.

Added a === Core stdlib === section with 24 new tests covering boundaries (equal, below, above) for each comparison, all five regions for WITHIN, zero-and-nonzero cases for the numeric helpers, and an ALLOT/!/? sequence for ?.

Test plan

  • bash tests/test-north.sh341 passed, 0 failed (was 317 before)
  • Manual smoke test in the shoe REPL: INCLUDE /lib/core then exercise a few words — requires copying core.fs onto the ship desk

🤖 Generated with Claude Code

Introduces desk/lib/core.fs, a first cut of the Forth-defined standard
library layered on top of the interpreter primitives. Includes <=, >=,
0<>, U<=, U>= comparison shorthands; WITHIN range test; SQUARED/CUBED
numeric helpers; and ? fetch-and-print debug.

Uses paren comments throughout so the file can be flattened to a single
line for tooling that does not preserve newlines (notably the urbit-eval
test harness).

tests/test-north.sh flattens core.fs into a CORE_SRC shell variable and
adds a Core stdlib section exercising each word (24 new tests).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant