3 ms·
> Last I checked, that's totally valid Racket. And it has the same effect as using set-car!. No. There's an important difference. This is valid Scheme and Rack
by catnaroek 10y ago
> Last I checked, that's totally valid Racket. And it has the same effect as using set-car!.
No. There's an important difference. This is valid Scheme and Racket:
(define x (list "hello" "world"))
(define y x)
(set! x (list "goodbye" "world")) ;; y is still (list "hello" "world")
But this isn't valid Racket:
(define x (list "hello" "world"))
(define y x)
(set-car! x "goodbye") ;; now y is (list "goodbye" "world") too
Racket has a separate (dynamic) type of mutable cons cells, together with `set-mcar!` and `set-mcdr!` operations. In Racket, cons cells are bona fide compound values, but the object identity of an mcons cells is a primitive value.