I'm not really a fan of "compiling" tail calls in to while loops. I played
around with trampolining a while back, and I think it is the best solution
to this problem. You mention performance as being a deterrent to using
trampolining, and that just doesn't make too much sense to me. First, I
wouldn't worry about it until you have found that the cost of the
trampolining is the bottleneck in your program. Second, you can always just
transform the code to use continuation passing style and blow out the stack
with a setTimeout every now and then. That way you don't need to create all
of these intermediate objects or rebind the context all the time.

I tried playing around to make the syntax nicer, but I broke mutual
recursion: https://gist.github.com/749901

Gerard Paapu shared his trampolining implementation with me (requires
MooTools, I believe) which does mutual recursion:
https://gist.github.com/749904

It is popular to talk about how functional JS is; I guess I am guilty too,
being the author of Wu.js. But really, the fact that we have to resort to
stuff like this just to get TCO makes me sad.

_Nick_



On Mon, Dec 20, 2010 at 10:45 AM, glathoud <[email protected]> wrote:

> Hello,
>
> I have been exploring some ways to optimize tail calls in Javascript.
> In case of interest: http://glat.info/jscheck/tomrec.xhtml
>
> Comments are welcome.
>
> Best regards,
> Guillaume Lathoud
>
> --
> To view archived discussions from the original JSMentors Mailman list:
> http://www.mail-archive.com/[email protected]/
>
> To search via a non-Google archive, visit here:
> http://www.mail-archive.com/[email protected]/
>
> To unsubscribe from this group, send email to
> [email protected]<jsmentors%[email protected]>
>

-- 
To view archived discussions from the original JSMentors Mailman list: 
http://www.mail-archive.com/[email protected]/

To search via a non-Google archive, visit here: 
http://www.mail-archive.com/[email protected]/

To unsubscribe from this group, send email to
[email protected]

Reply via email to