sigildocs

(scheme lazy)

(scheme lazy) - R7RS Lazy Evaluation Library

Lazy evaluation with promises. Defer computation until explicitly needed with force. Promises cache their result so repeated forcing is efficient.

See: R7RS Small §4.2.5

Exports

forceprocedure

Force evaluation of a promise.

If the promise has not been forced before, evaluates its expression and caches the result. Returns the cached value on subsequent calls.

(define p (delay (begin (display "computing...") 42)))
(force p)  ; prints "computing...", returns 42
(force p)  ; returns 42 (no output, cached)
make-promiseprocedure

Create a promise from an already-computed value.

Unlike delay, does not defer computation. The value is stored immediately.

(define p (make-promise 42))
(force p)    ; => 42
(promise? p) ; => #t
promise?procedure

Test if an object is a promise.

(promise? (delay 42))       ; => #t
(promise? (make-promise 1)) ; => #t
(promise? 42)               ; => #f