DOC PREVIEW
Berkeley COMPSCI 61A - Lecture Notes

This preview shows page 1-2-16-17-18-34-35 out of 35 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 35 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 35 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 35 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 35 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 35 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 35 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 35 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 35 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

CS61A Lecture 24Clicker poll Goalsmce reviewHow many calls to mc-eval?Slide 6Slide 7REVIEW What is a procedure?How many calls to mc-eval? DEMOcalls to mc-eval(fact 1)Slide 12(fact 2)(fact 3)PowerPoint PresentationanalzyeanalyzeSlide 18Slide 19Slide 20Slide 21Slide 22analyze-quotedTwo versions of analyze-quotedWrite analyze-ifanalyze-if solution(analyze '(if #t 3 4))Slide 28Do we save time using the analyzing mce?Compiling JavaCompilersFrames in MCE (below the line)Environments (below the line)Slide 34Environments (Below the line)CS61A Lecture 242011-08-01Colleen Lewis1Clicker poll  Have you started project 4 part 1?A)Yes – we’re done!B)Yes – we’re close to done!C)Yes – we started D)Yes – we started reading the project/codeE)No – we haven’t started2Goals•Increase comfort with the meta-circular evaluator (MCE)•Identify inefficiency•See efficiency improvement using analyze•Connect the ideas in analyze to compiling 3mce review•You could define new functions in mce?–A. True–B. False4How many calls to mc-eval?;;; M-Eval input:(define (fact n) (if (= n 0) 1 (* n (fact (- n 1)))))A)1 B) 2C) 3D) 4 E) 5Does this make any calls to mc-apply?A) Yes B) NO!!!5How many calls to mc-eval?;;; M-Eval input:(define (simple x) x)A)1 B) 2 C) 3 D) 4 E) 5(define (mc-eval exp env) (display (list 'mc-eval 'exp: exp)) (newline) (cond ((self-evaluating? exp) exp)(mc-eval exp: (define (simple x) x))(mc-eval exp: (lambda (x) x))6How many calls to mc-eval?;;; M-Eval input:(simple 5)A)1 B) 2 C) 3 D) 4 E) 5(mc-eval exp: (simple 5))(mc-eval exp: simple)(mc-eval exp: 5)(mc-eval exp: x)7REVIEW What is a procedure?STk> (mc-eval '(lambda (x) (* x x)) '(((a) 3)))(procedure (x) ((* x x)) (((a) 3)))8car cdr((a).(3))Params: xBody: (+ x x)Globala: 3procedurecar cdr(x)car cdr((* x x))car cdrcar cdrHow many calls to mc-eval?DEMO(fact 0)(procedure (n) ((if (= n 0) 1 (* n (fact (- n 1))))) env)9123456 7 89calls to mc-eval(mc-eval exp: (fact 0))(mc-eval exp: fact)(mc-eval exp: 0)(mc-eval exp: (if (= n 0) 1 (* n (fact (- n 1)))))(mc-eval exp: (= n 0))(mc-eval exp: =)(mc-eval exp: 0)(mc-eval exp: n)(mc-eval exp: 1)10(fact 1)(fact 1)(mc-eval exp: (fact 1))(mc-eval exp: fact)(mc-eval exp: 1)(mc-eval exp: (if (= n 0) 1 (* n (fact (- n 1)))))(mc-eval exp: (= n 0))(mc-eval exp: =)(mc-eval exp: 0)(mc-eval exp: n)(mc-eval exp: (* n (fact (- n 1))))(mc-eval exp: *)(mc-eval exp: (fact (- n 1)))(mc-eval exp: fact)(mc-eval exp: (- n 1))(mc-eval exp: -)(mc-eval exp: 1)(mc-eval exp: n)11(mc-eval exp: (if (= n 0) 1 (* n (fact (- n 1)))))(mc-eval exp: (= n 0))(mc-eval exp: =)(mc-eval exp: 0)(mc-eval exp: n)(mc-eval exp: 1)(mc-eval exp: n)(fact 1)(fact 1)(mc-eval exp: (fact 1))(mc-eval exp: fact)(mc-eval exp: 1)(mc-eval exp: (if (= n 0) 1 (* n (fact (- n 1)))))(mc-eval exp: (= n 0))(mc-eval exp: =)(mc-eval exp: 0)(mc-eval exp: n)(mc-eval exp: (* n (fact (- n 1))))(mc-eval exp: *)(mc-eval exp: (fact (- n 1)))(mc-eval exp: fact)(mc-eval exp: (- n 1))(mc-eval exp: -)(mc-eval exp: 1)(mc-eval exp: n)12(mc-eval exp: (if (= n 0) 1 (* n (fact (- n 1)))))(mc-eval exp: (= n 0))(mc-eval exp: =)(mc-eval exp: 0)(mc-eval exp: n)(mc-eval exp: 1)(mc-eval exp: n)(fact 2)13(mc-eval exp: (if (= n 0) 1 (* n (fact (- n 1)))))(mc-eval exp: (= n 0))(mc-eval exp: =)(mc-eval exp: 0)(mc-eval exp: n)(mc-eval exp: (* n (fact (- n 1))))(mc-eval exp: *)(mc-eval exp: (fact (- n 1)))(mc-eval exp: fact)(mc-eval exp: (- n 1))(mc-eval exp: -)(mc-eval exp: 1)(mc-eval exp: n)(mc-eval exp: (if (= n 0) 1 (* n (fact (- n 1)))))(mc-eval exp: (= n 0))(mc-eval exp: =)(mc-eval exp: 0)(mc-eval exp: n)(mc-eval exp: (* n (fact (- n 1))))(mc-eval exp: *)(mc-eval exp: (fact (- n 1)))(mc-eval exp: fact)(mc-eval exp: (- n 1))(mc-eval exp: -)(mc-eval exp: 1)(mc-eval exp: n)(mc-eval exp: (if (= n 0) 1 (* n (fact (- n 1)))))(mc-eval exp: (= n 0))(mc-eval exp: =)(mc-eval exp: 0)(mc-eval exp: n)(mc-eval exp: 1)(mc-eval exp: n)(mc-eval exp: n)(mc-eval exp: (fact 2))(mc-eval exp: fact)(mc-eval exp: 2)(fact 3)14(mc-eval exp: (if (= n 0) 1 (* n (fact (- n 1)))))(mc-eval exp: (= n 0))(mc-eval exp: =)(mc-eval exp: 0)(mc-eval exp: n)(mc-eval exp: (* n (fact (- n 1))))(mc-eval exp: *)(mc-eval exp: (fact (- n 1)))(mc-eval exp: fact)(mc-eval exp: (- n 1))(mc-eval exp: -)(mc-eval exp: 1)(mc-eval exp: n)(mc-eval exp: (if (= n 0) 1 (* n (fact (- n 1)))))(mc-eval exp: (= n 0))(mc-eval exp: =)(mc-eval exp: 0)(mc-eval exp: n)(mc-eval exp: (* n (fact (- n 1))))(mc-eval exp: *)(mc-eval exp: (fact (- n 1)))(mc-eval exp: fact)(mc-eval exp: (- n 1))(mc-eval exp: -)(mc-eval exp: 1)(mc-eval exp: n)(mc-eval exp: (if (= n 0) 1 (* n (fact (- n 1)))))(mc-eval exp: (= n 0))(mc-eval exp: =)(mc-eval exp: 0)(mc-eval exp: n)(mc-eval exp: 1)(mc-eval exp: n)(mc-eval exp: n)(mc-eval exp: (fact 2))(mc-eval exp: fact)(mc-eval exp: 2)(mc-eval exp: (if (= n 0) 1 (* n (fact (- n 1)))))(mc-eval exp: (= n 0))(mc-eval exp: =)(mc-eval exp: 0)(mc-eval exp: n)(mc-eval exp: (* n (fact (- n 1))))(mc-eval exp: *)(mc-eval exp: (fact (- n 1)))(mc-eval exp: fact)(mc-eval exp: (- n 1))(mc-eval exp: -)(mc-eval exp: 1)(mc-eval exp: n)(define (mc-eval exp env) (cond ((self-evaluating? exp)...((variable? exp)...((quoted? exp) ...((assignment? exp) ...((definition? exp) ...((if? exp) ...((lambda? exp) ...((begin? exp) ...((cond? exp) ...((application? exp) ...(else (error “what?"))))15Each call to mc-eval could have a lot of sub-calls!Most didn’t depend upon the environment so I could do in advanceanalzye(define (mc-eval exp env) ( env))What is the domain and range of analyze?A.Domain: function Range: function B.Domain: expression Range: function C.Domain: function Range: expression D.Domain: expression Range: expression E.Other16(analyze exp)analyzeanalyzeList representing expressionSTK Scheme expression(λ(env)17(define (mc-eval exp env) ((analyze exp) env))analyze(define (analyze exp) (cond ((self-evaluating? exp) ((quoted? exp) … ((variable? exp) … ((assignment? exp) … ((definition? exp) … ((if? exp) … ((lambda? exp) … ((begin? exp) … ((cond? exp) … ((application? exp) … (else (error "Unknown" exp))))18(define (mc-eval exp env) ((analyze exp) env))(define (mc-eval exp env) (cond ((self-evaluating? exp) exp)((quoted? exp) (text-of-quotation exp)) ((variable? exp)(lookup-variable-value exp env))…(define (analyze exp) (cond ((self-evaluating? exp) (analyze-self-evaluating exp)) ((quoted? exp) (analyze-quoted exp)) ((variable? exp)


View Full Document

Berkeley COMPSCI 61A - Lecture Notes

Documents in this Course
Lecture 1

Lecture 1

68 pages

Midterm

Midterm

5 pages

Midterm

Midterm

6 pages

Lecture 35

Lecture 35

250 pages

Lecture 14

Lecture 14

125 pages

Lecture 2

Lecture 2

159 pages

Lecture 6

Lecture 6

113 pages

Lecture 3

Lecture 3

162 pages

Homework

Homework

25 pages

Lecture 13

Lecture 13

117 pages

Lecture 29

Lecture 29

104 pages

Lecture 11

Lecture 11

173 pages

Lecture 7

Lecture 7

104 pages

Midterm

Midterm

6 pages

Midterm

Midterm

6 pages

Lecture 8

Lecture 8

108 pages

Lab 4

Lab 4

4 pages

Lecture 7

Lecture 7

52 pages

Lecture 20

Lecture 20

129 pages

Lecture 15

Lecture 15

132 pages

Lecture 9

Lecture 9

95 pages

Lecture 30

Lecture 30

108 pages

Lecture 17

Lecture 17

106 pages

Load more
Download Lecture Notes
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Lecture Notes and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Lecture Notes 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?