diff --git a/lib/minikanren/intarith.sx b/lib/minikanren/intarith.sx index 1ca9aee2..ed3692a9 100644 --- a/lib/minikanren/intarith.sx +++ b/lib/minikanren/intarith.sx @@ -60,3 +60,11 @@ (define stringo (fn (x) (project (x) (if (string? x) succeed fail)))) (define symbolo (fn (x) (project (x) (if (symbol? x) succeed fail)))) + +(define + even-i + (fn (n) (project (n) (if (and (number? n) (even? n)) succeed fail)))) + +(define + odd-i + (fn (n) (project (n) (if (and (number? n) (odd? n)) succeed fail)))) diff --git a/lib/minikanren/tests/intarith.sx b/lib/minikanren/tests/intarith.sx index d81db4c1..baab8fe2 100644 --- a/lib/minikanren/tests/intarith.sx +++ b/lib/minikanren/tests/intarith.sx @@ -86,4 +86,18 @@ (== q x))) (list 1 2)) +(mk-test "even-i-pos" (run* q (even-i 4)) (list (make-symbol "_.0"))) + +(mk-test "even-i-neg" (run* q (even-i 5)) (list)) + +(mk-test "odd-i-pos" (run* q (odd-i 7)) (list (make-symbol "_.0"))) + +(mk-test "odd-i-neg" (run* q (odd-i 4)) (list)) + +(mk-test + "even-i-filter" + (run* q (fresh (x) (membero x (list 1 2 3 4 5 6)) (even-i x) (== q x))) + (list 2 4 6)) + (mk-tests-run!) + diff --git a/plans/minikanren-on-sx.md b/plans/minikanren-on-sx.md index b040fb45..07f05f2c 100644 --- a/plans/minikanren-on-sx.md +++ b/plans/minikanren-on-sx.md @@ -173,6 +173,7 @@ _(none yet)_ _Newest first._ +- **2026-05-08** — **even-i / odd-i (intarith)**: ground-only parity goals via project. Composes with membero for filtered enumeration: -> . 5 new tests, 416/416 cumulative. - **2026-05-08** — **selecto**: classic miniKanren "choose an element + rest". Direct base (l = (x . rest)) plus skip-head recurse. Enumerates all (element, rest) splits in run*; runs forward, backward, mid-pipeline. 6 new tests, 411/411 cumulative. - **2026-05-08** — **subo (contiguous sublist)**: Two appendos chained — l = front ++ s ++ back. Goal order matters: appendo on the ground l first, so the search is finitary; then constrain front. 7 new tests, 405/405 cumulative. - **2026-05-08** — **prefixo + suffixo**: classic appendo-derived sublist relations. (prefixo p l) ≡ p ⊕ ? = l; (suffixo s l) ≡ ? ⊕ s = l. Both enumerate all prefixes/suffixes when given a fresh first arg. 9 new tests, 398/398 cumulative.