Instead, Racket introduces a separate data type called a mutable pair whose constructor is mcons (as opposed to cons).
The selectors and mutators for mutable pairs are similarly named:
Operation | Pair | Mutable Pair |
---|---|---|
constructor | cons | mcons |
selectors | car | mcar |
cdr | mcdr | |
mutators | set-car! | set-mcar! |
set-cdr! | set-mcdr! |
An implementation of linked nodes in Racket:
(define make-node mcons)
(define node-element mcar)
(define node-rest mcdr)
(define node-set-element! set-mcar!)
(define node-set-rest! set-mcdr!)