ikarus/scheme/ikarus.promises.ss

27 lines
671 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 "not a procedure" x))
2007-09-02 02:47:50 -04:00
(x))
(define (make-promise proc)
(unless (procedure? proc)
(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*))))))))))