functional programming - Does Ruby perform Tail Call Optimization? -
Functional languages use recursive to solve many problems, and so many of them will be able to optimize the call TCO). The TCO calls the function from any other function (or by itself, in which case this feature is also known as tile Rickingsian elimination, which is a subset of TCO), as the last step of that function, A new stack frame is not required, which reduces overhead and memory usage.
Ruby has obviously "borrowed" many concepts from functional languages (Lambda, Map and further functions like), making me curious: Do Ruby Tail Do Call Optimization?
No, Ruby does not show TCO, however, also not TCO Does not show up.
Ruby language specificity does not say anything about TCO. It does not say that you have to do this, but do not even say that you can not do that you can not trust on it.
This is contrary to the plan, where the language specificity is required is that all should implement TCO display but it does not have Python , Where Gideon van Rossam has made it very clear on several occasions (just a few days ago) that the Python implementation should not not TCO perform.
Yukihiro Matsumoto sympathizes with TCO, he just does not want to force all to implement it. Unfortunately, this means that you can not trust TCO, or if you do, your code will not be portable to apply other ruby.
So, some Ruby implementations do to TCO, but most do not. For example, for example, supports TCO, however (for the moment) you have to explicitly dismiss a line in the source code and recompile the VC so that TCO can be activated - future versions After this implementation has been proven, will be turned on by default in the stable. The parrot virtual machine supports TCO basically, so the cardinal can easily support it. CLR has some support for TCO, which means that IronRuby and Ruby.NET could probably do this. Rubinis could possibly do this.
But Jerubi and Anturu do not support TCO, and they probably will not do this unless JVM does not get support for TCO itself. The problem is: If you want fast implementation with Java, and want fast and seamless integration, you should be stack-compatible with Java and should use the JVM stack as much as possible. You can easily apply TCO trumpoline or with a clear continuity-passing style, but then you are no longer using JVM stack, which means that every time you want to call in Java or in Ruby from Java Need to call, you have to perform some kind of conversion, which is slow, therefore, XRuby and JRuby decided to go with TCO and the speed of continuation and Java integration (which is the basic form Area have the same problem).
This applies to all the implementations of Ruby which is tightly integrated with some host platforms does not support TCO originally. For example, I think MacRuby has the same problem.
Comments
Post a Comment