From 62069af4f92cff708ab1ea6ecfb279bcb8f79a00 Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Thu, 14 Nov 2013 17:31:59 +0900 Subject: [PATCH] add named-let --- piclib/built-in.scm | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/piclib/built-in.scm b/piclib/built-in.scm index 9eea4614..c916e972 100644 --- a/piclib/built-in.scm +++ b/piclib/built-in.scm @@ -137,10 +137,24 @@ (cons (f (car list)) (map f (cdr list))))) -;;; bootstrap (define-macro (let bindings . body) - (cons (cons 'lambda (cons (map car bindings) body)) - (map cadr bindings))) + (if (symbol? bindings) + (begin + (define name bindings) + (set! bindings (car body)) + (set! body (cdr body)) + ;; expanded form should be like below: + ;; `(let () + ;; (define ,loop + ;; (lambda (,@vars) + ;; ,@body)) + ;; (,loop ,@vals)) + (list 'let '() + (list 'define name + (cons 'lambda (cons (map car bindings) body))) + (cons name (map cadr bindings)))) + (cons (cons 'lambda (cons (map car bindings) body)) + (map cadr bindings)))) (define-macro (cond . clauses) (if (null? clauses)