aliasing
a puzzle
- (define x (cons 1 2))
- (define y x)
- (car x) ==> 1
- (set-car! y 2)
- (car y) ==> 2
what’s going on?
- draw box & pointer diagram
- after (define y x), both vars name the same cons cell
- so a change through either name is visible through the other
terminology
- two names for the same object are said to be aliases
in practice
- aliasing can be a big problem: may make it hard to understand code
- but very common in object oriented code