tail recursion

(redirected from Tail-recursion)

tail recursion

(programming)
When the last thing a function (or procedure) does is to call itself. Such a function is called tail recursive. A function may make several recursive calls but a call is only tail-recursive if the caller returns immediately after it. E.g.

f n = if n < 2 then 1 else f (f (n-2) + 1)

In this example both calls to f are recursive but only the outer one is tail recursive.

Tail recursion is a useful property because it enables tail recursion optimisation.

If you aren't sick of them already, see recursion and tail recursion.
References in periodicals archive ?
Extensions to other features such as tail-recursion elimination and first-class continuations are quite easy to make, though we do not include them in this article.
We also find that evaltrace is flexible-- extensions to other features of Lisp such as tail-recursion elimination and first-class continuations (CALL/CC) are quite easy to make, though we have not included them in this article.
Other areas for further development of evaltrace notation include extensions to express tail-recursion elimination, first-class continuations, and multiple closures with a shared parent contour.