# ps09 - CS51 Assignment 9 Mutability and OOP Due Tuesday...

This preview shows pages 1–3. Sign up to view the full content.

CS51 Assignment 9: Mutability and OOP Due: Tuesday, April 28th, 2009, 11:59PM Total Points: 48 (including 5 style points) (Note: There will be an optional contest to use CS51 techniques or algorithms to pre- dict the outcomes of Red Sox games. The details will be ﬁnalized this weekend. Check http://cs51.seas.harvard.edu/redsox.php for updates.) 1 Mutable Data (18 points total) 1.1 Lists Exercise 1. 12 points We’ve deﬁned the mutable lists foo and bar as follows: ( define foo ( mcons a ( mcons b ( mcons c empty ) ) ) ) ( define bar ( mcdr foo ) ) Fill in the values of foo and bar after applying the following functions. Assume that before each function is run, the variables are reset to the above values. NOTE: while you can obviously test your answers in DrScheme, you should ﬁrst try to ﬁgure them out yourself–you won’t have DrScheme available on the ﬁnal. (a) [2 points] > ( define ( f1 lst ) ( set-mcar ! ( mcdr lst ) x ) ) > ( f1 foo ) (b) [2 points] > ( f1 bar ) (c) [2 points] > ( define ( f2 ) ( set-mcar ! ( mcdr foo ) x ) ) > ( f2 ) 1

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
1 MUTABLE DATA CS51 Assignment 9: Mutability and OOP (d) [2 points] > ( define ( f3 lst ) ( let ( [ copy lst ] ) ( set-mcar ! ( mcdr copy ) x ) ) ) > ( f3 bar ) (e)
This is the end of the preview. Sign up to access the rest of the document.

## This note was uploaded on 07/26/2009 for the course COMPUTERSC CS51 taught by Professor Gregmorrisett during the Spring '09 term at Harvard.

### Page1 / 4

ps09 - CS51 Assignment 9 Mutability and OOP Due Tuesday...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online