Re: Untangling Multi-function Recursion
- From: cri@xxxxxxxx (Richard Harter)
- Date: Sun, 30 Dec 2007 04:38:22 GMT
On Sat, 29 Dec 2007 07:36:56 -0800 (PST), Anant Narayanan
<anant@xxxxxx> wrote:
Hi,
I have a function (let's call it f) that calls 4 other functions (say
f1, f2, f3 and f4) depending on the parameters passed to it. f1, f2,
f3 and f4, call f in turn with a different set of parameters that what
it received and returns that as a value. This goes on until a
terminating condition reaches and f returns a value.
The problem with the code is that it fills up the stack space to
quickly. A typical execution sequence goes on like:
f -> f2 -> f -> f4 -> f -> f1 ..... 100 times ... -> f -> f3 -> f ->
final value
Is there a way in which I can "untangle" this recursion and not
encounter a stack overflow?
Any help would be greatly appreciated.
An obvious way to do this that works in most languages is for f1
et al to return the parameters instead of calling f.
.
- References:
- Untangling Multi-function Recursion
- From: Anant Narayanan
- Untangling Multi-function Recursion
- Prev by Date: Re: Brian Kernighan, maybe I'm not worthy, maybe I'm scum
- Next by Date: Re: If not .Net then what?
- Previous by thread: Re: Untangling Multi-function Recursion
- Next by thread: Commenting functions
- Index(es):
Relevant Pages
|