On this page:
promise?
delay
lazy
force
Version: 4.1

9.3 Delayed Evaluation

 (require scheme/promise)

The bindings documented in this section are provided by the scheme/promise and scheme libraries, but not scheme/base.

A promise encapsulates an expression to be evaluated on demand via force. After a promise has been forced, every later force of the promise produces the same result.

(promise? v)  boolean?

  v : any/c

Returns #t if v is a promise, #f otherwise.

(delay expr)

Creates a promise that, when forced, evaluates expr to produce its value.

(lazy expr)

Like delay, except that if expr produces a promise, then this promise is forced to obtain a value. In other words, this form creates a kind of a composable promise, which is mostly useful for implementing lazy libraries and languages. Also note that the expr in this case is restricted to one that produces a single value.

(force v)  any

  v : any/c

If v is a promise, then the promise is forced to obtain a value. If the promise has not been forced before, then the result is recorded in the promise so that future forces on the promise produce the same value (or values). If forcing the promise raises an exception, then the exception is similarly recorded so that forcing the promise will raise the same exception every time.

If v is forced again before the original call to force returns, then the exn:fail exception is raised.

If v is not a promise, then it is returned as the result.