ikarus/scheme/ikarus.promises.ss

27 lines
683 B
Scheme
Raw Normal View History

2007-09-02 02:47:50 -04:00
(library (ikarus promises)
(export force make-promise)
(import
(except (ikarus) force make-promise))
(define (force x)
(unless (procedure? x)
(error 'force "~s is not a procedure" x))
(x))
(define (make-promise proc)
(unless (procedure? proc)
(error 'make-promise "~s is not a procedure" proc))
(let ([results #f])
(lambda ()
(if results
(apply values results)
(call-with-values proc
(lambda x*
(if results
(apply values results)
(begin
(set! results x*)
(apply values x*))))))))))