Lazy Evaluation

In programming language theory, lazy evaluation or call-by-need 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 (sharing). The sharing can reduce the running time of certain functions by an exponential factor over other non-strict evaluation strategies, such as call-by-name.

The benefits of lazy evaluation include:

  • Performance increases by avoiding needless calculations, and error conditions in evaluating compound expressions
  • The ability to construct potentially infinite data structures
  • The ability to define control flow (structures) as abstractions instead of primitives

Lazy evaluation can lead to reduction in memory footprint, since values are created when needed. However, with lazy evaluation, it is difficult to combine with imperative features such as exception handling and input/output, because the order of operations becomes indeterminate. Lazy evaluation can introduce space leaks.

The opposite of lazy actions is eager evaluation, sometimes known as strict evaluation. Eager evaluation is commonly the default behavior used in programming languages.

Read more about Lazy Evaluation:  History, Applications, Laziness in Eager Languages, Controlling Eagerness in Lazy Languages

Famous quotes containing the words lazy and/or evaluation:

    The dreary flies, lazy and casual,
    Stick to the ceiling, buzz along the wall.
    O heart, the spider shuffles from the mould
    Weaving, between the pinks and grapes, his pall.
    Allen Tate (1899–1979)

    Evaluation is creation: hear it, you creators! Evaluating is itself the most valuable treasure of all that we value. It is only through evaluation that value exists: and without evaluation the nut of existence would be hollow. Hear it, you creators!
    Friedrich Nietzsche (1844–1900)