From: Ramakrishnan Muthukrishnan Date: Sun, 27 May 2012 16:27:43 +0000 (+0530) Subject: cleaner way for function application inside `eval'. X-Git-Url: https://git.rkrishnan.org/about.html?a=commitdiff_plain;h=26c9af18426fa429a470d267350f08b9213a2c6d;p=sicp.git cleaner way for function application inside `eval'. --- diff --git a/src/sicp/metacircular2.rkt b/src/sicp/metacircular2.rkt index ef387d4..0a4a575 100644 --- a/src/sicp/metacircular2.rkt +++ b/src/sicp/metacircular2.rkt @@ -15,12 +15,12 @@ (define (variable? expr) (symbol? expr)) - ;; sequence (define (eval-sequence exps env) - (cond ((last-exp? exps) (eval (first-exp exps) env)) - (else (eval (first-exp exps) env) - (eval-sequence (rest-exps exps) env)))) + (cond + [(last-exp? exps) (eval (first-exp exps) env)] + [else (eval (first-exp exps) env) + (eval-sequence (rest-exps exps) env)])) ;; begin (define (last-exp? seq) (null? (cdr seq))) @@ -145,11 +145,11 @@ (match procedure [`(primitive ,f ...) (apply-primitive-procedure procedure arguments)] [`(procedure ,f ...) (eval-sequence - (procedure-body procedure) - (extend-environment - (procedure-parameters procedure) - arguments - (procedure-environment procedure)))] + (procedure-body procedure) + (extend-environment + (procedure-parameters procedure) + arguments + (procedure-environment procedure)))] [_ (error "Unknown procedure type -- APPLY" procedure)])) ;; truth @@ -235,7 +235,7 @@ [`(let ,(? symbol? name) ,bindings ,body ..1) (eval (named-let->combination exp) env)] [`(let* ,bindings ,body ..1) (eval (let*->nested-lets exp) env)] [`(letrec ,bindings ,body ..1) (eval (letrec->combination exp) env)] - [(list f x ...) (apply (eval f env) (list-of-values x env))] + [`(,f ,x ...) (apply (eval f env) (list-of-values x env))] [_ (error "unable to evaluate expression -- EVAL " exp)]))