Scope
The meaning of a procedure (function) should be independent of the parameter names used by its author.
Variable binding
The parameter names must be local to the body of the procedure:
- Formal parameters of a procedure are therefore bound variables, and the procedure definition binds its formal parameters.
- The procedure is unchanged if a bound variable is consistently renamed throughout the definition.
- A variable that is not bound is a free variable.
- The set of expressions for which a binding defines a name is called the scope of that name.
- Names of functions also have their particular scope.
- = is a free variable/symbol throughout the python language, for example.
- Possible to override things or capture them, but one must tread carefully when doing this.
- Whereas, the variables bound by a procedure definition as its formal parameters have a scope limited to the body of the procedure.
Lexical scoping
We don't want to see all the inner workings of a numerical procedure at run-time, so there's no need to expose util functions (eg. check for good approx) to the outside.
- We can make some procedures subsidiaries of the main procedure.
- Nesting of definitions - block structure
- Lexical scoping: All subprocedures may treat bound variables of the main procedure as free variables, and assume their values to be sensible.
- Similar rationale for creating classes and objects.
Links