datalog: reject compound terms in fact / rule-head args
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 25s
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 25s
Datalog has no function symbols in argument positions, but the
existing dl-add-fact! / dl-add-rule! validators only checked that
literals were ground (no free variables). A compound like `+(1, 2)`
contains no variables, so:
p(+(1, 2)).
=> stored as the unreduced tuple `(p (+ 1 2))`
double(*(X, 2)) :- n(X). n(3).
=> saturates `double((* 3 2))` instead of `double(6)`
Added dl-simple-term? (number / string / symbol) and an
args-simple? walker, used by:
- dl-add-fact!: all args must be simple terms
- dl-add-rule!: rule head args must be simple terms (variables
are symbols, so they pass)
Compounds remain legal in body literals where they encode `is` /
arithmetic / aggregate sub-goals. Error messages name the offending
literal and point the user at the body-only mechanism.
2 new regression tests; conformance 271/271.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -15,7 +15,7 @@ for rose-ash data (e.g. federation graph, content relationships).
|
||||
|
||||
## Status (rolling)
|
||||
|
||||
`bash lib/datalog/conformance.sh` → **269/269 across 11 suites**
|
||||
`bash lib/datalog/conformance.sh` → **271/271 across 11 suites**
|
||||
(tokenize, parse, unify, eval, builtins, semi_naive, negation, aggregates,
|
||||
api, magic, demo). Source is ~3100 LOC, tests ~2900 LOC, public API
|
||||
documented in `lib/datalog/datalog.sx`.
|
||||
@@ -320,6 +320,16 @@ large graphs.
|
||||
|
||||
_Newest first._
|
||||
|
||||
- 2026-05-11 — Compound terms in fact-arg / rule-head positions were
|
||||
silently stored as unreduced expressions. `p(+(1, 2)).` resulted
|
||||
in a tuple `(p (+ 1 2))` (dl-ground? sees no free variables, so it
|
||||
passed). `double(*(X, 2)) :- n(X).` saturated to `double((* 3 2))`
|
||||
rather than `double(6)`. Datalog has no function symbols in arg
|
||||
positions — `dl-add-fact!` and `dl-add-rule!` now reject compound
|
||||
args via a new `dl-simple-term?` (number / string / symbol).
|
||||
Compounds remain legal in body literals where they encode `is` /
|
||||
arithmetic / aggregate sub-goals. 2 new regression tests; 271/271.
|
||||
|
||||
- 2026-05-11 — Quoted atoms with uppercase-or-underscore-leading
|
||||
names were misclassified as variables. `p('Hello World').` ran
|
||||
through the tokenizer's `"atom"` branch and through the parser's
|
||||
|
||||
Reference in New Issue
Block a user