[ ^ CSE 341 | section index | next -->]

CSE 341 -- 6 Apr. 2000


let and the uses of lexical closures

An environment defines a set of bindings between symbols and their values:

[global environment diagram, mappings from symbols to values] (define a 15) (define b 'foo) (define c (lambda (n p) (= p (* n p)))) (define d '(1 2))

Using lets and/or lambdas, we can define new environment and "capture" it:
[local environment diagram, mappings from symbols to values] (define (myfunc y) (let ((c "foo") (d c)) (display (cons c d)) y)) (myfunc b)

What does it mean to "capture" an environment? Essentially, as long as you have a way of reaching the environment's scope (e.g., a binding that refers to the function containing the let or lambda), the environment will remain "alive". A closure is the name we give to the combination of a procedure pointer and the environment "inside" it.


Last modified: Wed Apr 5 21:52:56 PDT 2000