oakes / odoyle-rules

A rules engine for Clojure(Script)
The Unlicense
530 stars 20 forks source link

then not= doesn't stop an infinite loop that i think it should #33

Open drewverlee opened 5 months ago

drewverlee commented 5 months ago

this code

(def rules
  (o/ruleset
    {::foo
     [:what
      [id ::x x {:then not=}]
      :then
      (o/insert! (inc id) {::x 10})]}))

(def *session
  (atom (reduce o/add-rule (o/->session) rules)))

(swap! *session
       (fn [session]
         (-> session
             (o/insert 0 ::x 1)
             o/fire-rules)))

results in this error

This may be an infinite loop.
The current recursion limit is 16 (set by the :recursion-limit option of fire-rules).

Cycle detected! :drews.national-institutes-of-health/foo is triggering itself.

Try using {:then false} to prevent triggering rules in an infinite loop.

i expected their to be no loop because while the first insert would pass because (not= 10 1) is true, on the second (not= 10 10) would be false and it would stop. For reasons i don't understand if i hardcode the id passed to insert:

(def rules
  (o/ruleset
    {::foo
     [:what
      [id ::x x {:then not=}]
      :then
      (o/insert! 2 {::x 10})]}))

It works, this implies whats being compared, by the then block, is really it per entity. is that right?