Skip to content

Add example programs and test suite for North Forth#23

Merged
sigilante merged 2 commits intomasterfrom
sigilante/examples
Apr 13, 2026
Merged

Add example programs and test suite for North Forth#23
sigilante merged 2 commits intomasterfrom
sigilante/examples

Conversation

@sigilante
Copy link
Copy Markdown
Owner

Adds five example programs under examples/ demonstrating key language capabilities, with a corresponding test suite (tests/test-examples.sh, make test-examples).

  • fibonacci.fs iterative fib(n) using two VARIABLE cells
  • ackermann.fs recursive Ackermann-Péter via RECURSE
  • sieve.fs Sieve of Eratosthenes with HERE/ALLOT array
  • charclass.fs isdigit/isupper/islower/isalpha/isalnum/isspace/toupper/tolower
  • wordcount.fs count-words with pre-stored demo strings (no S" quoting needed)

Each .fs file is stripped of \ comments and embedded in a Hoon tape literal, following the same pattern as tests/test-nock.sh. Boolean results are normalised with "1 AND" so tests compare [1]/[0].

sigilante and others added 2 commits April 13, 2026 14:02
Adds five example programs under examples/ demonstrating key
language capabilities, with a corresponding test suite
(tests/test-examples.sh, make test-examples).

- fibonacci.fs   iterative fib(n) using two VARIABLE cells
- ackermann.fs   recursive Ackermann-Péter via RECURSE
- sieve.fs       Sieve of Eratosthenes with HERE/ALLOT array
- charclass.fs   isdigit/isupper/islower/isalpha/isalnum/isspace/toupper/tolower
- wordcount.fs   count-words with pre-stored demo strings (no S" quoting needed)

Each .fs file is stripped of \ comments and embedded in a Hoon tape
literal, following the same pattern as tests/test-nock.sh.  Boolean
results are normalised with "1 AND" so tests compare ~[1]/~[0].

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
North's DO LOOP (like ANS Forth) always executes the body at least
once, so '0 0 DO ... LOOP' iterated once rather than zero times.
For fib(2), '2 - 0 DO' became '0 0 DO' causing fib(2)=2 instead of 1.

Replaced with a counted BEGIN/WHILE/REPEAT loop that correctly
iterates zero times when n=2.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@sigilante sigilante merged commit af11462 into master Apr 13, 2026
2 checks passed
@sigilante sigilante deleted the sigilante/examples branch April 13, 2026 19:45
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