Fork me on GitHub
#clara
<
2016-06-06
>
devn16:06:16

Hello friends

devn16:06:11

Question for you... Provided:

(defrecord DatedFact [date whatever])
(defrecord LatestFact [date whatever])

(def latest
  "Accumulator for finding the maximum value of a :date field."
  (clara.acc/max (comp time.coerce/to-long :date)
                 :returns-fact true))

(clara/defrule simple-latest-rule
  [?result <- latest :from [DatedFact (= ?date date)]]
  =>
  (clara.rules/insert! (map->LatestFact ?result)))

(clara/defquery query-latest [] [?latest <- LatestFact])

devn16:06:55

This will insert! for all DatedFacts.

devn16:06:28

Without the constraint on (= ?date date), it will fire only once.

devn16:06:57

I understand why this is so, but I guess I'm interested to know what you think about how you'd prevent this sort of thing from happening by rule authors.

devn17:06:13

On second thought, I could use a good plain english explanation of why this is the case.