@MISC{Meier95recursionvs., author = {Micha Meier}, title = {Recursion vs. Iteration in Prolog}, year = {1995} }
Bookmark
OpenURL
Abstract
We outline methods of compiling recursive procedures in Prolog to yield code which is close to that of imperative languages. Recursion is compiled into iteration which keeps loop invariants unchanged and uses destructive assignment on the stack variables. We also adentify various recursion types, depending on the stack frame type which is involved, namely environments, choice points and suspended goals. III 1 Introduction Prolog, like any other programming language, usually spends most of its execution time in a small portion of the program code, executing loops. It does not have the loop constructs heavily used in procedural languages, e.g. while or for, repetitive actions and loops (without side effects) are expressed using recursive procedures. Today, when it seems more and more likely that Prolog will reach a speed not much different from imperative languages, we have to reconsider the way we treat loops in Prolog. Although exploiting tail recursion optimization is usual in WAM ...