► |  | Reference: PLT Scheme

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

▼ | 9 | Control Flow

9.1 | Multiple Values
9.2 | Exceptions
9.3 | Delayed Evaluation
9.4 | Continuations
9.5 | Continuation Marks
9.6 | Breaks
9.7 | Exiting

On this page:

promise?
delay
lazy
force
promise-forced?
promise-running?

Version: 4.1.4
top← prev up next →

#### 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.

(promise-forced? promise) → boolean?
promise : promise?

Returns #t if promise has been forced.

(promise-running? promise) → boolean?
promise : promise?

Returns #t if promise is currently being forced. (Note that a promise can be either running or forced but not both.)

top← prev up next →