From acd70f108d546b0e32e46c8a0176b110d18bf7d1 Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Tue, 10 Dec 2013 08:30:06 -0800 Subject: [PATCH] implement let-values --- piclib/built-in.scm | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/piclib/built-in.scm b/piclib/built-in.scm index 3854416d..bc3dab5b 100644 --- a/piclib/built-in.scm +++ b/piclib/built-in.scm @@ -276,8 +276,25 @@ (apply consumer (cdr res)) (consumer res)))) + (define (cadr p) (car (cdr p))) + (define (cddr p) (cdr (cdr p))) + (define (cdar p) (cdr (car p))) + (define (caar p) (car (car p))) + + (define-syntax let-values + (er-macro-transformer + (lambda (form r c) + (let ((formals (cadr form))) + (if (null? formals) + `(,(r 'let) () ,@(cddr form)) + `(,(r 'call-with-values) (,(r 'lambda) () ,@(cdar formals)) + (,(r 'lambda) (,@(caar formals)) + (,(r 'let-values) (,@(cdr formals)) + ,@(cddr form))))))))) + (export values - call-with-values)) + call-with-values + let-values)) (import (picrin macro) (picrin core-syntax) @@ -291,7 +308,8 @@ _ ... syntax-error) (export values - call-with-values) + call-with-values + let-values) (define (any pred list) (if (null? list)