Frame

From CS 61A Wiki
Jump to: navigation, search

A frame contains bindings, which are pairs of variables and values. A function call creates a new frame whose parent is the current frame.

The first frame is the global frame.

Example

In the following code:

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

there are three frames: global, outer, and inner. Here are the bindings in each frame:

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