Re: [ILUG] impressive...

From: Smelly Pooh (plop at domain redbrick.dcu.ie)
Date: Wed 03 Nov 1999 - 12:50:54 GMT


In reply to Mel's flatulent wordings,
> On Thu, 28 Oct 1999, Caolan McNamara wrote:
>
> > On 28-Oct-99 John P . Looney wrote:
> > Reminds me of the horrors of using recursion in the real world. I
> > remember on co-op some moronic computer science character had
> > decided to write some bastardized linked list adder using recursion,
> > sure it works fine on those imaginary computers, but in the real world
> > embedded dos system that it went into it just *ATE* stack space,

> I'd say thats because Computer Scientists often spout about the merits of
> recursion and rarely consider what happens on the real machine in terms of
> stack space and function call overhead.

In theory and practice, there are many tasks that are always better expressed
in terms of recursive functions, the factorial function being a prime example.
The problem is that only functional languages are really built to handle
recursion. Imperative languages such as C or PERL call each recursive
function like any other function, hence the stack space problem, functional
languages are built in such a way that they can make use of a concept called
tail recursion. That's when the recursive function is called at the very end
of the function (and because of the way functional languages always returns
the values of the last statement executed they are very well suited to this).
Now any practical computer person can deduce for themselves that they no
longer need the stack space from the initial invocation of the function,
because you're returning the value from the next invocatio., so all that is
needed is to free that stack and execute the next invocation and so on and so
on, you always use the same amount of memory, there is method behind the
madness of all those functional languages that refuse to use a simple loop
over recursion.



This archive was generated by hypermail 2.1.6 : Thu 06 Feb 2003 - 13:04:49 GMT