Skip to content

JS WAM: string_length/2 and writeq/~q nested quoting - #4205

Open
s243a wants to merge 1 commit into
grok/wamjs-string-tagfrom
grok/wamjs-string-polish
Open

JS WAM: string_length/2 and writeq/~q nested quoting#4205
s243a wants to merge 1 commit into
grok/wamjs-string-tagfrom
grok/wamjs-string-polish

Conversation

@s243a

@s243a s243a commented Aug 31, 2026

Copy link
Copy Markdown
Owner

D34 residuals on the JS WAM string tag: string_length/2 and writeq/1 / recursive ~q quoting.

Branched from grok/wamjs-string-tag and extended it (net additions). No INTEGRATION_PATCH.md.

What landed

  • string_length/2 — accepts a string, atom, or number (text form); binds the Unicode code-point length. string_length("abc", N)N = 3.
  • writeq/1 registered. The quoted writer (quoted_term_to_string) is the same path format ~q uses. It now recurses through lists and compounds:
    • strings render double-quoted: writeq("ab")"ab"; writeq(["ab", foo])["ab",foo]
    • atoms quote only when needed (see subset)
  • write/1 is unchanged (string text unquoted; list spacing still ", ").

Atom-quoting subset (SWI-like, pragmatic)

Unquoted: [], !, ;, {}, ^[a-z][A-Za-z0-9_]*$, and ISO graphic atoms (#$&*+-./:<=>?@^~\) except the lone atom . (end-of-term). Quoted otherwise; escapes \\ and \' only.

Tests (local, all green)

  1. tests/test_wam_javascript_builtins.pl including probe_string_polish and string_polish_output
  2. tests/test_wam_javascript_lowered.pl and tests/test_wam_javascript_fact_sources.pl
  3. Official CONFORMANCE_TARGETS=javascript harness exits 0 (adapter still unpatched; local 48-query stand-in stays 48/48)
  4. SWI vs Node dumps match for string_length, writeq (string / quoted atom / bare atom / []), write of a string, and nested ~q

Residuals (unchanged / documented)

  • Compiled "foo" literals still collapse to atoms (wam_target.pl out of scope)
  • Fact-source cells stay atoms
  • No \n/\t escapes in writeq
  • Brace terms {a} not special-cased
Open in Web Open in Cursor 

Register string_length/2 (string/atom/number, code-point length) and
writeq/1. The quoted writer now walks lists and compounds so nested
strings render as "…" and atoms quote only when SWI needs it.

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