Christian Neukirchen <chneukirchen / gmail.com> writes:

> The real question is why the Ruby interpreter doesn't do tail-call
> optimization...

Wouldn't this be tricky in the general case?  Consider:

  def f arg
    (class << arg; self; end).send(:define_method, :f){|a| 10}
    f(1)
  end

`f' looks tail recursive but isn't since it may redefine itself:

  f(self)

We could just sweep the problem under the rug (optimize anyway and
hope no-one tries anything that crazy).  Or we could resort to a new
keyword, say `recurse(...)', which would mean "call the function it
appears in".  That would be optimizable.

Just a thought.