Am Freitag, 10. März 2017 11:27:13 UTC+1 schrieb Cev Ing:
>
>
> (define-syntax define-facts
> (syntax-rules ()
> ((_ (name a0 a1 ...) ((v00 v01 ...) (v10 v11 ...) ...))
> (define (name a0 a1 ...)
> (conde
> ((== a0 v00) (== a1 v01) ...)
> ((== a0 v10) (== a1 v11) ...)
> ...)))))
>
>
I was told, that the above macro, although it works in some Schemes, is
invalid R7RS. Also the list around the facts is not necessary. The
following works with R7RS.
(define ==*
(lambda (x l)
(fresh (a d)
(== `(,a . ,d) l)
(conde
((== x a))
((==* x d))))))
(define-syntax define-facts
(syntax-rules ()
((_ (name a ...) (v ...) ...)
(define name
(lambda (a ...)
(fresh ()
(==* (list a ...)
(list (list v ...) ...))))))))
(define-facts (mano m)
("Abraham")
("Ismael")
("Isaac")
("Jacob")
("Benjamin"))
(run 2 (q)
(mano q)) ;; => ("Abraham" "Ismael")
(define-facts (fathero f c)
("Abraham" "Ismael")
("Abraham" "Isaac")
("Isaac" "Jacob")
("Jacob" "Benjamin"))
(run* (q)
(fathero "Abraham" q)) ;; => ("Ismael" "Isaac")
(define (grand-fathero gf gc)
(fresh (f)
(fathero gf f)
(fathero f gc)))
(run* (q)
(grand-fathero "Isaac" q)) ;; => ("Benjamin")
--
You received this message because you are subscribed to the Google Groups
"minikanren" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/minikanren.
For more options, visit https://groups.google.com/d/optout.