Fork me on GitHub
#clara
<
2023-08-17
>
Joel18:08:17

I’m not using defrecords and trying to figure out how to capture the map I’m using, this doesn’t work:

(defrule high-temperatures
  [:temperature [{:keys [value] :as tmp}] (= ?temp value) (> value 12)]
  =>
  (prn "High temperature" tmp))

(-> (mk-session :fact-type-fn :type)
    (insert {:type :temperature :value 15 :location "MCI"}

Joel19:08:37

I found this worked, but feels tedious

(defrule high-temperatures
  [:temperature [{temp :value :as tmp}] (= ?tmp tmp) (= ?temp temp) (> temp 12)]
  =>
  (prn "High temperature" ?tmp))

ethanc21:08:20

the variable tmp would only be bound in the scoping of its usage in the alpha node, for usage in constraints where it was destructured. perhaps, this would be more clean:

(r/defrule high-temps
  [?tmp <- :temperature [{:keys [value]}] (> value 12)]
  =>
  (prn "high temp" ?tmp))
used like:
(-> (r/mk-session :fact-type-fn :type)
    (r/insert {:type :temperature :value 15 :location "MCI"})
    (r/fire-rules))

👍 2