mk: phase 4A — appendo canary green, both directions
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:
2026-05-07 20:24:42 +00:00
parent 52070e07fc
commit cae87c1e2c
10 changed files with 511 additions and 164 deletions

View File

@@ -4,12 +4,12 @@
(mk-test
"fresh-empty-vars-equiv-conj"
((fresh () (== 1 1)) empty-s)
(stream-take 5 ((fresh () (== 1 1)) empty-s))
(list empty-s))
(mk-test
"fresh-empty-vars-no-goals-is-succeed"
((fresh ()) empty-s)
(stream-take 5 ((fresh ()) empty-s))
(list empty-s))
;; --- single var ---
@@ -17,8 +17,8 @@
(mk-test
"fresh-one-var-bound"
(let
((s (first ((fresh (x) (== x 7)) empty-s))))
(let ((vs (vals s))) (first vs)))
((s (first (stream-take 5 ((fresh (x) (== x 7)) empty-s)))))
(first (vals s)))
7)
;; --- multiple vars + multiple goals ---
@@ -33,7 +33,7 @@
(== x 10)
(== y 20)
(== q (list x y)))))
(mk-walk* q (first (g empty-s))))
(mk-walk* q (first (stream-take 5 (g empty-s)))))
(list 10 20))
(mk-test
@@ -47,7 +47,7 @@
(== b 2)
(== c 3)
(== q (list a b c)))))
(mk-walk* q (first (g empty-s))))
(mk-walk* q (first (stream-take 5 (g empty-s)))))
(list 1 2 3))
;; --- fresh interacts with disj ---
@@ -77,7 +77,7 @@
(== x 1)
(== y 2)
(== q (list x y))))))
(mk-walk* q (first (g empty-s))))
(mk-walk* q (first (stream-take 5 (g empty-s)))))
(list 1 2))
;; --- call-fresh (functional alternative) ---
@@ -85,7 +85,7 @@
(mk-test
"call-fresh-binds-and-walks"
(let
((s (first ((call-fresh (fn (x) (== x 99))) empty-s))))
((s (first (stream-take 5 ((call-fresh (fn (x) (== x 99))) empty-s)))))
(first (vals s)))
99)
@@ -95,7 +95,7 @@
((q (mk-var "q")))
(let
((g (call-fresh (fn (x) (mk-conj (== x 5) (== q (list x x)))))))
(mk-walk* q (first (g empty-s)))))
(mk-walk* q (first (stream-take 5 (g empty-s))))))
(list 5 5))
(mk-tests-run!)