views:

281

answers:

1

What is the theoretical/practical limit to the recursion depth in languages implementing Tail Call optimisation? (Please assume that the recurring function is properly tail call-ed).

My guess is that the theoretical limit is NONE, as there is no recursive process, even though it is recursive procedure. Practical limit would be that allowed by the main memory available to be used. Please clarify or correct if I am wrong somewhere.

+4  A: 

When a tail recursive function is optimized, it'll essentially become an iterative function. The compiler reuses the stack frame of the original call for subsequent calls, so you won't run out of stack space. If you are not allocating any heap memory (or any other kind of memory that's not on the stack, for that matter), you can have infinitely deep (as long as you are patient enough ;)) recursion (think of it as an infinite loop; it has the same characteristics).

To summarize, there's no practical limit.

Mehrdad Afshari
I am currently waiting for (waiting for (factorial 10000000000) to finish :)
Amit