From: George Ogata Date: 2005-06-16T20:34:41+09:00 Subject: Re: Ruby and recursion (Ackermann benchmark) Christian Neukirchen writes: > George Ogata writes: > >> Christian Neukirchen 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.