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)