Question

According to https://github.com/clojure/core.logic/wiki/Differences-from-The-Reasoned-Schemer core.logic supports listo.

However, the following piece of code does not compile

(ns test.chap03
  (:refer-clojure :exclude [==])  
  (:use [clojure.core.logic]))

(defn ex07 []
  (run*
    [x]
    (listo `(a b ~x d))))

It complains:

Exception: java.lang.RuntimeException: Unable to resolve symbol: listo in this context, compiling:(test/chap03.clj:8)

Question: what is going on, and how do I get listo?

Was it helpful?

Solution

listo is not implemented. core.logic does not ship with all the definitions from The Reasoned Schemer.

OTHER TIPS

as user1311390 pointed out, They are available in the tests.

https://github.com/clojure/core.logic/blob/master/src/test/clojure/clojure/core/logic/tests.clj#L459 Here is the part that implements listo.

(defn pairo [p]
  (fresh [a d]
    (== (lcons a d) p)))

(defn listo [l]
  (conde
    [(emptyo l) s#]
    [(pairo l)
     (fresh [d]
       (resto l d)
       (listo d))]))

Now we can get the expected behavior. Please note that for brevity I have purposely NOT included the entire missing implementation to The Reasoned Schemer. See link above.

(run 1
  [x]
  (listo `(a b ~x d))) 
;; => (_0)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top