1 Language Model
2 Syntactic Forms
3 Datatypes
4 Structures
5 Classes and Objects
6 Units
7 Contracts
8 Pattern Matching
9 Control Flow
10 Concurrency
11 Macros
12 Input and Output
13 Reflection and Security
14 Operating System
15 Memory Management
16 Running PLT Scheme
Bibliography
Index
On this page:
promise?
delay
lazy
force
Version: 4.0.2

 

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 the promise is forced to obtain a 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.