You are documenting nested functions in a programming language. Match each term to its description, distinguishing name lookup, competing declarations, retained environments, and variable occurrences not bound within a function expression.
A function together with access to the surrounding bindings needed by its body
An inner declaration takes precedence over an outer declaration with the same name
The rule that name resolution follows the nesting of declarations in source code
A use of a variable that is not bound within the function expression under consideration
Closure
Shadowing
Lexical scope
Free variable occurrence
Unlock full course notes by signing up
Lookup after a module update
A drawing application uses integer scale factors. Execute the following Python statements in order and complete the table with the exact unitless integer printed beside each label.
Two counters and a misleading caller
A monitoring script maintains separate event counters for two sensors using the Python code below. Execute the final three assignments in order. Find first, second, and third, giving each as a unitless integer to zero decimal places.
One program under two scoping rules
The program below is written in Python syntax. Assume every assignment or parameter inside a function creates a new local binding for that function, and that the module binding x = 1 never changes.
Each call is made separately from the module level. Fill in the integer value returned by each call when the free name x in get is resolved by lexical scope, and again when a hypothetical interpreter resolves it by dynamic scope, using the most recent active binding of x on the call stack.