Skip to content

Add term_variables/2, numbervars/3, and =@=/2 to the JS WAM - #4197

Open
s243a wants to merge 2 commits into
grok/wamjs-fact-sourcesfrom
grok/wamjs-term-meta
Open

Add term_variables/2, numbervars/3, and =@=/2 to the JS WAM#4197
s243a wants to merge 2 commits into
grok/wamjs-fact-sourcesfrom
grok/wamjs-term-meta

Conversation

@s243a

@s243a s243a commented Aug 30, 2026

Copy link
Copy Markdown
Owner

Closes G-W3 follow-up: the JS WAM was missing term_variables/2, numbervars/3, =@=/2, and \=@=/2.

Semantics (SWI)

  • term_variables(+Term,-List): distinct unbound vars, first-occurrence L-to-R depth-first.
  • numbervars(+Term,+Start,-End): bind+trail each distinct unbound var to '$VAR'(N) from Start; End is Start+count. write/1 prints '$VAR'(N) literally (no letter-style A/B rendering).
  • =@=/2: variant equality (ground as ==; vars via a consistent bijection). \=@=/2 is the negation.

Walks reuse the copy_term deref + seen cycle guard.

Tests (green locally)

swipl -q -g run_tests -t halt tests/test_wam_javascript_builtins.pl
swipl -q -g run_tests -t halt tests/test_wam_javascript_lowered.pl
swipl -q -g run_tests -t halt tests/test_wam_javascript_fact_sources.pl

Parser probes, fact sources, 48-query local suite, and lowered emitter stay green.

Branched from grok/wamjs-fact-sources and extended it. Shared files are not edited.

Open in Web Open in Cursor 

cursoragent and others added 2 commits August 30, 2026 17:57
Port the Rust/Clojure term-meta walks onto the existing copy_term
depth-first deref walk. numbervars binds+trails '$VAR'(N). =@= uses a
consistent var bijection; \=@= is its negation. write/1 still prints
'$VAR'(N) literally, not SWI letter rendering.

Co-authored-by: johns243a <johns243a@gmail.com>
\+ compiled as ITE undoes Y registers allocated only inside the try
branch, so f(T,T) \=@= f(U,V) must mention T/U/V first.

Co-authored-by: johns243a <johns243a@gmail.com>
@s243a
s243a marked this pull request as ready for review August 30, 2026 17:58
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.

2 participants