Pho Tek wrote:I found that scala has a @tailrec annotation.
Be aware that the @tailrec annotation does not have any functional purpose, i.e. it does not make your tail call optimised when it otherwise is not. All it does is cause the compiler to raise an error if your function is not in the correct format required for optimisation.
Pierre-Yves, what a fascinating solution you posed there. I shall most certainly be implementing this myself just to play with it. I can see how you avoid blowing the stack, but I wonder about Object creation on the heap for very deep recursion? I think some experimentation is in order. However, definitely worthy of a
cow.