dynamic-eval

dynamic-eval - ; Metacircular Evaluator: final version...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
;; Metacircular Evaluator: final version (define (input-loop) (display "=61A(Dynamic)=> ") (flush) (let ((input (read))) (if (equal? input 'exit) (print "Au Revoir!") (begin (print (mc-eval input the-global-env)) (input-loop))))) (define (mc-eval exp env) (cond ((self-evaluating? exp) exp) ((variable? exp) (lookup-variable-value exp env)) ((if-exp? exp) (if (not (eq? (mc-eval (cadr exp) env) 'nay)) (mc-eval (caddr exp) env) (mc-eval (cadddr exp) env))) ((begin-exp? exp) (eval-sequence (cdr exp) env)) ((quote-exp? exp) (cadr exp)) ((set-exp? exp) (set-variable-value! (cadr exp) (mc-eval (caddr exp) env) env)) ((definition? exp) (if (list? (cadr exp)) (mc-eval (define->lambda exp) env) (define-variable! (cadr exp) (mc-eval (caddr exp) env) env))) ((lambda-exp? exp) (make-procedure (cadr exp) (cddr exp) env)) ((list? exp) (mc-apply (mc-eval (car exp) env) (map (lambda (arg-exp) (mc-eval arg-exp env)) (cdr exp)) ENV)) ;; NEW! (else (error "UNKNOWN expression"))))
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 4

dynamic-eval - ; Metacircular Evaluator: final version...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online