Difference between revisions of "Environment"

From CS 61A Wiki
Jump to: navigation, search
[unchecked revision][checked revision]
(see also)
(Example: bindings example moved to frame)
Line 15: Line 15:
 
outer()()
 
outer()()
 
</syntaxhighlight>
 
</syntaxhighlight>
the sequence of frames that makes up the environment of <code>inner</code> is <code>inner</code> → <code>outer</code> → <code>global</code>. Here are the bindings in each frame:
+
the sequence of frames that makes up the environment of <code>inner</code> is <code>inner</code> → <code>outer</code> → <code>global</code>.
{| class="wikitable" style="text-align:center"
+
! frame
+
! x
+
! y
+
|-
+
! <code>global</code>
+
| 1 || 2
+
|-
+
! <code>outer</code>
+
| 3 || 4
+
|-
+
! <code>inner</code>
+
| 5 || 6
+
|}
+
  
 
== See also ==
 
== See also ==
 
* [[Environment diagram]]
 
* [[Environment diagram]]

Revision as of 11:28, 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.

See also