Written: Scope

Question 1: Free Identifiers in Substitution

In the environment-based interpreter, an identifier is free (and reported as such by lookup) when it isn't in the current environment. What determines whether an identifier is free under substitution?

Question 2: Closing Over Environments

Our interpreter constructs a closure by closing over the whole of the current environment at the point where the closure is defined. Could it close over a smaller environment? Either explain why not, or provide examples to illustrate why.

Question 3: Loops and Mutation

We have seen in class that when creating closures in a loop, a typical for-loop leads to surprising output because of the shared variable. Why does this problem not occur when using map? Explain in detail with a brief but illustrative example. (You may use one shown in the course; you still have to explain why it behaves differently, ideally by tracing through the environments.)

Submit at this link: