1 665c255d 2023-08-04 jrmu (define (cons x y)
2 665c255d 2023-08-04 jrmu (define (set-x! v) (set! x v))
3 665c255d 2023-08-04 jrmu (define (set-y! v) (set! y v))
4 665c255d 2023-08-04 jrmu (define (dispatch m)
5 665c255d 2023-08-04 jrmu (cond ((eq? m 'car) x)
6 665c255d 2023-08-04 jrmu ((eq? m 'cdr) y)
7 665c255d 2023-08-04 jrmu ((eq? m 'set-car!) set-x!)
8 665c255d 2023-08-04 jrmu ((eq? m 'set-cdr!) set-y!)
9 665c255d 2023-08-04 jrmu (else (error "Undefined operation -- CONS" m))))
11 665c255d 2023-08-04 jrmu (define (car z) (z 'car))
12 665c255d 2023-08-04 jrmu (define (cdr z) (z 'cdr))
13 665c255d 2023-08-04 jrmu (define (set-car! z new-value)
14 665c255d 2023-08-04 jrmu ((z 'set-car!) new-value)
16 665c255d 2023-08-04 jrmu (define (set-cdr! z new-value)
17 665c255d 2023-08-04 jrmu ((z 'set-cdr!) new-value)
20 665c255d 2023-08-04 jrmu Assignment is all that is needed, theoretically, to account for the behavior of mutable data. As soon as we admit set! to our language, we raise all the issues, not only of assignment, but of mutable data in general.21
22 665c255d 2023-08-04 jrmu Exercise 3.20. Draw environment diagrams to illustrate the evaluation of the sequence of expressions
24 665c255d 2023-08-04 jrmu (define x (cons 1 2))
25 665c255d 2023-08-04 jrmu (define z (cons x x))
26 665c255d 2023-08-04 jrmu (set-car! (cdr z) 17)