Tail recursion

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. [Jargon File] (2006-04-16)


Read Also:

  • Tail recursion modulo cons

    programming, compiler A generalisation of tail recursion introduced by D.H.D. Warren. It applies when the last thing a function does is to apply a constructor functions (e.g. cons) to an application of a non-primitive function. This is transformed into a tail call to the function which is also passed a pointer to where its result […]

  • Tail recursion optimisation

    programming (TRO) Discarding the calling environment (call stack frame) when the last thing a function or procedure does is to call itself. This is important when a procedure calls itself recursively many times since, without tail recursion optimisation, the environments of earlier invocations would fill up the memory only to be discarded when (if) the […]

  • Tail rotor

    noun 1. a small propeller fitted to the rear of a helicopter to counteract the torque reaction of the main rotor and thus prevent the body of the helicopter from rotating in an opposite direction

  • Tails

    adjective, adverb 1. (of a coin) with the reverse facing up: On the next toss, the coin came up tails. Compare heads. noun 2. tail1 (def 6). noun 1. the hindmost part of an animal, especially that forming a distinct, flexible appendage to the trunk. 2. something resembling or suggesting this in shape or position: […]

Disclaimer: Tail recursion definition / meaning should not be considered complete, up to date, and is not intended to be used in place of a visit, consultation, or advice of a legal, medical, or any other professional. All content on this website is for informational purposes only.