Re:Tail Recursion
by sdevlin on Tuesday November 27, 2012 @12:22PM
(#4837710)
Decent explanation, but I have a couple quibbles.
First, the term "tail recursion" is overly narrow. This transformation should apply to all tail calls, not just recursive ones. This is useful, for example, in families of mutually recursive functions.
Second, this transformation is not really an optimization, as it changes the behavior of some programs (by preventing stack overflow or memory allocation errors). It's a documented feature of languages (or specific implementations of languages) that users rely on to write programs in a particular style.
I prefer the term "tail call elimination" to describe these transformations.
Re:Tail Recursion
by kvb on Tuesday November 27, 2012 @12:50PM
(#4837753)
Of course, some languages only support elimination of tail calls when they're recursive. I believe that Scala suffers from this (since the JVM doesn't support tail call elimination).
First, the term "tail recursion" is overly narrow. This transformation should apply to all tail calls, not just recursive ones. This is useful, for example, in families of mutually recursive functions.
Second, this transformation is not really an optimization, as it changes the behavior of some programs (by preventing stack overflow or memory allocation errors). It's a documented feature of languages (or specific implementations of languages) that users rely on to write programs in a particular style.
I prefer the term "tail call elimination" to describe these transformations.