mk: phase 4A — appendo canary green, both directions
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 23s
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 23s
Three coupled fixes plus a new relations module land together because
each is required for the next: appendo can't terminate without all
three.
1. unify.sx — added (:cons h t) tagged cons-cell shape because SX has no
improper pairs. The unifier treats (:cons h t) and the native list
(h . t) as equivalent. mk-walk* re-flattens cons cells back to flat
lists for clean reification.
2. stream.sx — switched mature stream cells from plain SX lists to a
(:s head tail) tagged shape so a mature head can have a thunk tail.
With the old representation, mk-mplus had to (cons head thunk) which
SX rejects (cons requires a list cdr).
3. conde.sx — wraps each clause in Zzz (inverse-eta delay) for laziness.
Zzz uses (gensym "zzz-s-") for the substitution parameter so it does
not capture user goals that follow the (l s ls) convention. Without
gensym, every relation that uses `s` as a list parameter silently
binds it to the substitution dict.
relations.sx is the new module: nullo, pairo, caro, cdro, conso,
firsto, resto, listo, appendo, membero. 25 new tests.
Canary green:
(run* q (appendo (list 1 2) (list 3 4) q))
→ ((1 2 3 4))
(run* q (fresh (l s) (appendo l s (list 1 2 3)) (== q (list l s))))
→ ((() (1 2 3)) ((1) (2 3)) ((1 2) (3)) ((1 2 3) ()))
(run 3 q (listo q))
→ (() (_.0) (_.0 _.1))
152/152 cumulative.
This commit is contained in:
@@ -100,20 +100,21 @@ Key semantic mappings:
|
||||
`appendo` deferred to Phase 4.
|
||||
|
||||
### Phase 4 — standard relations
|
||||
- [ ] `appendo` `l` `s` `ls` — list append, runs forwards and backwards
|
||||
- [ ] `membero` `x` `l` — x is a member of l
|
||||
- [ ] `listo` `l` — l is a proper list
|
||||
- [ ] `nullo` `l` — l is empty
|
||||
- [ ] `pairo` `p` — p is a pair (cons cell)
|
||||
- [ ] `caro` `p` `a` — car of pair
|
||||
- [ ] `cdro` `p` `d` — cdr of pair
|
||||
- [ ] `conso` `a` `d` `p` — cons
|
||||
- [ ] `firsto` / `resto` — aliases for caro/cdro
|
||||
- [x] `appendo` `l` `s` `ls` — list append, runs forwards AND backwards.
|
||||
Canary green: `(run* q (appendo (1 2) (3 4) q))` → `((1 2 3 4))`;
|
||||
`(run* q (fresh (l s) (appendo l s (1 2 3)) (== q (list l s))))` →
|
||||
all four splits.
|
||||
- [x] `membero` `x` `l` — enumerates: `(run* q (membero q (a b c)))` → `(a b c)`
|
||||
- [x] `listo` `l` — l is a proper list; enumerates list shapes with laziness
|
||||
- [x] `nullo` `l` — l is empty
|
||||
- [x] `pairo` `p` — p is a (non-empty) cons-cell / list
|
||||
- [x] `caro` / `cdro` / `conso` / `firsto` / `resto`
|
||||
- [ ] `reverseo` `l` `r` — reverse of list
|
||||
- [ ] `flatteno` `l` `f` — flatten nested lists
|
||||
- [ ] `permuteo` `l` `p` — permutation of list
|
||||
- [ ] `lengtho` `l` `n` — length as a relation (Peano or integer)
|
||||
- [ ] Tests: run each relation forwards and backwards; generate from partial inputs
|
||||
- [x] Tests: run each relation forwards and backwards (so far 25 in
|
||||
`tests/relations.sx`; reverseo/flatteno/permuteo/lengtho deferred)
|
||||
|
||||
### Phase 5 — `project` + `matche` + negation
|
||||
- [ ] `project` `(x ...) body` — access reified values of logic vars inside a goal;
|
||||
@@ -151,6 +152,23 @@ _(none yet)_
|
||||
|
||||
_Newest first._
|
||||
|
||||
- **2026-05-07** — **Phase 4 piece A — appendo canary green**: cons-cell support
|
||||
in `unify.sx` + `(:s head tail)` lazy stream refactor in `stream.sx` + hygienic
|
||||
`Zzz` (gensym'd subst-name) wrapping each `conde` clause + `lib/minikanren/
|
||||
relations.sx` with `nullo` / `pairo` / `caro` / `cdro` / `conso` / `firsto` /
|
||||
`resto` / `listo` / `appendo` / `membero`. 25 new tests in `tests/relations.sx`,
|
||||
152/152 cumulative.
|
||||
- **Three deep fixes shipped together**, all required to make `appendo`
|
||||
terminate in both directions:
|
||||
1. SX has no improper pairs, so a stream cell of mature subst + thunk
|
||||
tail can't use `cons` — moved to a `(:s head tail)` tagged shape.
|
||||
2. `(Zzz g)` wrapped its inner fn in a parameter named `s`, capturing
|
||||
the user goal's own `s` binding (the `(appendo l s ls)` convention).
|
||||
Replaced with `(gensym "zzz-s-")` for hygiene.
|
||||
3. SX cons cells `(:cons h t)` for relational decomposition (so
|
||||
`(conso a d l)` can split a list by head/tail without proper
|
||||
improper pairs); `mk-walk*` re-flattens cons cells back to native
|
||||
lists for clean reification output.
|
||||
- **2026-05-07** — **Phase 3 done** (run + reification): `lib/minikanren/run.sx` (~28 lines).
|
||||
`reify`/`reify-s`/`reify-name` for canonical `_.N` rendering of unbound vars in
|
||||
left-to-right occurrence order; `run*` / `run` / `run-n` defmacros. 18 new tests
|
||||
|
||||
Reference in New Issue
Block a user