next up previous
Next: About this document

MASSACHVSETTS INSTITVTE OF TECHNOLOGY
Department of Electrical Engineering and Computer Science
6.001---Structure and Interpretation of Computer Programs
Spring Semester, 1999

Recitation -- Friday, April 2

1. Object Oriented Programming

Below is the object oriented system from the April 1st Lecture Notes (just included for reference):

2. Object Oriented Stacks

Using this object oriented style, write the function create-stack that will create a stack object. Recall that stacks are data structures that include the operations push, pop, peek, and clear. Objects get pushed on and popped off the stack in a last-in-first-out manner. Complete the function create-stack.

3. Object Oriented Variables

Next, let's write an abstraction for variables in the object oriented style. We do this so that in addition to the get (lookup) and set! operations that we have in scheme, we also want to implement an undo! method that un-does the last set!ing of the variable. We want to store an arbitrary number of undos. How can we use stacks to help us with this undo!? Complete the code for create-var.

4. Object Oriented Pairs

Well, we wrote it for one variable, now let's write it for pairs. Consider the function create-pair that generates a pair of variables (the car and the cdr) that you can get or set. When the message undo! is sent, the last setting gets undone (be it a set-car! or set-cdr!. Consider the following example and complete the code for create-pair.

5. Object Oriented Variables with Redo!

Now we have the ability to undo! the results to set, let's add a redo! feature, such that successive calls to undo! and be taken back using a call to redo!. Complete the code for create-var.





next up previous
Next: About this document



Michael E. Leventon
Fri Apr 2 13:23:23 EST 1999