3 ms·
> then you get tail-calls for every function, which effectively obviates the stack. This is true, however CPS moves the work from the stack to the heap, so a d
by siraben 6y ago
> then you get tail-calls for every function, which effectively obviates the stack.
This is true, however CPS moves the work from the stack to the heap, so a deep enough recursion would exhaust the heap instead. Using a trampoline[0] in conjunction with CPS ensure constant stack usage for tail-recursive functions.
[0] https://en.wikipedia.org/wiki/Trampoline_(computing) https://en.wikipedia.org/wiki/Trampoline_(computing)