NextPrevUpTopContentsIndex

6.2.3.2 Tail Recursion

The KnowledgeWorks Backward Chainer supports the transformation of "tail-recursive" calls into jumps. Thus, stack overflow can be avoided without resorting to "repeat, fail" loops in most cases. For example, given the definition:

(defrule run-forever :backward
                    ((run-forever)
                    <--
                     (run-forever)))

the call: (run-forever) will run forever without generating a stack overflow. Note that this optimization is not limited to recursive calls to the same rule. The last call of any rule will be compiled as a jump, drastically reducing stack usage.


KnowledgeWorks and Prolog User Guide (Windows version) - 29 Feb 2008

NextPrevUpTopContentsIndex