Problem 1 (100pts): Frame

Implement the define and lookup methods of the Frame class, in scheme_classes.py. Each Frame object has the following instance attributes:

  • bindings is a dictionary representing the bindings in the frame. It maps Scheme symbols (represented as Python strings) to Scheme values.
  • parent is the parent Frame instance. The parent of the Global Frame is None.
  1. define takes a symbol (represented by a Python string) and a value. It binds the symbol to the value in the Frame instance.
  2. lookup takes a symbol and returns the value bound to that symbol in the first frame of the environment in which the symbol is bound. The environment for a Frame instance consists of that frame, its parent frame, and all its ancestor frames, including the Global Frame.
  • If the symbol is bound in the current frame, return its value.
  • If the symbol is not bound in the current frame, and the frame has a parent frame, continue lookup in the parent frame.
  • If the symbol is not found in the current frame and there is no parent frame, raise a SchemeError.

Before writing any code, unlock the tests to verify your understanding of the question:

$ python ok -q 01 -u

Once you are done unlocking, begin implementing your solution. You can check your correctness with:

$ python ok -q 01

After you complete this problem, you can start your Scheme interpreter (with python scheme.py). You should be able to look up built-in procedure names:

scm> +
#[+]
scm> odd?
#[odd?]

However, your Scheme interpreter will still not be able to call these procedures. We will fix that in next problems.

Remember, at this point you can only exit the interpreter by pressing Ctrl-d.