This preview shows pages 1–2. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.View Full Document
Unformatted text preview: ;;;;AMB EVALUATOR FROM SECTION 4.3 OF ;;;; STRUCTURE AND INTERPRETATION OF COMPUTER PROGRAMS ;;;;Matches code in ch4.scm. ;;;; To run the sample programs and exercises, code below also includes ;;;; -- enlarged primitive-procedures list ;;;; -- support for Let (as noted in footnote 56, p.428) ;;;;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 the section 4.2 definition ;; of eval overrides the definition from 4.1.1 (load "~cs61a/lib/mceval.scm") ;;;Code from SECTION 4.3.3, modified as needed to run it (define (amb? exp) (tagged-list? exp 'amb)) (define (amb-choices exp) (cdr exp)) ;; analyze from 4.1.6, with clause from 4.3.3 added ;; and also support for Let (define (analyze exp) (cond ((self-evaluating? exp) (analyze-self-evaluating exp)) ((quoted? exp) (analyze-quoted exp)) ((variable? exp) (analyze-variable exp)) ((assignment? exp) (analyze-assignment exp)) ((definition? exp) (analyze-definition exp)) ((if? exp) (analyze-if exp)) ((lambda? exp) (analyze-lambda exp)) ((begin? exp) (analyze-sequence (begin-actions exp))) ((cond? exp) (analyze (cond->if exp))) ((let? exp) (analyze (let->combination exp))) ;** ((amb? exp) (analyze-amb exp)) ;** ((application? exp) (analyze-application exp)) (else (error "Unknown expression type -- ANALYZE" exp)))) (define (ambeval exp env succeed fail) ((analyze exp) env succeed fail)) ;;;Simple expressions (define (analyze-self-evaluating exp) (lambda (env succeed fail) (succeed exp fail))) (define (analyze-quoted exp)...
View Full 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.
- Spring '10