I am little bit confused by the result of this example:
(define mk-q
(lambda ()
(let ([l '(x)])
(cons l l))))
(define q (mk-q))
q
=> ((x) x)
(set-car! (cdr q) 'y)
=> ((y) y)
I am wondering why both x
atoms have been replaced by set-car!
procedure (my first guess for what the result would be was ((x) y)
)?
For example:
(define mk-q2
(lambda ()
(let ([l '(x)])
(cons l (cons l l)))))
(define q2 (mk-q2))
(set-car! (cdr q2) 'y)
=> ((x) y x) which fits my understanding of set-car!
Why are both x
s in the first example replaced?