CS 251 Fall 2019 Principles of Programming Languages
Ben Wood
λ
CS 251 Spring 2020
Principles of Programming Languages
Ben Wood
λ
https://cs.wellesley.edu/~cs251/s20/
Lexical Scope and Function Closures
+closures.rkt
Lexical Scope and Function Closures 1
Topics
- Lexical vs dynamic scope
- Closures implement lexical scope.
- Design considerations: why lexical scope?
- Relevant design dimensions
Lexical Scope and Function Closures 2
A question of scope (warmup)
Lexical Scope and Function Closures 3
What is the argument value passed to this function application?
(define x 1) (define f (lambda (y) (+ x y))) (define z (let ([x 2] [y 3]) (f (+ x y))))
A question of scope
Lexical Scope and Function Closures 4
What is the value of x when this function body is evaluated for this function application?
(define x 1) (define f (lambda (y) (+ x y))) (define z (let ([x 2] [y 3]) (f (+ x y))))