home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / s / s48.zip / MISC / VALUES.SCM < prev    next >
Text File  |  1992-07-06  |  697b  |  26 lines

  1. ; Copyright (c) 1992 by Richard Kelsey and Jonathan Rees.  See file COPYING.
  2.  
  3.  
  4. ; Multiple return values (will be in Revised^5 Report)
  5.  
  6. (define multiple-value-token (vector 'multiple-value-token))
  7.  
  8. (define (values . things)
  9.   (if (and (pair? things)
  10.        (null? (cdr things)))
  11.       (car things)
  12.       (cons multiple-value-token things)))
  13.  
  14. (define (call-with-values producer consumer)
  15.   (let ((things (producer)))
  16.     (if (and (pair? things)
  17.          (eq? (car things) multiple-value-token))
  18.     (apply consumer (cdr things))
  19.     (consumer things))))
  20.  
  21. (define-syntax receive
  22.   (syntax-rules ()
  23.     ((receive vars producer . body)
  24.      (call-with-values (lambda () producer)
  25.                (lambda vars . body)))))
  26.