From 47d95c588d90de000efb7a32c8bf7e9e281ba295 Mon Sep 17 00:00:00 2001 From: Ramakrishnan Muthukrishnan <vu3rdd@gmail.com> Date: Sat, 31 Dec 2011 16:19:01 +0530 Subject: [PATCH] let* added to the language --- src/sicp/metacircular2.rkt | 8 ++++++++ 1 file changed, 8 insertions(+) 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)])) -- 2.45.2