I'm having troubles understanding why doesn't this clips code get trapped in an infinite loop
(defrule rule0
=>
(assert (my-fact))
)
(defrule rule1
?f <- (my-fact)
=>
(retract ?f)
)
As far as I know, rule0
is executed asserting my-fact
then rule1
is executed retracting it. Why doesn't rule0
execute again now?
Here are my thoughts:
- Clips memorizes for each rule if it was executed using some basis facts and avoids re-executing this rule using the same basis facts.
- There is some sort of optimizer that detected a loop and avoided it.
- Clips memorizes the facts that were inserted and deleted, and avoids re-inserting these facts (highly doubt it, I'm almost sure this can't be the case).
Note: I abstracted this piece of code from another small program that uses templates instead of facts.