I am new to miniKanren and still struggling with the basics. Maybe someone
can help me.
I try to write a function taking a variable number of arguments and
behaving like conde.
This is my cond example:
(run* (x)
(conde
((== x "1"))
((== x "2"))
((== x "3")))) ;; => ("1" "2" "3")
I can write a macro, which takes a variable number of arguments and
converts it into a conde:
(define-syntax conde-list
(syntax-rules ()
((_ (a0 a1 ...) x)
(conde
((== x a0))
((== x a1))
...))))
(run* (x)
(conde-list ("1" "2" "3") x)) ;; => ("1" "2" "3")
Now I tried to write a similar function condeo in miniKanren using
recursion so that the following expression is true.
(run* (x)
(condeo '("1" "2" "3") x)) ;; => ("1" "2" "3")
This is what I did, but it does not work:
(define condeo
(lambda (in out)
(fresh (hi ti)
(== `(,hi . ,ti) in)
(fresh (ho to)
(== `(,ho . ,to) out)
(conde
((== hi ho))
((condeo ti to)))))))
Like the appendo example in the tutorials I split the input list in head
and tail and the same for the output list. And then I use conde for head
and tail, putting the recursion at the end. But when I try it, I get funny
results:
(run 4 (x)
(condeo '("1" "2" "3") x)) ;; => (("1" . _.0) (_.0 "2" . _.1) (_.0 _.1
"3" . _.2))
It iterates somehow but why are there so many free variables?
--
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.