An Introduction to Scheme and its Implementation - lambda and Lexical Scope Go to the first , previous , next , last section, table of contents . Except for local variables of the procedure itself, including its arguments, names in the body of the procedure refer to whatever they refer to at the point where the procedure is created by lambda .
Local variables created by the procedure have the usual scope rule within the body.
Whenever the procedure references a free variable, it will will refer to the bindings of those variables in the environment where the procedure was created. When quux is called, it will bind its local variable foo and then call baz . When baz is called from quux , however, it will still see the top level binding of foo , whose value is 1 . There is a very good reason for this, and it's the rule used by most programming languages. It is important that the meaning of a procedure be fixed where it is defined, rather than having the meaning depend on where it is called from.