Skip to content

forth: add tests for definitions that use built-in words - #2702

Closed
rabestro wants to merge 1 commit into
exercism:mainfrom
rabestro:forth-builtin-word-binding
Closed

rabestro wants to merge 1 commit into
exercism:mainfrom
rabestro:forth-builtin-word-binding

Conversation

@rabestro

Copy link
Copy Markdown
Member

The existing tests check that a definition keeps the meaning its words had when it was defined, but only for user-defined words:

  • : foo 5 ; : bar foo ; : foo 6 ; bar foo → [5, 6]
  • : foo 10 ; : foo foo 1 + ; foo → [11]

Nothing checks the same rule for built-in words. A solution that expands user-defined words at definition time but leaves built-ins as names to look up later passes the whole suite, yet:

  • : sum + ; : + * ; 2 3 sum gives [6] instead of [5]
  • : dup dup dup ; 1 dup never terminates, because dup keeps expanding into itself

This PR adds those two cases, next to the two existing ones.

Notes:

  • No existing case is changed, and neither case requires an error for an undefined word inside a definition, which was the contested part of the earlier discussion.
  • A solution with the bug loops forever on the second case instead of failing an assertion, so tracks will see it as a timeout.

Related: #1800, https://forum.exercism.org/t/forth-test-suite-may-not-be-complete/11676

🤖 Generated with Claude Code

@rabestro rabestro self-assigned this Nov 12, 2026
The existing tests check that a definition keeps the meaning its words
had when it was defined, but only for user-defined words. Add the same
checks for built-in words.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@rabestro
rabestro force-pushed the forth-builtin-word-binding branch from 7e60ec3 to 9b65f28 Compare November 12, 2026 10:12
Comment on lines +527 to +533
"instructions": [
": sum + ;",
": + * ;",
"2 3 sum"
]
},
"expected": [5]

@glennj glennj Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 5 sum 2 5 + with expected [7, 10] would be a bit more illustrative.

@IsaacG

IsaacG commented Nov 12, 2026

Copy link
Copy Markdown
Member

Please follow the standard process of opening a forum thread to discuss problem spec changes first. Problem spec PRs should only be opened after three maintainers have given approval on the forum.

@IsaacG IsaacG closed this Nov 12, 2026
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.

3 participants