I have a tail recursive pathfinding algorithm that I've implemented in Javascript and would like to know if any (all?) browsers would possibly get stack overflow exceptions.
+2
A:
Pretty much every browser you encounter will barf on "too much recursion". Here's an entry in the V8 bug tracker that will probably be interesting reading.
If it's simple self-recursion, it's probably worth the effort to use explicit iteration rather than hoping for tail-call elimination.
Hank Gay
2010-09-07 16:31:59
+7
A:
The ECMAScript 4 spec was originally going to add support for TCO, but it was dropped.
http://lambda-the-ultimate.org/node/3047
As far as I know, no widely-available implementations of JS currently do automatic TCO. This may be of use to you, though:
http://paulbarry.com/articles/2009/08/30/tail-call-optimization
Essentially, using the accumulator pattern accomplish the same effect.
Tim Sylvester
2010-09-07 16:33:37
Or just use a trampoline...
sclv
2010-09-08 00:58:06