I am studying *The Reasoned Schemer, 2nd ed.* and translating its source 
code into Clojure.

https://github.com/philoskim/reasoned-schemer-for-clojure

In the middle of studying the problem #98 of Chapter 3, I encountered an 
unexpected result like this.

https://github.com/philoskim/reasoned-schemer-for-clojure/blob/master/src/rs/ch3.clj#L498
  

in 3.100 the expected result is (fagioli e pasta).

So I debugged the code like this by using my *debux (*
https://github.com/philoskim/debux) library. The dbg macro here just prints 
its executed result without interrupting the code execution.

(use 'debux.core)

(defn memberrevo [x l]
  (conde
    [(dbg (emptyo l)) u#]
    [s# (fresh [d]
          (dbg (resto l d))
          (dbg (memberrevo x d)))]
    [s# (dbg (eq-caro l x))]))

(run* [x]
  (memberrevo x '(pasta e fagioli)))


Suprisingly, the execution order of the printed result is not what I 
expected.


dbg: (emptyo l) =>
|   #function[clojure.core.logic/==/fn--15821]

dbg: (eq-caro l x) =>
|   #function[clojure.core.logic/firsto/fn--16147]

dbg: (resto l d) =>
|   #function[clojure.core.logic/resto/fn--16152]

dbg: (memberrevo x d) =>
|   #function[rs.ch3/memberrevo/fn--21091]

dbg: (emptyo l) =>
|   #function[clojure.core.logic/==/fn--15821]

dbg: (eq-caro l x) =>
|   #function[clojure.core.logic/firsto/fn--16147]

dbg: (resto l d) =>
|   #function[clojure.core.logic/resto/fn--16152]

dbg: (memberrevo x d) =>
|   #function[rs.ch3/memberrevo/fn--21091]

dbg: (emptyo l) =>
|   #function[clojure.core.logic/==/fn--15821]

dbg: (eq-caro l x) =>
|   #function[clojure.core.logic/firsto/fn--16147]

dbg: (resto l d) =>
|   #function[clojure.core.logic/resto/fn--16152]

dbg: (memberrevo x d) =>
|   #function[rs.ch3/memberrevo/fn--21091]

dbg: (emptyo l) =>
|   #function[clojure.core.logic/==/fn--15821]

dbg: (eq-caro l x) =>
|   #function[clojure.core.logic/firsto/fn--16147]

dbg: (resto l d) =>
|   #function[clojure.core.logic/resto/fn--16152]

dbg: (memberrevo x d) =>
|   #function[rs.ch3/memberrevo/fn--21091]


What I expected was as follows.


dbg: (emptyo l) =>
|   #function[clojure.core.logic/==/fn--15821]

dbg: (resto l d) =>
|   #function[clojure.core.logic/resto/fn--16152]

dbg: (memberrevo x d) =>
|   #function[rs.ch3/memberrevo/fn--21091]

dbg: (eq-caro l x) =>
|   #function[clojure.core.logic/firsto/fn--16147]

dbg: (emptyo l) =>
|   #function[clojure.core.logic/==/fn--15821]

dbg: (resto l d) =>
|   #function[clojure.core.logic/resto/fn--16152]

dbg: (memberrevo x d) =>
|   #function[rs.ch3/memberrevo/fn--21091]

dbg: (eq-caro l x) =>
|   #function[clojure.core.logic/firsto/fn--16147]
......


Because the code 

[s# (fresh [d]
  (resto l d)
  (memberrevo x d))]

precedes

[s# (eq-caro l x)]


I cannot understand the unexpected result at all.

Could anyone explain to me why this happens?

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to