[clean-list] Memory usage in recursion

F.S.A.Zuurbier@inter.nl.net F.S.A.Zuurbier@inter.nl.net
Tue, 21 Nov 2000 11:20:16 +0100 (MET)


Jerzy wrote:
=============
> Clean and other functional programming languages would not be useful if this problem had not been solved. Indeed, it has been solved. So called tail-recursion can usually (if not always) by compiled in such a way that a stack-frame is not needed. 
> 
Not always. (And not only because the compilers of, say, C++ are lousy). 
In Prolog or other Logic Programming Languages the calls often must 
leave something on the "trail" in order to enable the backtracking. 
So, even the tail calls may overflow internal data structures, unless 
the user is conscious and "cuts" the backtrack points. 
=============

Check the Prolog-like Mercury language. I have not tried, but I would not be surprised if ithas a much nicer way to avoid stack allocation for tail calls. Not explicit cuts, but a way of knowing that backtracking is not needed in the context at hand, namely mode analysis.

Reagrds Erik Zuurbier