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:

    A lazy person, whatever the talents with which he set out, will have condemned himself to second-hand thoughts and to second-rate friends.
    Cyril Connolly (1903–1974)

    Good critical writing is measured by the perception and evaluation of the subject; bad critical writing by the necessity of maintaining the professional standing of the critic.
    Raymond Chandler (1888–1959)