Question

This is NOT homework -- the solution is already in the text. I just failed to understand the solution.

Problem

(run* (q)
  (let [a (== true q)
        b (== false q)]
    b))

Correct Solution

(false)

My believed solution

()

My Confusion

Apparently the "a (== true q)" line is NOT executed, since only b is the goal. This confuses me. My mental model so far for logic programming has been:

  • consider all possible assignemnts to q
  • output the ones that manages to pass through the entire program

    Thus, the "a (== true q)" forces q = true, which makes it impossible to satisfy the "b (== false q)" line.

    However, apparently only "thigns needed to compute the goal" are executed. What's going on? What's the right mental execution model for core.logic / mini-kanren?

Thanks

(BTW, I'm clearly in the wrong, since mini-karen + core.logic agre with each other -- I just want to understand what I'm doing wrong.)

Was it helpful?

Solution

== produces a goal. But you don't pass the a goal to run. So run doesn't know about it. A comparable situation is this:

(defn call [f] (f))

(call
  (let [a #(println "a")
        b #(println "b")]
    b))

The a function is created but not passed to call. So it is never executed.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top