Clojure, core.logic: listo

366 Views Asked by At

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?

2

There are 2 best solutions below

1
On BEST ANSWER

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

0
On

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)