summaryrefslogtreecommitdiff
path: root/module/srfi/srfi-45.scm
diff options
context:
space:
mode:
authorMark H Weaver <mhw@netris.org>2013-03-18 20:01:12 -0400
committerMark H Weaver <mhw@netris.org>2013-03-19 10:29:44 -0400
commit1d64b4edb9da4011ad06c0fab1c6225ec20b0876 (patch)
tree69b2edd1a1917b861c6a2b3932d81f0fc60daa4f /module/srfi/srfi-45.scm
parent8150dfa1f2f84d151ced5f723dc69ce0cae1cd32 (diff)
downloadguile-1d64b4edb9da4011ad06c0fab1c6225ec20b0876.tar.gz
SRFI-45: Support multiple values; add promise? predicate.
* module/srfi/srfi-45.scm (eager): Accept any number of arguments. Store the list of arguments in the value record. Previously, only one argument was accepted, and that value was stored in the value record. (delay): Support expressions that return any number of arguments. (force): Return the list of values stored in the value record. (promise?): Export. * doc/ref/srfi-modules.texi (SRFI-45): Update docs. Remove typing for simplicity in discussing multiple values. * test-suite/tests/srfi-45.test: Add tests. Add FSF copyright for 2010 and 2013. Add missing year to André van Tonder's copyright notice.
Diffstat (limited to 'module/srfi/srfi-45.scm')
-rw-r--r--module/srfi/srfi-45.scm21
1 files changed, 12 insertions, 9 deletions
diff --git a/module/srfi/srfi-45.scm b/module/srfi/srfi-45.scm
index 29b0393ff..47e3ba605 100644
--- a/module/srfi/srfi-45.scm
+++ b/module/srfi/srfi-45.scm
@@ -1,6 +1,6 @@
;;; srfi-45.scm -- Primitives for Expressing Iterative Lazy Algorithms
-;; Copyright (C) 2010, 2011 Free Software Foundation, Inc.
+;; Copyright (C) 2010, 2011, 2013 Free Software Foundation, Inc.
;; Copyright (C) 2003 André van Tonder. All Rights Reserved.
;; Permission is hereby granted, free of charge, to any person
@@ -25,8 +25,8 @@
;;; Commentary:
-;; This is the code of the reference implementation of SRFI-45, slightly
-;; modified to use SRFI-9.
+;; This is the code of the reference implementation of SRFI-45,
+;; modified to use SRFI-9 and to support multiple values.
;; This module is documented in the Guile Reference Manual.
@@ -36,8 +36,9 @@
#:export (delay
lazy
force
- eager)
- #:replace (delay force)
+ eager
+ promise?)
+ #:replace (delay force promise?)
#:use-module (srfi srfi-9))
(define-record-type promise (make-promise val) promise?
@@ -50,16 +51,18 @@
(define-syntax-rule (lazy exp)
(make-promise (make-value 'lazy (lambda () exp))))
-(define (eager x)
- (make-promise (make-value 'eager x)))
+(define (eager . xs)
+ (make-promise (make-value 'eager xs)))
(define-syntax-rule (delay exp)
- (lazy (eager exp)))
+ (lazy (call-with-values
+ (lambda () exp)
+ eager)))
(define (force promise)
(let ((content (promise-val promise)))
(case (value-tag content)
- ((eager) (value-proc content))
+ ((eager) (apply values (value-proc content)))
((lazy) (let* ((promise* ((value-proc content)))
(content (promise-val promise))) ; *
(if (not (eqv? (value-tag content) 'eager)) ; *