This preview shows page 1 out of 4 pages.

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

Unformatted text preview:

6.001, Spring 2006—Recitation 15 — 4/7/2006 1MASSACHVSETTS INSTITVTE OF TECHNOLOGYDepartment of Electrical Engineering and Computer Science6.001—Structure and Interpretation of Computer ProgramsSpring 2006Recitation 15 — 4/7/2006Environment ModelEval• name - Look up name in the current environment, if found return value, otherwise lookup inenclosing (parent) environment.• (lambda (params) body) - Create double bubble with code ptr to params and body and envptr to current environment.• (define name value) - Evaluate value and then create/replace binding for name with theresult.• (set! name value) - Evaluate value and then replace the first binding for name in the chainof environments, starting with the current env.• (proc args ... ) - Evaluate proc and args in the current environment, then a¯pply.• Otherwise – Follow the correct rule (numbers, if, cond, begin, quote, etc.)Apply• Step 1 - Drop a new frame• Step 2 - Link frame pointer of new frame to environment pointed to by env pointer of doublebubble being applied.• Step 3 - Bind params of double bubble in the new frame.• Step 4 - E¯val the body in the new frame.6.001, Spring 2006—Recitation 15 — 4/7/2006 2ProblemsProblem 1(define (square x)(* x x))(define (sum-of-squares x y)(+ (square x) (square y)))(sum-of-squares 2 3)Problem 2(define x 3)((lambda (x y) (+ (x 1) y))(lambda (z) (+ x 2))3)6.001, Spring 2006—Recitation 15 — 4/7/2006 3Problem 3(define (fact n)(if (= n 0)1(* n (fact (- n 1)))))(fact 2)Problem 4(define x 1)(let ((x 5)(y (+ x 5)))(+ x y))6.001, Spring 2006—Recitation 15 — 4/7/2006 4Problem 5(define (previous f)(let ((old #f))(lambda (x)(let ((return old))(set! old (f x))return))))(define echo (previous (lambda (y) y)))(echo


View Full Document

MIT 6 001 - Recitation 15

Documents in this Course
Quiz 1

Quiz 1

6 pages

Databases

Databases

12 pages

rec20

rec20

2 pages

Quiz II

Quiz II

15 pages

Streams

Streams

5 pages

Load more
Download Recitation 15
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 Recitation 15 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 Recitation 15 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?