Christian Neukirchen <chneukirchen / gmail.com> writes:

> George Ogata <g_ogata / optushome.com.au> writes:
>
>> 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)
>
> So what?  It just calls the new definition with a TC and it's
> done...  It can simply detect on each function *definition* whether it
> is going to use TCO.

Yeah, that is kind of obvious now that you say it.  In fact, now that
I read your words again, I realize you said "tail-call" and nothing
about tail recursivity.  I was way off.

Apologies.