Fork me on GitHub
#clara
<
2018-04-03
>
mikerod02:04:05

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

mikerod02:04:44

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

mikerod02:04:28

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

mikerod02:04:29

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

mikerod02:04:57

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

mikerod02:04:29

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 Gaillard09:04:12

Awesome answer! Thank you!

4