add values/call-with-values

This commit is contained in:
Yuichi Nishiwaki 2013-11-11 08:01:29 +09:00
parent 4fea9169cc
commit 901cf0ed09
1 changed files with 13 additions and 0 deletions

View File

@ -212,3 +212,16 @@
(if (compare obj (caar list)) (if (compare obj (caar list))
(car list) (car list)
(assoc obj (cdr list) compare))))) (assoc obj (cdr list) compare)))))
(define (values . args)
(if (and (pair? args)
(null? (cdr args)))
(car args)
(cons '*values-tag* args)))
(define (call-with-values producer consumer)
(let ((res (producer)))
(if (and (pair? res)
(eq? '*values-tag* (car res)))
(apply consumer (cdr res))
(consumer res))))