- Tail Call - When the last thing a function does is call another function, and then immediately returns the result of that call.
- Tail Recursion - Just a special case of tail call where the function tail called is the same as the caller function. Tail Recursion won't come up again in this post, so if the definition isn't clear, don't worry about it.
- Tail Call Optimization - A compiler technique for avoiding adding an activation record to the stack for a tail call. (However, I don't like the word 'optimization' here. It is more like the correct implementation. More on that later.)
Regular Function Calls
Tail Call Optimization
- How the Scala compiler can turn tail recursive functions into while loops, and why it can't do so with non-final functions.
- What @tailrec does.
- Mutually recursive functions, trampolining and scala.util.control.TailCalls.
- Lambda: the ultimate goto
- Fortress Blog - ObjectOrientedTailRecursion
- Rich Dougherty - Tail Calls, Tail Rec, Trampolines
- John Rose - Tail Calls in the JVM
- Matthias Felleisen - A Tail-Recursive Machine with Stack Inspection
- Stack Overflow - @tailrec and non-final methods