lazy-final - ; Lazy Evaluator (define (input-loop) (display...

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

View Full Document Right Arrow Icon
;; Lazy Evaluator (define (input-loop) (display "=61A(Lazy)=> ") (flush) (let ((input (read))) (if (equal? input 'exit) (print "Au Revoir!") (begin (print (ACTUAL-VALUE (mc-eval input the-global-env))) ;; NEW!! (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? (ACTUAL-VALUE (mc-eval (cadr exp) env)) 'nay)) ;; NEW!! (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 (ACTUAL-VALUE (mc-eval (car exp) env)) ;; NEW!! (map (lambda (arg-exp) (make-thunk arg-exp env)) (cdr exp)))) (else (error "UNKNOWN expression")))) (define (mc-apply fn args) (cond ((lambda-proc? fn) (eval-sequence (body fn) (extend-environment (params fn) args
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 / 5

lazy-final - ; Lazy Evaluator (define (input-loop) (display...

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