JS WAM: distinct string term tag - #4204
Open
s243a wants to merge 3 commits into
Open
Conversation
Introduce V.String and thread it through unify, ==, copy_term, write, compare/sort (Atom < String < Compound). String-producing builtins (atom_string, string_concat, string_chars, string_to_atom, number_string, split_string) now yield strings; compiled Prolog string constants emit as V.String. Co-authored-by: johns243a <johns243a@gmail.com>
The shared WAM tokeniser stores every constant as text, so treating string(C) as V.String rewrote atoms and broke unify. Strings come from builtins and the Pratt \"...\" reader. Standard order matches SWI 9.0.4 (String @< Atom). Co-authored-by: johns243a <johns243a@gmail.com>
String sorts before Atom on this SWI (compare(foo,"foo") = >). Co-authored-by: johns243a <johns243a@gmail.com>
s243a
marked this pull request as ready for review
August 30, 2026 20:17
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.
G-W3 residual: the JS WAM now has a distinct
stringtag (V.String) instead of interning SWI strings as atoms.Branched from
grok/wamjs-op3and extended it (net additions). NoINTEGRATION_PATCH.md.What landed
V.String(s)alongside atom/int/float/var/struct.deref, unify (string unifies only with an equal string, never an atom of the same text),copy_term,==/\==, andcompare/3/sorthandle the tag."foo" @< foo/compare(foo, "foo")is>. The older “Atom < String” manual line is not this SWI version.atom/1is false for strings;string/1is true only for the tag.V.String:atom_string/2string_concat/3(atom_concat still produces atoms)string_chars/2construct (decompose is still a list of one-char atoms)string_to_atom/2number_string/2split_string/4(list of strings)write/1prints the text without quotes (SWIwrite).format~qquotes with"."..."as the string tag.Compiled constants stay atoms. The shared WAM tokeniser stores every constant as a Prolog string token, so wrapping
put_constantinV.Stringwould rewrite atoms/ints and break the 48-query suite. Construct strings via builtins or the Pratt"..."reader.Tests
probe_string_tag/0intests/test_wam_javascript_builtins.pl:atom_string(a, S), string(S), \+ atom(S)split_string('a,b,c', ',', '', Parts)is a list of stringsstring_concat(x, y, Z)yields a stringsort([foo, SFoo, 1, bar], L)→[1, SFoo, bar, foo]Local acceptance:
tests/test_wam_javascript_builtins.plgreen (incl. new probe)tests/test_wam_javascript_lowered.plandtests/test_wam_javascript_fact_sources.plgreenCONFORMANCE_TARGETS=javascriptharness exits 0 (adapter still unpatched; local 48-query stand-in in the builtins file stays 48/48)string/1,atom_string,split_string,string_concat, and standard-ordersortResiduals
writeq/1is not registered as a standalone builtin (quoted rendering is viaformat~q)"foo"literals collapse to atomfoo(shared WAM constant tokens; cannot fix without editingwam_target.pl)string_length/2not addedformat('~q', [List])does not quote nested strings (list walk useswrite, notwriteq)