mutable abstract type
example
- vector abstract type might now have operations like
set-x-component!
scale-vector!
- sample code
(define (scale-vector! v k)(set-car! v (* k (car v)))(set-cdr! v (* k (cdr v))))
- sample use
(define v (make-vector 3 4))
(x-coord v) ==> 3
(scale-vector! v 2)
(x-coord v) ==> 6
aside: beneficent side effects
- sometimes we allow operations to mutate the representation
- so that no changes are visible through the abstraction barrier
- examples
balancing a tree
memoizing results of queries