Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to match a map that contains lvars?

I am trying to use maps as my data structure and I initialize them to contain lvars to be assigned values later from other relations.

This succeeds:

(run 1 [q]
  (fresh [a b]
    (== q {:a 1 :b 2 :c b})
    (featurec q {:a b})))
-> ({:a 1, :b 2, :c 1})

But these fail:

;; Expected result -> ({:a 1 :b 2 :c _0})
(run 1 [q]
  (fresh [a b]
    (== q {:a a :b 2 :c b})
    (featurec q {:a 1})))
-> java.lang.ClassCastException: java.lang.Long cannot be cast to clojure.lang.IPersistentMap

;; Expected result -> ({:a _0 :b 2 :c _0})
(run 1 [q]
  (fresh [a b]
    (== q {:a a :b 2 :c b})
    (featurec q {:a b})))
-> java.lang.ClassCastException: clojure.core.logic.LVar cannot be cast to clojure.lang.IPersistentMap

I am using [org.clojure/core.logic "0.8.5"]. How can I make both goals succeed?

like image 615
muhuk Avatar asked Dec 06 '25 10:12

muhuk


1 Answers

This is due to a bug in partial-map (http://dev.clojure.org/jira/browse/LOGIC-145).

like image 145
A. Webb Avatar answered Dec 08 '25 05:12

A. Webb



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!