Search results
Results from the WOW.Com Content Network
Tail recursion modulo cons is a generalization of tail-recursion optimization introduced by David H. D. Warren [9] in the context of compilation of Prolog, seen as an explicitly set once language. It was described (though not named) by Daniel P. Friedman and David S. Wise in 1974 [10] as a LISP compilation technique. As the name suggests, it ...
Continuation passing style can be used to implement continuations and control flow operators in a functional language that does not feature first-class continuations but does have first-class functions and tail-call optimization. Without tail-call optimization, techniques such as trampolining, i.e. using a loop that iteratively invokes thunk ...
The recursive program above is tail-recursive; it is equivalent to an iterative algorithm, and the computation shown above shows the steps of evaluation that would be performed by a language that eliminates tail calls. Below is a version of the same algorithm using explicit iteration, suitable for a language that does not eliminate tail calls.
Iterative algorithms can be implemented by means of recursive predicates. Prolog systems typically implement a well-known optimization technique called tail call optimization (TCO) for deterministic predicates exhibiting tail recursion or, more generally, tail calls: A clause's stack frame is discarded before performing a call in a tail ...
As with direct recursion, tail call optimization is necessary if the recursion depth is large or unbounded, such as using mutual recursion for multitasking. Note that tail call optimization in general (when the function called is not the same as the original function, as in tail-recursive calls) may be more difficult to implement than the ...
The Scheme language standard requires implementations to support proper tail recursion, meaning they must allow an unbounded number of active tail calls. [60] [61] Proper tail recursion is not simply an optimization; it is a language feature that assures users that they can use recursion to express a loop and doing so would be safe-for-space. [62]
Therefore, compilers will attempt to transform the first form into the second; this type of optimization is known as map fusion and is the functional analog of loop fusion. [ 2 ] Map functions can be and often are defined in terms of a fold such as foldr , which means one can do a map-fold fusion : foldr f z . map g is equivalent to foldr (f .
Tail-recursive algorithms can be converted to iteration through a process called tail-recursion elimination or tail-call optimization. Deforestation ( data structure fusion) In languages where it is common for a sequence of transformations to be applied to a list, deforestation attempts to remove the construction of intermediate data structures.