tail recursion optimisation

tail recursion optimisation

(programming)(TRO) Discarding the calling environment (call stack frame) when the last thing a function or proceduredoes is to call itself. This is important when a procedurecalls itself recursively many times since, without tailrecursion optimisation, the environments of earlierinvocations would fill up the memory only to be discarded when(if) the last call terminated.

Tail recursion optimisation is a special case of last call optimisation but it allows the further optimisation that somearguments may be passed in situ, possibly in registers. Itallows recursive functions to be compiled into iterativeloops.

See also conversion to iteration, tail recursion modulo cons.