;; 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)))))
