Basics of Binding and Free Variables
1Introduction
This lecture defines the syntax of lambda terms and classifies every variable occurrence as bound or free. A name alone does not determine the classification; the occurrence's position and the scope of its binder are essential.
2Syntax and syntax trees
Let be a countably infinite set of variables. The set of untyped lambda terms is defined recursively by the grammar
Here is a variable, is an application, and is an abstraction. When parentheses are omitted, application associates to the left and the body of an abstraction extends as far to the right as possible. Thus and .
3Binders, scopes, and occurrences
In , the prefix is a binder for , and the subterm is its scope. An occurrence of at a leaf of the syntax tree is bound if it lies inside the body of some . If several such binders enclose the occurrence, the nearest one in the syntax tree binds it. An occurrence of that lies in the scope of no is free.
Boundness is a property of an occurrence, not merely of a variable name. For example, in
the leftmost occurrence of is free, whereas the rightmost occurrence is bound by the inner . In
the occurrence in the inner body is bound by the inner binder, while the final occurrence is bound by the outer binder. This phenomenon is called shadowing.
4The set of free variables
is the set of variable names that have at least one free occurrence in . It is defined structurally by
For example,
A term is closed if and open otherwise. A term is closed exactly when every variable occurrence is bound by some binder.
5Check
In , both occurrences of are bound by the outer , the occurrence of is bound by , and only the occurrence of is free. Hence . The next lecture uses this occurrence-level classification to define substitution that avoids capture.