3 ms·
While it is perhaps useful to think of tail-call elimination as changing a recursive function into a while loop is a useful first approximation (and is how it i
by dwohnitmok 7y ago
While it is perhaps useful to think of tail-call elimination as changing a recursive function into a while loop is a useful first approximation (and is how it is implemented in e.g. Scala), this is not really an accurate picture of tail-call elimination in general. Indeed it breaks down when considering mutually recursive functions.
Tail-call elimination is simply the observation that in a tail position you do not keep a reference to the parent function around after you've called the child function.
If function calls happen on the heap instead of the stack for example, then tail-call elimination is done simply as a matter of course by the garbage collector.