Design patterns·Functional ideas that went mainstream
the recursion went a million deep and the stack never grew, because the call was the very last thing the function did.
Tail call optimisation
Also calledTCO, tail call elimination, proper tail calls
A compiler transformation that reuses the current stack frame when a call is the final action of a function, turning recursion into iteration. Where it is guaranteed, recursion is a normal control structure; where it is not, deep recursion is a stack overflow waiting for a large input. Knowing which of those you are in is the difference between elegant and fragile.