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)
|
2007-10-25 14:32:26 -04:00
|
|
|
(error 'force "not a procedure" x))
|
2007-09-02 02:47:50 -04:00
|
|
|
(x))
|
|
|
|
|
|
|
|
(define (make-promise proc)
|
|
|
|
(unless (procedure? proc)
|
2007-10-25 14:32:26 -04:00
|
|
|
(error 'make-promise "not a procedure" proc))
|
2007-09-02 02:47:50 -04:00
|
|
|
(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*))))))))))
|
|
|
|
|