From: gabriele renzi Date: 2005-12-17T23:22:47+09:00 Subject: Re: Ruby tail recursion Collins, Justin ha scritto: > Yes, you are right - it can improve performance. What I meant was more that performance gains aren't usually the reason for doing it. > > However, I am fairly sure it isn't that difficult (in the general case) to implement tail > calls this way. For example, in one of my classes we implemented a parser, > interpreter,stack,heap,etc. with proper tail calls. > Of course, it was for a tiny language, so that's why I'm not sure > about how easy it would be to do with Ruby. > > The article you linked says at the end: > "Automatic optimization, on the other hand, is easy to implement in a compiler > and has little run-time cost. It will always identify opportunities for > tail recursion removal, even in complex functions. It improves execution > time without degrading the quality of source code, in some > cases by more than 700%, and can even beat carefully hand-optimized > code. Tail recursion removal frees the programmer to program > in the most elegant and natural style, without worrying about > performance problems resulting from inefficient language implementations." > > Sounds like a good reason to implement it to me! > > I do agree that Ruby doesn't encourage programming recursively, really, but why shouldn't it? Recursion isn't necessary, but it can allow for "nicer" solutions to naturally recursive problems. > > BTW, I am not going to be upset if this isn't implemented in Ruby, I'm just saying it would nice :) > > -Justin I think it is worth noting that Koichi Sasada said once that he plans to support tail call optimization in YARV, even because IIRC he wants it to be able to support Scheme too, which requires TCO. I think he'd appreciate if someone could do that (hint! hint!).