Skip to content

Add file-backed P/2 fact sources to the JavaScript WAM - #4195

Open
s243a wants to merge 2 commits into
grok/wamjs-parserfrom
grok/wamjs-fact-sources
Open

s243a wants to merge 2 commits into
grok/wamjs-parserfrom
grok/wamjs-fact-sources

Conversation

@s243a

@s243a s243a commented Aug 30, 2026

Copy link
Copy Markdown
Owner

Closes G-W4: the JS WAM had only an empty fact_sources: {} scaffold, so every fact had to be compiled inline.

What changed

Lightweight file-backed P/2 facts, modeled on Lua's lua_fact_sources/1:

  • Option javascript_wam_fact_sources([source(P/2, file(Path))]) (alias js_fact_sources/1).
  • Matching predicates emit I.CallFactStream + I.Proceed() instead of inline WAM.
  • Node runtime reads TSV/CSV (tab if present, else comma) or JSONL ([a,b], {a1,a2}, {args:[...]}) via fs.readFileSync. No npm deps.
  • First-arg index when A1 is bound; multi-solution via the existing fact_stream choice point.
  • Cell values go through parse_term (int/float/atom/compound).
  • Inline-facts path (no option) is unchanged.

LMDB / CSR are out of scope (same as Lua).

Tests (green locally)

swipl -q -g run_tests -t halt tests/test_wam_javascript_fact_sources.pl
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

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

Branching

Branched from grok/wamjs-parser and extended it (net additions). Shared files are not edited (INTEGRATION_PATCH.md unchanged).

Open in Web Open in Cursor 

cursoragent and others added 2 commits August 30, 2026 17:32
javascript_wam_fact_sources/1 (Lua-shaped) emits CallFactStream instead
of inline WAM and loads TSV/CSV or JSONL at runtime via Node fs. First-arg
indexing when A1 is bound. No new npm dependency; inline facts unchanged.
LMDB/CSR stay out of scope.

Co-authored-by: johns243a <johns243a@gmail.com>
js_fs_probe called js_fs_has/2, which the TSV/JSONL compiles omitted.
The CSV suite still exercises the caller via CLI.

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