From http://www.seas.gwu.edu/~rhyspj/spring09cs145/lab8/lab82.html
The lambda operator does not bind every occurrence of its variable because "shadowing" can occur. A variable is bound by its nearest enclosing lambda.
In $(\lambda (x) ((y\,\, x) (\lambda (x) (x\,\, y))))$, the $x$ in $(y\,\, x)$ is bound by the outermost lambda, whereas the $x$ in $(x\,\, y)$ is bound by the inner lambda. In this example, both occurrences of $y$ are free.
How shall I understand the lambda expression $(\lambda (x) ((y\,\, x) (\lambda (x) (x\,\, y))))$?
I wonder if the $x$ in $(y\,\, x)$ and the $x$ in $(x\,\, y)$ are the same or different variables?
If I rename one of them, will the renamed version be the same as $(\lambda (x) ((y\,\, x) (\lambda (x) (x\,\, y))))$? E.g.
- Is $(\lambda (x) ((y\,\, x) (\lambda (z) (z\,\, y))))$ the same as $(\lambda (x) ((y\,\, x) (\lambda (x) (x\,\, y))))$?
- Is $(\lambda (z) ((y\,\, z) (\lambda (x) (x\,\, y))))$ the same as $(\lambda (x) ((y\,\, x) (\lambda (x) (x\,\, y))))$?
Do the two occurrences of $y$ mean the same variable?