Hi! Im not a minikanren authority.
Anyway I cant make sense of what you want to do.
As i undestand conde expresses alternative "executions", not a list of
results
See what this outputs
(run* (x)
(conde
((== x "1"))
((== x "2"))
((== x "3")))
(conde
((== x "4"))
((== x "5"))
((== x "6"))))
Any way i guess ill try something like this:
(I niether a schemer :P, and probably ahead comes buggy code)
(define condeo (lambda in out)
(conde
((== in '()) ;; the case in is empty cant unify/relate
out to nothing
#f) ;; must fail or out will be free
((fresh (head tail)
(conso head tail in) ;; the case in is not
empty splits in 2
(conde ((== out head)) ;; theres a case
where out is the first element
((condeo tail out))))))) ;; theres case
where out has some value from the rest of the list.
Cheers.
On Wednesday, March 8, 2017 at 1:49:31 PM UTC-3, Cev Ing wrote:
>
> 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.