clara

http://www.clara-rules.org/
Pieter Slabbert 2020-08-31T13:54:10.004Z

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
  [ThingB
   (= ?k k)]
  [ThingA
   (= ?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))
    (rules/fire-rules))
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