Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 57s
Squash merge of 76 commits from loops/minikanren. Adds lib/minikanren/ — a complete miniKanren-on-SX implementation built on top of lib/guest/match.sx, validating the lib-guest unify-and-match kit as intended. Modules (20 .sx files, ~1700 LOC): unify, stream, goals, fresh, conde, condu, conda, run, relations, peano, intarith, project, nafc, matche, fd, queens, defrel, clpfd, tabling Phases 1–5 fully done (core miniKanren API, all classic relations, matche, conda, project, nafc). Phase 6 — native CLP(FD): domain primitives, fd-in / fd-eq / fd-neq / fd-lt / fd-lte / fd-plus / fd-times / fd-distinct / fd-label, with constraint reactivation iterating to fixed point. N-queens via FD: 4-queens 2 solutions, 5-queens 10 solutions (vs naive timeout past N=4). Phase 7 — naive ground-arg tabling: table-1 / table-2 / table-3. Fibonacci canary: tab-fib(25) = 75025 in seconds, naive fib(25) times out at 60s. Ackermann via table-3: A(3,3) = 61. 71 test files, 644+ tests passing across the suite. Producer/consumer SLG (cyclic patho, mutual recursion) deferred — research-grade work. The lib-guest validation experiment is conclusive: lib/minikanren/ unify.sx adds ~50 lines of local logic (custom cfg, deep walk*, fresh counter) over lib/guest/match.sx's ~100-line kit. The kit earns its keep ~3× by line count.
139 lines
2.4 KiB
Plaintext
139 lines
2.4 KiB
Plaintext
;; lib/minikanren/tests/matche.sx — Phase 5 piece D tests for `matche`.
|
|
|
|
;; --- literal patterns ---
|
|
|
|
(mk-test
|
|
"matche-literal-number"
|
|
(run* q (matche q (1 (== q 1))))
|
|
(list 1))
|
|
|
|
(mk-test
|
|
"matche-literal-string"
|
|
(run* q (matche q ("hello" (== q "hello"))))
|
|
(list "hello"))
|
|
|
|
(mk-test
|
|
"matche-literal-no-clause-matches"
|
|
(run*
|
|
q
|
|
(matche 7 (1 (== q :a)) (2 (== q :b))))
|
|
(list))
|
|
|
|
;; --- variable patterns ---
|
|
|
|
(mk-test
|
|
"matche-symbol-pattern"
|
|
(run* q (fresh (x) (== x 99) (matche x (a (== q a)))))
|
|
(list 99))
|
|
|
|
(mk-test
|
|
"matche-wildcard"
|
|
(run* q (fresh (x) (== x 7) (matche x (_ (== q :any)))))
|
|
(list :any))
|
|
|
|
;; --- list patterns ---
|
|
|
|
(mk-test
|
|
"matche-empty-list"
|
|
(run* q (matche (list) (() (== q :ok))))
|
|
(list :ok))
|
|
|
|
(mk-test
|
|
"matche-pair-binds"
|
|
(run*
|
|
q
|
|
(fresh
|
|
(x)
|
|
(== x (list 1 2))
|
|
(matche x ((a b) (== q (list b a))))))
|
|
(list (list 2 1)))
|
|
|
|
(mk-test
|
|
"matche-triple-binds"
|
|
(run*
|
|
q
|
|
(fresh
|
|
(x)
|
|
(== x (list 1 2 3))
|
|
(matche x ((a b c) (== q (list :sum a b c))))))
|
|
(list (list :sum 1 2 3)))
|
|
|
|
(mk-test
|
|
"matche-mixed-literal-and-var"
|
|
(run*
|
|
q
|
|
(fresh
|
|
(x)
|
|
(== x (list 1 99 3))
|
|
(matche x ((1 m 3) (== q m)))))
|
|
(list 99))
|
|
|
|
;; --- multi-clause dispatch ---
|
|
|
|
(mk-test
|
|
"matche-multi-clause-shape"
|
|
(run*
|
|
q
|
|
(fresh
|
|
(x)
|
|
(== x (list 5 6))
|
|
(matche
|
|
x
|
|
(() (== q :empty))
|
|
((a) (== q (list :one a)))
|
|
((a b) (== q (list :two a b))))))
|
|
(list (list :two 5 6)))
|
|
|
|
(mk-test
|
|
"matche-three-shapes-via-fresh"
|
|
(run*
|
|
q
|
|
(fresh
|
|
(x)
|
|
(matche
|
|
x
|
|
(() (== q :empty))
|
|
((a) (== q (list :one a)))
|
|
((a b) (== q (list :two a b))))))
|
|
(list
|
|
:empty (list :one (make-symbol "_.0"))
|
|
(list :two (make-symbol "_.0") (make-symbol "_.1"))))
|
|
|
|
;; --- nested patterns ---
|
|
|
|
(mk-test
|
|
"matche-nested"
|
|
(run*
|
|
q
|
|
(fresh
|
|
(x)
|
|
(==
|
|
x
|
|
(list (list 1 2) (list 3 4)))
|
|
(matche x (((a b) (c d)) (== q (list a b c d))))))
|
|
(list (list 1 2 3 4)))
|
|
|
|
;; --- repeated var names create the same fresh var → must unify ---
|
|
|
|
(mk-test
|
|
"matche-repeated-var-implies-equality"
|
|
(run*
|
|
q
|
|
(fresh
|
|
(x)
|
|
(== x (list 7 7))
|
|
(matche x ((a a) (== q a)))))
|
|
(list 7))
|
|
|
|
(mk-test
|
|
"matche-repeated-var-mismatch-fails"
|
|
(run*
|
|
q
|
|
(fresh
|
|
(x)
|
|
(== x (list 7 8))
|
|
(matche x ((a a) (== q a)))))
|
|
(list))
|
|
|
|
(mk-tests-run!)
|