Tail call optimisation in Javascript

I just happend across this old link

Basically it’s a (surprisingly elegant) way of creating tail call optimised functions in javascript.

There’s a slight subtlety with it unfortunately – you can’t simultaneously have a function call itself in a non-tail recursive manner. If you do it will break things.

It claims to support mutually recursive functions, and I think this is true, but I bet you’ll find there are some finicky details which can cause the stack to grow unboundedly before the optimisation kicks in, and I think you might have trouble properly optimising mutally recursive calls in this manner.

Still, very cool.

This entry was posted in programming and tagged , on by .