[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Compatible support for multiple values in SRFI-45

Here's another approach to supporting multiple values in SRFI-45, which
will most likely be deployed in Guile 2.0.8.  In this approach, 'eager'
remains a procedure, but one that accepts any number of arguments.  It
is therefore used in the same way as 'values'.

This approach has the benefit of full compatibility with existing code
that uses SRFI-45.  Furthermore, the attached patch maintains _binary_
compatibility [1] with code that was compiled for the unmodified SRFI-45
reference implementation (a requirement for inclusion in the Guile 2.0
stable series): although the 'delay' macro has changed, code that was
expanded using the old 'delay' macro will continue to work properly with
the new procedures.

Comments and suggestions welcome.


[1] Assuming that neither 'eager' nor 'force' are inlined in the
    compiled code.

--- srfi-45.scm	2013-03-19 10:59:29.024514686 -0400
+++ srfi-45-with-mv.scm	2013-03-19 11:00:52.046923561 -0400
@@ -13,17 +13,19 @@
     ((lazy exp)
      (box (cons 'lazy (lambda () exp))))))
-(define (eager x)
-  (box (cons 'eager x)))
+(define (eager . xs)
+  (box (cons 'eager xs)))
 (define-syntax delay
   (syntax-rules ()
-    ((delay exp) (lazy (eager exp)))))
+    ((delay exp) (lazy (call-with-values
+                           (lambda () exp)
+                         eager)))))
 (define (force promise)
   (let ((content (unbox promise)))
     (case (car content)
-      ((eager) (cdr content))
+      ((eager) (apply values (cdr content)))
       ((lazy)  (let* ((promise* ((cdr content)))        
                       (content  (unbox promise)))                      ; * 
                  (if (not (eqv? (car content) 'eager))                 ; *