I got confused as a result of using set-car! to two lists that have the same structure, but were built differently.
So, here is a sample code for two lists m and n :
(define m (cons (cons 'a '()) (cons (cons 'a '()) '()))) (display m)(newline) ; => ((a) (a)) (set-car! (cadr m) 'b) (display m)(newline) ; => ((a) (b)) (newline) (define n (list '(x) '(x))) (display n)(newline) ; => ((x) (x)) (set-car! (cadr n) 'y) (display n)(newline) ; => ((y) (y))
According to do display , both lists have the same structure, but why applying the same procedure to them leads to different behavior? Is this related to how they were built?
source share