Paul Barry Shows How to Accomplish Tail Call Optimization in JavaScript
Local Polyglot Extraordinare, Paul Barry has been on a JavaScript spree of late, especially in showing how JavaScript compares to other full functional programming languages like Clojure, Haskell, and Erlang. In his most recent article, he goes about showing how to use the accumulator pattern, from the SICP book if I am not mistaken, to accomplish Tail Call Optimization in JavaScript. One of the things he doesn't mention and is a known issue with JavaScript in most interpreters is that after around 1,000 recursive calls the interpreter will exception out the execution regardless. This is done based purely on the call stack and not on memory usage in an (vain) attempt to be protective in nature due to the "constrained" client environment and operating sandbox of JavaScript. It more often then not becomes a pain in the tail (recursion) in the modern era where people have more than 64kb of memory. That said, Paul's technique is a great one that is widely applicable in many formats, not just JavaScript.
Here's hoping he continues to love the JS and what he is doing that has transpired these recent posts.


