This is the mail archive of the guile@cygnus.com mailing list for the guile project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: multiple return values


> > but once Guile does have multiple return values,

> And when will this be? :-)

The following is said to be an R5RS compliant implementation of 
multiple values in R4RS Scheme.  Am I missing something, or couldn't
somebody just toss this into an initialization file and be a happy
hacker?

From: William D Clinger <will@ccs.neu.edu>
Newsgroups: comp.lang.scheme
; Multiple values.
;
; (values E ...)
; (call-with-values producer consumer)

(define values)
(define call-with-values)

(let* ((apply apply)
       (*multiple-values* (list '*multiple-values*))
       (*values0* (list *multiple-values*)))
  (set! values
        (lambda vals
          (cond ((null? vals) *values0*)
                ((null? (cdr vals)) (car vals))
                (else (cons *multiple-values* vals)))))
  (set! call-with-values
        (lambda (producer consumer)
          (let ((vals (producer)))
            (if (and (pair? vals)
                     (eq? (car vals) *multiple-values*))
                (apply consumer (cdr vals))
                (consumer vals)))))
  'call-with-values)