4.67 Exercise 4.67
TODO: Expand and implement
A straightforward way to detect loops is to maintain a stack of all derivations that a system has made at every point of execution, akin to a call stack. If a derivation is ever attempted that already exists in this stack, then we know that the system is entering an infinite loop.
It is necessary for the derivation and all bound parameters to match exactly. If, for example, we evaluate the rule with a superset of the bound parameters of an earlier call, then we are not infinitely looping.