clara

http://www.clara-rules.org/
2018-04-03T02:38:05.000069Z

@ggaillard when you perform the side-effect, you can insert a fact that indicates that the side effect was performed

2018-04-03T02:38:44.000103Z

you can then have a rule that uses that to “retract” the side effects

2018-04-03T02:39:28.000034Z

you likely need to make these effects “idempotent” so they can be replaced multiple times without causing issues

2018-04-03T02:42:29.000039Z

maybe something like

(r/defrule do-thing
  [A (= v :something) (= ?id id)]
  =>
  (do-side-effect ?a)
  (r/insert! (->DidSideEffectFor ?id)))

(r/defrule undo-thing
  [?effect-data <- DidSideEffectFor (= ?id id)]
  [:not [A (= ?id id)]]
  =>
  (retract-side-effect ?effect-data))
Assumes you have a way to link facts up, like an ID. This doesn’t attempt to remove the DidSideEffectFor facts. So if this is a long running process, this may start to add up as too much data in memory

2018-04-03T02:42:57.000062Z

If that’s the case, you may just want to handle the side-effects externally and clean up the DidSideEffectFor as well

2018-04-03T02:47:29.000149Z

My post on ways to update facts may be somewhat related to, if you are interested http://www.metasimple.org/2017/12/23/clara-updating-facts.html

Geoffrey Gaillard 2018-04-03T09:26:12.000347Z

Awesome answer! Thank you!

✅ 1