Add core.fs stdlib: comparison, range, numeric helpers#28
Open
sigilante wants to merge 1 commit into
Open
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:<=,>=,0<>,U<=,U>=— defined in terms of existing primitives (>,<,0=,NOT,U<,U>).WITHIN ( n lo hi -- f )— true ifflo <= n < hi, standard semantics.SQUARED,CUBED.?— 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.shnow readscore.fs, escapes it into aCORE_SRCshell 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 forWITHIN, zero-and-nonzero cases for the numeric helpers, and anALLOT/!/?sequence for?.Test plan
bash tests/test-north.sh— 341 passed, 0 failed (was 317 before)INCLUDE /lib/corethen exercise a few words — requires copyingcore.fsonto the ship desk🤖 Generated with Claude Code