Add example programs and test suite for North Forth#23
Merged
Conversation
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>
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.
Adds five example programs under examples/ demonstrating key language capabilities, with a corresponding test suite (tests/test-examples.sh, make test-examples).
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].