From: Ramakrishnan Muthukrishnan Date: Sat, 31 Dec 2011 10:49:01 +0000 (+0530) Subject: let* added to the language X-Git-Url: https://git.rkrishnan.org/listings/vdrive/frontends/webapi.txt?a=commitdiff_plain;h=47d95c588d90de000efb7a32c8bf7e9e281ba295;p=sicp.git let* added to the language --- diff --git a/src/sicp/metacircular2.rkt b/src/sicp/metacircular2.rkt index 7196c94..7bc5f02 100644 --- a/src/sicp/metacircular2.rkt +++ b/src/sicp/metacircular2.rkt @@ -172,6 +172,13 @@ [`((,var ,val) ...) bindings]) `((lambda ,var ,body) ,@val))) +;; let* +(define (let*->nested-lets lexpr) + (match lexpr + [`(let* (,first-binding ,rest-bindings ...) ,body) + `(let (,first-binding) ,(let*->nested-lets `(let* ,rest-bindings ,body)))] + [`(let* () ,body) body])) + ;; eval (define (eval exp env) (match exp @@ -186,6 +193,7 @@ [`(begin ,exp ...) (eval-sequence exp env)] [`(cond ,clauses ...) (eval (cond->if clauses) env)] [`(let ,bindings ,body) (eval (let->combination exp) env)] + [`(let* ,bindings ,body) (eval (let*->nested-lets exp) env)] [(list f x ...) (apply (eval f env) (list-of-values x env))] [_ (error "unable to evaluate expression -- EVAL " exp)]))