Subj : Re: Are recursive functions ever needed? To : comp.programming From : Tatu Portin Date : Sat Oct 01 2005 04:33 pm Aleya Roe wrote: >>Are recursive functions ever needed, i.e. cannot you just replace them >>with iterative clauses? > > Yes, you can always convert recursion to iteration. But it's not always > worth the effort since all but the simplest examples of recursion > require you to explicitly use a stack to save the algorithm state that > would otherwise be saved by making a recursive call. Sometimes the > algorithm makes things easier and with a lot of creativity you can > figure out how to avoid the stack, but examples like that are rare. > > >>b = func (func (func (a))) > > That's not really recursion though, unless this statement is inside the > definition of func. You're just calling the function three times. > That's easy to turn into iteration. > Well, my problem here seems to be lack of good examples where recursion is needed. Would anybody provide some? .