[clean-list] Memory usage in recursion
Richard A. O'Keefe
ok@atlas.otago.ac.nz
Wed, 22 Nov 2000 15:13:58 +1300 (NZDT)
fjh wrote:
Actually for Prolog code that creates choice points, Prolog
implementations can't do tail call optimization.
Only partly true. In Quintus Prolog, *all* dynamically-last calls were
tail calls. It's just that tail calls only physically reclaimed the
memory of a stack frame when the predicate became determinate up to that
point. This meant that the garbage collector would quite often squeeze
out stack frames that were no longer needed.
BTW, as a matter of Prolog programming style, it is generally better
to use first-argument clause indexing to avoid creating choice points
in the first place, rather than creating choice points and then using
cuts to prune them away.
That is 100% dead right.