mk: numbero / stringo / symbolo type predicates
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 24s

Ground-only type tests via project. Each succeeds iff its argument
walks to the corresponding host value type. Composes with membero for
type-filtered enumeration:

  (fresh (x) (membero x (list 1 "a" 2 "b" 3)) (numbero x) (== q x))
    -> (1 2 3)

12 new tests, 328/328 cumulative. Caveat: SX keywords are strings, so
(stringo :k) succeeds.
This commit is contained in:
2026-05-08 11:17:27 +00:00
parent b4c1253891
commit 2d51a8c4ea
3 changed files with 63 additions and 0 deletions

View File

@@ -54,3 +54,9 @@
(project
(a b)
(if (and (number? a) (and (number? b) (not (= a b)))) succeed fail))))
(define numbero (fn (x) (project (x) (if (number? x) succeed fail))))
(define stringo (fn (x) (project (x) (if (string? x) succeed fail))))
(define symbolo (fn (x) (project (x) (if (symbol? x) succeed fail))))

View File

@@ -0,0 +1,52 @@
;; lib/minikanren/tests/types.sx — type-predicate goals.
(mk-test
"numbero-on-int"
(run* q (numbero 5))
(list (make-symbol "_.0")))
(mk-test "numbero-on-string" (run* q (numbero "5")) (list))
(mk-test "numbero-on-symbol" (run* q (numbero (quote x))) (list))
(mk-test "numbero-on-list" (run* q (numbero (list 1))) (list))
(mk-test
"stringo-on-string"
(run* q (stringo "hi"))
(list (make-symbol "_.0")))
(mk-test "stringo-on-int" (run* q (stringo 5)) (list))
(mk-test
"stringo-on-keyword"
(run* q (stringo :k))
(list (make-symbol "_.0"))) ;; SX keywords ARE strings
(mk-test
"symbolo-on-symbol"
(run* q (symbolo (quote x)))
(list (make-symbol "_.0")))
(mk-test "symbolo-on-string" (run* q (symbolo "x")) (list))
(mk-test "symbolo-on-int" (run* q (symbolo 5)) (list))
;; --- combine with membero for type-filtered enumeration ---
(mk-test
"membero-numbero-filter"
(run*
q
(fresh
(x)
(membero x (list 1 "a" 2 "b" 3))
(numbero x)
(== q x)))
(list 1 2 3))
(mk-test
"membero-stringo-filter"
(run*
q
(fresh
(x)
(membero x (list 1 "a" 2 "b" 3))
(stringo x)
(== q x)))
(list "a" "b"))
(mk-tests-run!)