4 ms·
Trampolining is a technique to achieve Tail-call Elimination in ES5 [1] However, I found this to only work in a linearly recursive algorithm (eg factorial) and
by mck- 12y ago
Trampolining is a technique to achieve Tail-call Elimination in ES5 [1]
However, I found this to only work in a linearly recursive algorithm (eg factorial) and not in a bi-directional recursive algorithm (eg tree construction)
I'm thinking TCO in ES6 might solve this problem? Anyone tried?
[1] http://raganwald.com/2013/03/28/trampolines-in-javascript.html http://raganwald.com/2013/03/28/trampolines-in-javascript.ht...
- kevingadd 12y agoAnother problem with trampolining in ES5 is that it produces GC pressure; not particularly ideal. TCO in future versions of JavaScript should be a big win, if only in that area.
- justincormack 12y agoApart from knowing if your environment supports TCO which could be an issue.
- esailija 12y agoChallenge accepted https://gist.github.com/petkaantonov/067c5f21395e7fe1f81d https://gist.github.com/petkaantonov/067c5f21395e7fe1f81d
- taylodl 12y agoI blogged about the advantages/disadvantages of trampolines in JavaScript a while back. See http://taylodl.wordpress.com/2013/06/07/functional-javascript-tail-call-optimization-and-trampolines/ http://taylodl.wordpress.com/2013/06/07/functional-javascrip.... I'm preparing to analyze TCO in ES6. I'll do a write up of my analysis.