x-lang

← Index

x/type/promise

Lazy evaluation: the delay form plus the Promise class.

Promises are memoized – forced only once.

delay

Create a promise that delays evaluation of an expression until forced.

Class Promise

(Promise promise? x)

Test whether a value is a promise.

Parameters:

Returns: BOOL — True if x is a promise

(Promise force p)

Force a promise, returning its cached value. Non-promises pass through.

Parameters:

Returns: ANY — The forced value, or p itself if not a promise

Examples:

(Promise force (delay (+ 1 2))) => 3