27 lines
683 B
Scheme
27 lines
683 B
Scheme
|
|
(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*))))))))))
|
|
|