lazy evaluation


lazy evaluation

[′lā·zē i‚val·yə′wā·shən] (computer science) demand-driven execution

lazy evaluation

(reduction)An evaluation strategy combining normal order evaluation with updating. Under normal order evaluation(outermost or call-by-name evaluation) an expression isevaluated only when its value is needed in order for theprogram to return (the next part of) its result. Updatingmeans that if an expression's value is needed more than once(i.e. it is shared), the result of the first evaluation isremembered and subsequent requests for it will return theremembered value immediately without further evaluation. Thisis often implemented by graph reduction. An unevaluatedexpression is represented as a closure - a data structurecontaining all the information required to evaluate theexpression.

Lazy evaluation is one evaluation strategy used to implementnon-strict functions. Function arguments may be infinitedata structures (especially lists) of values, the componentsof which are evaluated as needed.

According to Phil Wadler the term was invented by Jim Morris.

Opposite: eager evaluation.

A partial kind of lazy evaluation implements lazy datastructures or especially lazy lists where function argumentsare passed evaluated but the arguments of data constructorsare not evaluated.

Full laziness is a program transformation which aims tooptimise lazy evaluation by ensuring that all subexpressionsin a function body which do not depend on the function'sarguments are only evaluated once.