let and the uses of lexical closures
An environment defines a set of bindings between symbols and their 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:
(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.