Tail recursion
Tail recursion is a special way of writing recursive functions such that a compiler can optimize the recursion away and implement the algorithm as a loop instead. This is not because loops are inherently faster, but because every function call generally incurs the cost of a new stack frame in which it executes, sometimes leading to the dreaded
stack overflow
- where the beloved site of the same name, gets its name. Let's investigate how this works.
Source: Tail recursion, an article by Tarjei Skjærset.