95.307 - Programming Paradigms 1999

 6  Environments and Bindings


What's in This Set of Notes ?


6.1 Definitions


Issues:


6.2 Contour Model

Model


6.3 Visualization with Contour Model





Another Example with Recursion

 
line 1:    (define (factorial n)
line 2:            (if (< n 2)
line 3:                    1
line 4:                    (* n (factorial (- n 1)))))
line 5:    (define result (factorial 3))




6.4 Scoping

Scoping of Variables

Lexical Scoping

Dynamic Scoping


Example

Line1:        (define (main)
Line 2:             (let (( a 0) (b 0))

Line3:             (define (f)
Line4:                (let ((a 0))
Line5:                    (set! a b)
Line6:                     (writeln "in f: A and B are - " a b)
Line7:                    (g)))

Line8:             (define (g)
Line9:                (let ((b 0))
Line10:                    (set! b (+ a 2))
Line11:                    (writeln "in g: A and B are - " a b)
Line12:                     (f)))

Line13:            (set! a 5)
Line14:            (set! b 6)
Line15:            (f)))

Line16:     (define a 10)
Line17:     (define b 20)
Line 18:    (main)
 

Execution Contours Using Lexical Scoping


 

Execution Contours Using Dynamic Scoping


 


5.5 Notes