1.8.x is the current stable version of Ruby’s reference implementation. It, like its predecessors, does not support tail call optimization for recursive functions.

A couple times in recent months I set out to write something in Ruby and found myself thinking “I should do this with a recursive function.” Then I’d rattle around inside my head, trying to figure out why I can’t remember how to write tail recursive functions in Ruby. Finally, I’d realize “Oh, damn — that’s right! Ruby doesn’t support tail call optimization.” At that point, I’d just throw away my initial idea of how to write the code and reorganize the idea to use one of Ruby’s excellent block-fed iterators instead.

Ruby’s iterators that take blocks as parameters are beautiful things to behold, for what they are. Unfortunately, they are sometimes not the ideal solution — just the necessary solution if you don’t want to drag your code to a painstaking crawl, filling up all available RAM on your system, because there’s no tail call optimization. This is one of Ruby’s biggest, ugliest warts, in my opinion: the lack of support for tail call optimization. I wants my tail call optimization.

I started searching for information on future planned support for tail call optimization tonight, and found a Weblog post talking about how bare recursion is much faster in Ruby 1.9 than Python 2.5. This is not even tail recursive code in the example. Discussion in comments there suggests that Python 2.5 does not support tail call optimization, and whether Ruby 1.9 will support tail call optimization is essentially impossible to determine from this discussion, since support for tail call optimization wouldn’t make any difference in this case and the people involved in the discussion seem confused about the matter in any case.

I’ve searched around elsewhere on the Web for this information (though not exhaustively), and still found nothing that gives me any credible sense of whether Ruby 1.9 incorporates tail call optimization.

Is there someone out there who can answer this question for me?