;; DYNAMIC SCOPE EVALUATOR ;; This is the essential change: ;; + when procedures are called, current environment needs to be extended ;; instead, so mc-apply needs to take the CE as an argument ;; This file can be loaded into Scheme as a whole. ;; **NOTE** ;; This file loads the metacircular evaluator of ;; sections 4.1.1-4.1.4, since it uses the expression representation, ;; environment representation, etc. ;; You may need to change the (load ...) expression to work in your ;; version of Scheme. ;; Then you can initialize and start the evaluator by evaluating ;; the expression (mce). ;; **implementation-dependent loading of evaluator file ;; Note: It is loaded first so that this file's version ;; of eval overrides the definition from 4.1.1 (load "mceval.scm") (define (mc-eval exp env) (cond ((self-evaluating? exp) exp) ((variable? exp) (lookup-variable-value exp env)) ((quoted? exp) (text-of-quotation exp)) ((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)) ;; this is now superfluous ((begin? exp) (eval-sequence (begin-actions exp) env)) ((cond? exp) (mc-eval (cond->if exp) env)) ((application? exp) (mc-apply (mc-eval (operator exp) env) (list-of-values (operands exp) env) env)) ;; added (else (error "Unknown expression type -- EVAL" exp)))) (define (mc-apply procedure arguments env) ;; modified (cond ((primitive-procedure? procedure) (apply-primitive-procedure procedure arguments)) ((compound-procedure? procedure) (eval-sequence (procedure-body procedure) (extend-environment (procedure-parameters procedure) arguments ;; (procedure-environment procedure) ;; removed env))) ;; added (else (error "Unknown procedure type -- APPLY" procedure)))) ;; (define input-prompt ";;; M-Eval input:") ;; (define output-prompt ";;; M-Eval value:") (define input-prompt "DynMCE> ") (define output-prompt "") (define (prompt-for-input string) ;; (newline) (newline) (display string) ;; (newline) ) (define (announce-output string) ;; (newline) (display string) ;; (newline) )