@andrea: > It is easy to do TCO for self-recursive function. It is essentially not > doable in general, unless one controls the generated assembly...
Tail recursion optimization is an interesting topic, do you have any links providing examples on how to do it in Nim? I wonder ... if Nim were to support labels to mark code positions and some kind of GoTo like statement, maybe tail-recursion could be worked around by them. But I guess this would add potential complications to the language, for you can't just use GoTo to jump in-and-out stack frames wrecklessly. Nevertheless, GoTo has been used to circumvent tail recursions in languages that support the instruction (the debate on the merits and dangers of GoTo have been debated for a long time). But that's a viable (unsafe) alternative to editing the generated Assembly, by jumping to specific position in the code.