[clean-list] Memory usage in recursion

F.S.A.Zuurbier@inter.nl.net F.S.A.Zuurbier@inter.nl.net
Mon, 20 Nov 2000 15:05:28 +0100 (MET)


Eddy wrote:
==========================
Hi All, 
As I understand from the Clean tutorial "Functional programming in Clean", 
Clean uses quite a lot of recursion to implement certain functions. 
What I know from other languages is that recursion usually makes extensive 
use of the stack. When the code is assembled you usually see a number of 
'pushes' and 'pops' to store and retrieve data on the stack. 
As you all know the danger is that the depth of recursion depends on the 
data to be processed by the function in question. Usually you don't know in 
advance what the 'size' of the data will be and you don't know exactly how 
deep the recursion will be. As a result of this, a 'stack overflow' can occur. 
Is this also the case in Clean or is the data storage during recursion 
handled in a different way? 
Kind regards 
Eddy 
========================
Eddy,

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.

Regards Erik Zuurbier