Problem 8 (200pts): child Frame!
Implement the make_child_frame
method of the Frame
class (scheme_classes.py
), which will be used to create new frames when calling user-defined procedures. This method takes in two arguments: formals
, which is a Scheme list of symbols, and vals
, which is a Scheme list of values. It should return a new child frame, binding the formal parameters to the values.
To do this:
- If the number of argument values does not match with the number of formal parameters, raise a SchemeError.
- Create a new Frame instance, the parent of which is self.
- Bind each formal parameter to its corresponding argument value in the newly created frame. The first symbol in formals should be bound to the first value in vals, and so on.
- Return the new frame.
Hint: The
define
method of aFrame
instance creates a binding in that frame.
Use Ok to unlock and test your code:
python ok -q 08 -u
python ok -q 08