3 ms·
> This is basically what we're doing, except the stack is inside the trampoline. If you inlined the trampoline into the function itself then that is exactly a r
by a-dub 5y ago
> This is basically what we're doing, except the stack is inside the trampoline. If you inlined the trampoline into the function itself then that is exactly a recursion -> iteration transform.
yeah but aren't you basically creating a stack on the heap, and then running the recursive algorithm there?
i mean more like rewriting the unbounded space recursive version of the fibonacci function as the constant space two temporary iterative version.
- tylerhou 5y agoAh, this is definitely possible as well; you could statically analyze the function and then topologically sort the recursive calls. But that falls into an optimization category which requires some sophisticated analysis. That type of optimization is trivial for fib, but it's really difficult in general. Also, it only easily works where the recursive parameter that is changing is an int/index. You could also make it work with trees/graphs, but that requires some substructural analysis...