2 ms·
> wonder if it would be possible to do automated rewrites of recursive functions as iterative ones. Of course. > specifically for cases where stack memory tha
by thaumasiotes 5y ago
> wonder if it would be possible to do automated rewrites of recursive functions as iterative ones.
Of course.
> specifically for cases where stack memory that grows in a recursive implementation can be replaced by a few long lived temporaries... like the good ol' fibonacci function.
Rewriting a recursive Fibonacci function to use a loop with an explicit stack doesn't do anything about the growth of memory. You'll need just as many stack elements. It's just an explicit stack that you've assigned to a variable rather than being the function call stack.
- coldtea 5y ago>Rewriting a recursive Fibonacci function to use a loop with an explicit stack doesn't do anything about the growth of memory. Sort of. It means the amount of memory you can use is much bigger, and not constrained by the stack size.