Difference between revisions of "Environment"

From CS 61A Wiki
Jump to: navigation, search
[unchecked revision][unchecked revision]
(bold; break example into new section)
Line 1: Line 1:
An ''environment'' consists of a sequence of frames. For example, in the following code:
+
An '''environment''' consists of a sequence of [[frame]]s.
 +
 
 +
== Example ==
 +
In the following code:
 
<syntaxhighlight lang="python">
 
<syntaxhighlight lang="python">
 
x = 1
 
x = 1

Revision as of 10:54, 27 May 2014

An environment consists of a sequence of frames.

Example

In the following code:

x = 1
y = 2
def outer():
    x = 3
    y = 4
    def inner():
        x = 5
        y = 6
    return inner
outer()()

the sequence of frames that makes up the environment of inner is innerouterglobal. Here are the bindings in each frame:

frame x y
global 1 2
outer 3 4
inner 5 6