Lazy evaluation: Difference between revisions

m
English, paradigm cat
(Created)
 
m (English, paradigm cat)
Line 1:
[[Category:Encyclopedia]][[Category:Programming Paradigms]]'''Lazy evaluation''' describes a strategy of expression evaluation when the evaluation is done as late as possible. The opposite to lazy evaluation is '''eager evaluation''', when the evaluation is performed as early as possible.
 
Usually the programming language do not specify laziness leaving the decision to optimization.
Line 9:
* When the expression value does not depend on the evaluation time, which is usually the case for functional programing languages. In this context lazy evaluation can be used for optimization purposes and as light-weight [[closures]]. Constants folding is an example of eager evaluation optimization.
 
* When the expression value depends on the evaluation time, laziness changes the program semantics. This type of laziness is used in close to hardware and low-level [[concurrent programming]], when the state of an object might change asynchronously to the program. Such objects are usually marked as ''volatile'', and their values are acquired as late as possible. Further, the compiler is instructed not to store them when evaluating temporal expressions.
Anonymous user