lecture14 - E NVIRONMENTS AND L OCAL S TATE G EORGE WANG

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

View Full Document Right Arrow Icon
E NVIRONMENTS AND L OCAL S TATE 14 G EORGE W ANG gswang.cs61a@gmail.com Department of Electrical Engineering and Computer Sciences University of California, Berkeley July 15, 2010 1 Review 1.1 The Golden Rules 1. Calling a lambda procedure makes frames , pointing to the right bubble of the lambda . 2. Making a lambda procedure makes 2 bubbles , the left holding information, and the right pointing to the current frame. 2 The Environment Model 2.1 Exercise: Draw the Environment! (define (f x) (define (g y) (+ x y)) (g 3)) > (f 5) 2.2 Exercise: make-adder Draw the Environment! (define (make-adder n) (lambda (x) (+ x n))) (define 3+ (make-adder 3)) 1
Background image of page 1

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

View Full DocumentRight Arrow Icon
(define n 7) > (3+ n) Scheme’s rule, in which the procedure’s defining environment (the right bubble) is extended, is called LEXICAL SCOPE. The other rule, in which the current environment is extended, is called DYNAMIC SCOPE. A language with dynamic scope is possible, but it would have different features from Scheme.
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.

Page1 / 4

lecture14 - E NVIRONMENTS AND L OCAL S TATE G EORGE WANG

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