3 ms·
Understanding Tail Recursion
- octo_t 13y agoA useful term when understanding tail recursion is "trampoline"[1], even though most compilers don't use this, it is a very useful way of visualising tail recursive calls. [1] - https://en.wikipedia.org/wiki/Tail_call#Through_trampolining https://en.wikipedia.org/wiki/Tail_call#Through_trampolining
- tmoertel 13y agoIf anybody is interested in trampolines, I just wrote an introduction to them that uses Python examples and includes a runtime visualization so you can see what's happening with the stack: http://blog.moertel.com/posts/2013-06-12-recursion-to-iteration-4-trampolines.html http://blog.moertel.com/posts/2013-06-12-recursion-to-iterat...
- cdl 13y agoGreat read so far.
- taylodl 13y agoYou can trampoline in JavaScript too. I showed how the performance may not be as you expect: http://taylodl.wordpress.com/2013/06/07/functional-javascript-tail-call-optimization-and-trampolines/ http://taylodl.wordpress.com/2013/06/07/functional-javascrip...