datalog: unification + substitution + 28 tests (Phase 2, 72/72)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 53s
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 53s
dl-unify returns immutable extended subst dict (or nil). dl-walk chases bindings, dl-apply-subst recursively resolves vars. Lists unify element-wise so arithmetic compounds work too. dl-ground? and dl-vars-of for safety analysis (Phase 3).
This commit is contained in:
@@ -75,10 +75,12 @@ Key differences from Prolog:
|
||||
Conformance harness: `bash lib/datalog/conformance.sh` → 44 / 44 passing.
|
||||
|
||||
### Phase 2 — unification + substitution
|
||||
- [ ] Share or port unification from `lib/prolog/` — term walk, occurs check off by default
|
||||
- [ ] `dl-unify` `t1` `t2` `subst` → extended subst or nil (no function symbols means simpler)
|
||||
- [ ] `dl-ground?` `term` → bool — all variables bound in substitution
|
||||
- [ ] Tests: atom/atom, var/atom, var/var, list args
|
||||
- [x] Ported (not shared) from `lib/prolog/` — term walk, no occurs check.
|
||||
- [x] `dl-unify t1 t2 subst` → extended subst dict, or `nil` on failure.
|
||||
- [x] `dl-walk`, `dl-bind`, `dl-apply-subst`, `dl-ground?`, `dl-vars-of`.
|
||||
- [x] Substitutions are immutable dicts keyed by variable name (string).
|
||||
Lists/tuples unify element-wise (used for arithmetic compounds too).
|
||||
- [x] Tests in `lib/datalog/tests/unify.sx` (28). 72 / 72 conformance.
|
||||
|
||||
### Phase 3 — extensional DB + naive evaluation
|
||||
- [ ] EDB: `{:relation-name → set-of-ground-tuples}` using SX sets (Phase 18 of primitives)
|
||||
@@ -147,6 +149,12 @@ _(none yet)_
|
||||
|
||||
_Newest first._
|
||||
|
||||
- 2026-05-07 — Phase 2 done. `lib/datalog/unify.sx` (~140 LOC):
|
||||
`dl-var?` (case + underscore), `dl-walk`, `dl-bind`, `dl-unify` (returns
|
||||
extended dict subst or `nil`), `dl-apply-subst`, `dl-ground?`, `dl-vars-of`.
|
||||
Substitutions are immutable dicts; `assoc` builds extended copies. 28
|
||||
unify tests; conformance now 72 / 72.
|
||||
|
||||
- 2026-05-07 — Phase 1 done. `lib/datalog/tokenizer.sx` (~190 LOC) emits
|
||||
`{:type :value :pos}` tokens; `lib/datalog/parser.sx` (~150 LOC) produces
|
||||
`{:head … :body …}` / `{:query …}` clauses, with nested compounds
|
||||
|
||||
Reference in New Issue
Block a user