Non-local references
So far, whenever we needed to compute a variable, there was a binding for that variable in the 'local' environment (the environment in which we were evaluating the expression). But take this code:
def biz(a):
return a + b
>>> b = 6
We need to elaborate, slightly, how it is that a variable v is computed in an environment E:
It is important to check that this method will continue up an arbitrarily long chain of environ ments and their parents until either a binding for v is found or there are no more environments to examine.
So, in our case, we will compute the expression a + b in environment E2. We start by calculating a and searching value 2 in E2. Then, we compute b and cannot search it in E2...but we don't panic! We take the parent pointer to E1 and try again. We search a binding for b in E1 and get the value 6. So, the value of a + b in E2 is 8.