In programming language theory, lazy evaluation, or call-by-need,[1] is an evaluation strategy which delays the evaluation of an expression until its value is needed (non-strict evaluation) and which also avoids repeated evaluations (by the use of sharing).[2][3]
The benefits of lazy evaluation include:
The ability to define control flow (structures) as abstractions instead of primitives.
The ability to define potentially infinite data structures. This allows for more straightforward implementation of some algorithms.
The ability to define partly-defined data structures where some elements are errors. This allows for rapid prototyping.
Lazy evaluation is often combined with memoization, as described in Jon Bentley's Writing Efficient Programs.[4] After a function's value is computed for that parameter or set of parameters, the result is stored in a lookup table that is indexed by the values of those parameters; the next time the function is called, the table is consulted to determine whether the result for that combination of parameter values is already available. If so, the stored result is simply returned. If not, the function is evaluated, and another entry is added to the lookup table for reuse.
Lazy evaluation is difficult to combine with imperative features such as exception handling and input/output, because the order of operations becomes indeterminate.
The opposite of lazy evaluation is eager evaluation, sometimes known as strict evaluation. Eager evaluation is the evaluation strategy employed in most[quantify] programming languages.
^Hudak 1989, p. 384
^David Anthony Watt; William Findlay (2004). Programming language design concepts. John Wiley and Sons. pp. 367–368. ISBN 978-0-470-85320-7. Retrieved 30 December 2010.
^Reynolds 1998, p. 307
^Bentley, Jon Louis. Writing Efficient Programs. Prentice-Hall, 1985. ISBN 978-0139702440
In programming language theory, lazyevaluation, or call-by-need, is an evaluation strategy which delays the evaluation of an expression until its value...
and some authors define lazyevaluation as normal order evaluation or vice-versa, or confuse non-strictness with lazyevaluation.: 43–44 Boolean expressions...
before invoking the function. Lazyevaluation does not evaluate function arguments unless their values are required to evaluate the function call itself....
expensive process until the first time it is needed. It is a kind of lazyevaluation that refers specifically to the instantiation of objects or other resources...
statically-typed, purely functional programming language with type inference and lazyevaluation. Designed for teaching, research, and industrial applications, Haskell...
non-strict evaluation, an evaluation strategy where the arguments to a function are not immediately evaluated. This form of non-strict evaluation is also...
programs are evaluated, since eager evaluation will return the same result as lazyevaluation. However, it is still possible that an eager evaluation may not...
in call by need. Lazy futures are of use in languages which evaluation strategy is by default not lazy. For example, in C++11 such lazy futures can be created...
The term Lazy specification is coined by analogy with lazyevaluation in functional programming. The latter describes the delayed evaluation of sub-expressions...
summarized below. Lazyevaluation is particularly interesting in a purely functional language: 31 because the order of the evaluation never changes the...
allows the user to define non-strict functions, and hence may allow lazyevaluation. In most non-strict languages, the non-strictness extends to data constructors...
programming concepts. It was first used for early experimentation with lazyevaluation. An SECD machine-based implementation written in an ALGOL variant was...
are normally eager evaluation, but a lazyevaluation option exists, indicated by the use of the d operator. Usually, to evaluate an expression of the...
defined as having a strict evaluation strategy, although there are non-conforming back ends which implement a lazyevaluation strategy. PureScript was initially...
(1993). Partial Evaluation and Automatic Program Generation. Prentice Hall. ISBN 9780130202499. Danvy, O., ed. (1999). "Partial Evaluation and Semantics-Based...
article: The Paging Game Page cache Memory management Virtual memory Lazyevaluation Tanenbaum, Andrew S. Operating Systems: Design and Implementation (Second...
optimizing code by means of memoization, common subexpression elimination, lazyevaluation, or parallelization. The concept originated in Alfred North Whitehead...
use a lazyevaluation, that is, if the value of the expression can be determined from the left hand Boolean expression then they do not evaluate the right...
Comparative Notes on Algol 68 and PL/I – S. H. Valentine – November 1974 1976 – Evaluation of ALGOL 68, JOVIAL J3B, Pascal, Simula 67, and TACPOL Versus TINMAN –...