Welcome! Please see the About page for a little more info on how this works.

0 votes
in core.logic by

Hi,
I have encountered a problem in simple core.logic program:

(require '[clojure.core.logic :as l]

     '[clojure.core.logic.pldb :as db])
     

(def facts
(db/db

[In-zone 'A 'B]))

(println
(db/with-db facts

    (l/run* [q]
      (l/fresh [x y]
        (In-zone x y)
        (== q 'IN-ZONE)))))

It gives this result:

user=> (load-file "../PROGS/CL/inzone.clj")
CompilerException java.lang.ClassCastException: class clojure.core.logic.LVar cannot be cast to class java.lang.Number (clojure.core.logic.LVar is in unnamed module of loader clojure.lang.DynamicClassLoader @4d2015a9; java.lang.Number is in module java.base of loader 'bootstrap'), compiling:(/home/ru/clojure/core.logic-master/../PROGS/CL/inzone.clj:8:1)

What's wrong? No mention about numbers!

Thanks in advance for any help.

1 Answer

0 votes
by

I think you forgot to refer to == from core.logic, and are using clojure.core/== which explains the numbers error.

(require '[clojure.core.logic :as l]
         '[clojure.core.logic.pldb :as db])

(db/db-rel In-zone a b)

(def facts (db/db [In-zone 'A 'B])) 

(println
   (db/with-db facts
    (l/run* [q]
      (l/fresh [x y]
        (In-zone x y)
        (l/== q [x y])))))

;;([A B])
by
Great, Tom!
My fault :( Thanks!
By the way. Can you recommend comprehensive documentation on core.logic and its API, with examples and so on? All I have found is sketchy and fragmentary..
by
I think the legacy documentation is as far as it goes.  Most people recommend looking at "The Reasoned Schemer" since it is based in miniKanren, which is what core.logic implements.  There are odd bugs or counter intuitive results with certain operations (project is one example).

The library is essentially as baked as it is going to be at this point, unless new interest arises.  Happy to answer questions if I can help though.
by
"The Reasoned Schemer" is strange and funny, somewhat theoretical, unwonted as doc for developer.
By indirect evidence core.logic were used in some serious projects, Datomic, for example. I am not shure. All the same, thanks once more.
...