r6rs-lib

#
Chapter 17
Mutable pairs

The procedures provided by the `(rnrs mutable-pairs (6))`library allow new values to be assigned to the car and cdr fields of previously allocated pairs.

`(set-car! pair obj)` procedure

Stores obj in the car field of pair. The `set-car!` procedure returns unspecified values.

`(define (f) (list ’not-a-constant-list))
(define (g) ’(constant-list))
(set-car! (f) 3) ⇒ unspecified
(set-car! (g) 3) ⇒ unspecified
; should raise `&assertion` exception

`

If an immutable pair is passed to `set-car!`, an exception with condition type `&assertion` should be raised.

`(set-cdr! pair obj)` procedure

Stores obj in the cdr field of pair. The `set-cdr!` procedure returns unspecified values.

If an immutable pair is passed to `set-cdr!`, an exception with condition type `&assertion` should be raised.

`(let ((x (list ’a ’b ’c ’a))
(y (list ’a ’b ’c ’a ’b ’c ’a)))
(set-cdr! (list-tail x 2) x)
(set-cdr! (list-tail y 5) y)
(list
(equal? x x)
(equal? x y)
(equal? (list x y ’a) (list y x ’b))))
⇒ (`#t` `#t` `#f`)

`