Debian Codegraph @

scheme/ikarus.promises.ss

raw
1 ;;; Ikarus Scheme -- A compiler for R6RS Scheme.
2 ;;; Copyright (C) 2006,2007,2008 Abdulaziz Ghuloum
3 ;;;
4 ;;; This program is free software: you can redistribute it and/or modify
5 ;;; it under the terms of the GNU General Public License version 3 as
6 ;;; published by the Free Software Foundation.
7 ;;;
8 ;;; This program is distributed in the hope that it will be useful, but
9 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
10 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 ;;; General Public License for more details.
12 ;;;
13 ;;; You should have received a copy of the GNU General Public License
14 ;;; along with this program. If not, see <http://www.gnu.org/licenses/>.
15
16
17 (library (ikarus promises)
18 (export force make-promise)
19 (import
20 (except (ikarus) force make-promise))
21
22 (define (force x)
23 (unless (procedure? x)
24 (die 'force "not a procedure" x))
25 (x))
26
27 (define (make-promise proc)
28 (unless (procedure? proc)
29 (die 'make-promise "not a procedure" proc))
30 (let ([results #f])
31 (lambda ()
32 (if results
33 (apply values results)
34 (call-with-values proc
35 (lambda x*
36 (if results
37 (apply values results)
38 (begin
39 (set! results x*)
40 (apply values x*))))))))))
41