developerWorks: Lazy Programming and Lazy Evaluation

[ Thanks to An Anonymous Reader for
this link. ]

“Lazy programming is a technique that lets you delay the
evaluation of code until you need the resulting value. In Scheme,
for example, lazy programming is explicitly supported through two
special constructs. Scheme’s delay special form takes a block of
code and, rather than executing it, stores the code and its
parameters as a promise. If you force the promise to produce a
value, it will then run the code. The promise then saves the
result, so that future requests for the value will be returned
instantly without having to execute the code again.

“Here is a simple example of how delay and force work

Complete Story

Get the Free Newsletter!

Subscribe to Developer Insider for top news, trends, & analysis