Fork me on GitHub
Pieter Slabbert13:08:10

I have sample code that I'm trying to figure out the best way to fix.

(defrecord ThingA [id data])
(defrecord ThingB [k])

(defrule broken
   (= ?k k)]
   (= ?id id)
   (= ?data data)
   (= ?entry (-> data :items (get ?k)))
   (some? ?entry)]
  (println "entry" ?entry))

(-> (rules/mk-session)
    (rules/insert (->ThingA 1 {:items {:entry {:a 1 :b 2}}}))
    (rules/insert (->ThingB :entry))
When I run this I get
Execution error at clara.rules.compiler/try-eval (compiler.clj:233).
Unable to resolve symbol: ?entry in this context
If I hard code the value of ?k it works, but it when I try get it from another fact I get the error. What would be the proper way to extract a field from one fact and use it to look something up in another fact