ambeval-final

ambeval-final - Metacircular Evaluator final...

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

View Full Document Right Arrow Icon
;; Metacircular Evaluator: final version (define (input-loop next-try) (display "=61A(Non-deterministic)=> ") (flush) (let ((input (read))) (cond ((equal? input 'exit) (print "Au Revoir!")) ((equal? input 'choose-another) (next-try)) (else (begin (print "Starting new problem:") (mc-eval input the-global-env (lambda (val fail) (print val) (input-loop fail)) (lambda () (print "There are no more choices") (start-loop)))))))) (define (start-loop) (mc-eval '(define (require cond) (if (not cond) (choose) 'okay)) the-global-env (lambda (val fail) 'blah) (lambda () 'blah)) (input-loop (lambda () (print "There is no current problem") (start-loop)))) (define (mc-eval exp env success fail) (cond ((self-evaluating? exp) (success exp fail)) ((variable? exp) (success (lookup-variable-value exp env) fail)) ((or-exp? exp) (eval-or (cdr exp) env success fail)) ((and-exp? exp) (eval-and (cdr exp) env success fail)) ((if-exp? exp) (mc-eval (cadr exp) env (lambda (pred fail2) (if (not (eq? pred 'nay)) (mc-eval (caddr exp) env success fail2) (mc-eval (cadddr exp) env success fail2))) fail)) ((let-exp? exp) (mc-eval (let->lambda exp) env success fail)) ((begin-exp? exp) (eval-sequence (cdr exp) env success fail)) ((quote-exp? exp) (success (cadr exp) fail))
Background image of page 1

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

View Full DocumentRight Arrow Icon
((set-exp? exp) (mc-eval (caddr exp) env (lambda (val fail2) (let ((old-val (lookup-variable-value (cadr exp) env))) (set-variable-value! (cadr exp) val env) (success 'okay (lambda () (set-variable-value! (cadr exp) old-val env) (fail2))))) fail)) ((definition? exp) (if (list? (cadr exp)) (mc-eval (define->lambda exp) env success fail) (mc-eval (caddr exp) env (lambda (val fail2) (define-variable! (cadr exp) val env) (success 'okay fail2))
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 11/30/2010 for the course EECS 21281 taught by Professor Harvey during the Spring '10 term at Berkeley.

Page1 / 6

ambeval-final - Metacircular Evaluator final...

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

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