Join GitHub today
Add a mechanism for implict and/or explicit tail call optimisation #138
Performing TCO for a method that calls itself is a great start however when dealing with OO data structures, it's more common to call methods on other instances and/or mutual recursion between two methods--be they on the same or a different instance.
For example, imagine traversing a linked list recursively:
This works great for small-ish lists but when processing larger lists stack overflows are common place. To remedy this, it needs to be re-written iteratively:
Not only is the latter more verbose, but in either case, without TCO, because the code always executes in the context of the first element, the traversal must complete before the garbage collector has a chance to reap unreferenced elements.
It would be great if Rubinius could provide a mechanism for implicit or explicit tail-call elimination for any returning statement that no longer requires the stack.
I have a project for which I REALLY need this and thus I'm VERY motivated to work on it. I just need a little direction as to how to proceed.