In computer science, a tail call is a subroutine call that happens inside another procedure as its final action; it may produce a return value which is then immediately returned by the calling procedure. The call site is then said to be in tail position, i.e. at the end of the calling procedure. If any call that a subroutine performs, such that it might eventually lead to this same subroutine being called again down the call chain, is in tail position, such a subroutine is said to be tail-recursive. This is a special case of recursion.
Tail calls are significant because they can be implemented without adding a new stack frame to the call stack. Most of the frame of the current procedure is not needed any more, and it can be replaced by the frame of the tail call, modified as appropriate (similar to overlay for processes, but for function calls). The program can then jump to the called subroutine. Producing such code instead of a standard call sequence is called tail call elimination, or tail call optimization.
Traditionally, tail call elimination is optional. However, in functional programming languages, tail call elimination is often guaranteed by the language standard, and this guarantee allows using recursion, in particular tail recursion, in place of loops. In such cases, it is not correct (though it may be customary) to refer to it as an optimization.
Read more about Tail Call: Description, Syntactic Form, Example Programs, Tail Recursion Modulo Cons, History, Implementation Methods
Famous quotes containing the words tail and/or call:
“And how do you know that youre mad?
To begin with, the Cat said, a dogs not mad. You grant that?
I suppose so, said Alice.
Well then, the Cat went on, you see a dog growls when its angry, and wags its tail when its pleased. Now I growl when Im pleased, and wag my tail when Im angry. Therefore Im mad.”
—Lewis Carroll [Charles Lutwidge Dodgson] (18321898)
“Politics is repetition. It is not change. Change is something beyond what we call politics. Change is the essence politics is supposed to be the means to bring into being.”
—Kate Millett (b. 1934)