From 901cf0ed09c09a42ababdeb88960e7c8e252bcaf Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Mon, 11 Nov 2013 08:01:29 +0900 Subject: [PATCH] add values/call-with-values --- piclib/built-in.scm | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/piclib/built-in.scm b/piclib/built-in.scm index 73edb31a..70a36595 100644 --- a/piclib/built-in.scm +++ b/piclib/built-in.scm @@ -212,3 +212,16 @@ (if (compare obj (caar list)) (car list) (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))))