; a) Louis's evaluator will incorrectly treat other expressions such as ; (define x 3) as procedure applications because they are represented as lists ; starting too (ie: pair? returns true). ;b ) (load "evaluator.txt") (define (application? exp) (tagged-list? exp 'call)) (define (operator exp) (cadr exp)) (define (operands exp) (cddr exp)) (define (eval exp env) (cond ((self-evaluating? exp) exp) ((variable? exp) (lookup-variable-value exp env)) ((quoted? exp) (text-of-quotation exp)) ; Move application earlier in the list of cases ((application? exp) (apply (eval (operator exp) env) (list-of-values (operands exp) env))) ((assignment? exp) (eval-assignment exp env)) ((definition? exp) (eval-definition exp env)) ((if? exp) (eval-if exp env)) ((lambda? exp) (make-procedure (lambda-parameters exp) (lambda-body exp) env)) ((begin? exp) (eval-sequence (begin-actions exp) env)) ((cond? exp) (eval (cond->if exp) env)) (else (error "Unknown expression type -- EVAL" exp)))) ; 1 ]=> (define the-global-environment (setup-environment)) ; ; ;Value: the-global-environment ; ; 1 ]=> (driver-loop) ; ; ; ;;; M-Eval input: ; (call + 1 2) ; ; ;;; M-Eval value: ; 3 ; ; ;;; M-Eval input: ; (define (append x y) ; (if (call null? x) ; y ; (call cons (call car x) ; (call append (call cdr x) y)))) ; ; ;;; M-Eval value: ; ok ; ; ;;; M-Eval input: ; (call append '(a b c) '(d e f)) ; ; ;;; M-Eval value: ; (a b c d e f)