Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 25s
(defrel (NAME ARGS...) (CLAUSE1 ...) (CLAUSE2 ...) ...) expands to (define NAME (fn (ARGS...) (conde (CLAUSE1 ...) (CLAUSE2 ...) ...))). Mirrors Prolog's `name(Args) :- goals.` shape. Inherits the Zzz-on-each- clause laziness from conde, so user relations defined via defrel terminate on partial answers without needing manual delay. Tests redefine membero / listo / pluso through defrel and verify equivalence. 3 new tests, 347/347 cumulative.
26 lines
698 B
Plaintext
26 lines
698 B
Plaintext
;; lib/minikanren/defrel.sx — Prolog-style defrel macro.
|
|
;;
|
|
;; (defrel (NAME ARG1 ARG2 ...)
|
|
;; (CLAUSE1 ...)
|
|
;; (CLAUSE2 ...)
|
|
;; ...)
|
|
;;
|
|
;; expands to
|
|
;;
|
|
;; (define NAME (fn (ARG1 ARG2 ...) (conde (CLAUSE1 ...) (CLAUSE2 ...))))
|
|
;;
|
|
;; This puts each clause's goals immediately after the head, mirroring
|
|
;; Prolog's `name(Args) :- goals.` shape. Clauses are conde-conjoined
|
|
;; goals — `Zzz`-wrapping is automatic via `conde`, so recursive
|
|
;; relations terminate on partial answers.
|
|
|
|
(defmacro
|
|
defrel
|
|
(head &rest clauses)
|
|
(let
|
|
((name (first head)) (args (rest head)))
|
|
(list
|
|
(quote define)
|
|
name
|
|
(list (quote fn) args (cons (quote conde) clauses)))))
|