mutable data structures
how set! differs from set-car! and set-cdr!
- set! changes a FRAME
- set-car! and set-cdr! change a CONS CELL
mutable structures
- all data structures are made of cons cells
- so all we need to modify data structures are
set-car! : a way to change what’s in the first compartment
set-cdr! : a way to change what’s in the second compartment
- (in fact, set-car! alone is enough. can you implement a mutable pair with set-car! alone?)
contract
- after (set-car! c x), (car c) evaluates to x
- after (set-cdr! c y), (cdr c) evaluates to y
- … assuming that c names a cons cell