@ggaillard when you perform the side-effect, you can insert a fact that indicates that the side effect was performed
you can then have a rule that uses that to “retract” the side effects
you likely need to make these effects “idempotent” so they can be replaced multiple times without causing issues
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 memoryIf that’s the case, you may just want to handle the side-effects externally and clean up the DidSideEffectFor
as well
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
Awesome answer! Thank you!