Lazy evaluation

From Esolang
Jump to navigation Jump to search

Lazy evaluation or call-by-need is an evaluational plan that waits to process data until it is needed. This is in contrast with strict evaluation, where data is processed as soon as it is seen. As a result, the computer only performs the work necessary to output the final result. Though this may strike the casual reader as a brilliant idea, this approach may result in overhead costs required to store and manage the incomplete processes, often referred to promises, thonks, or futures.

To illustrate, consider the infamously lazy lists of Haskell. Haskell's lists only generate as many of their items as needed. This becomes troublesome when, for instance, summing all the items in the list. Now the Haskell computation must assemble a calculation object with partially applied addition on the entire list and then calculate an often huge expression spontaneously. Such an action can crash the program due to memory overflow. Meanwhile, a strict evaluator would merely store the running total of the summation.

Despite this, lazy evaluation has its merits. Among these are the ability to declare unbounded/infinite lists of values, the evaluation of whose elements can be deferred until necessary. This demonstrates that, while strict evaluators may be easier to implement, both execution strategies have their merits.

Esolangs that utilize lazy evaluation

(See here for a more complete article on the subject)