4

I have tried to use an implementation of mini-kanren in clojure. But been struggling to understand the difference between cond-a cond-u and cond-e. I seem to be quite clear about cond-e but understanding of cond-a and cond-u is quiet bad.

cond-e takes a set of goals and then tries each of them... i.e tries all the branches that succeed.

cond-a and cond-u on the contrary commit to the branch whose first predicate succeeds and cond-a returns all the possible successful unifications there after. while cond-u returns only the first successfull unification ... but however it seems like this understanding is not correct when I use it. Can somebody help me clarify this understanding.

false
  • 10,264
  • 13
  • 101
  • 209

2 Answers2

4

cond-e gives every answer from all branches that succeed

cond-i gives every answer but interleaves them.

cond-a only gives the answers from the first successful branch

cond-u only gives the first answer from the first successful branch

Jim Duey
  • 56
  • 1
  • Thanks Jim.. But What exactly is interleaving ? is it like it gets one successful answer from each branch .. before coming back to the first branch for the next successful answer... ? – Sunil S Nandihalli Nov 08 '10 at 04:56
  • according to your explaination the following code should behave the same whether I use cond-u or cond-a in place of cond-? (run q (exist [x] (cond-? ((& x :unassigned) fail) (succeed)) (& q 20))) But that does not seem to be the case .... can you please explain? – Sunil S Nandihalli Nov 08 '10 at 06:09
2

I was just trying to get my head around these matters. There's a shortified scheme implementation Sokuza-kanren with a few comments, I'll read it tonight.

claj
  • 5,172
  • 2
  • 27
  • 30