implement let-values

This commit is contained in:
Yuichi Nishiwaki 2013-12-10 08:30:06 -08:00
parent 45fb1be04f
commit acd70f108d
1 changed files with 20 additions and 2 deletions

View File

@ -276,8 +276,25 @@
(apply consumer (cdr res)) (apply consumer (cdr res))
(consumer 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 (export values
call-with-values)) call-with-values
let-values))
(import (picrin macro) (import (picrin macro)
(picrin core-syntax) (picrin core-syntax)
@ -291,7 +308,8 @@
_ ... syntax-error) _ ... syntax-error)
(export values (export values
call-with-values) call-with-values
let-values)
(define (any pred list) (define (any pred list)
(if (null? list) (if (null? list)