Page:AIM-453.djvu/66

From Wikisource
Jump to navigation Jump to search
There was a problem when proofreading this page.
Steele and Sussman
64
The Art of the Interpreter

{RPLACA Can Alter CAR Instead} Page 40

We have implicitly thought of the RPLACA operation as modifying a cons so as to have a different car. However, there is an interpretation in which RPLACA is thought of as modifying the CAR operator. Taking the car of an object always involves both the CAR operator and the object. When we perform an RPLACA on object denoted by FOO, all we can say is that the value of (CAR FOO) may have changed. It is not necessarily clear what aspect of that expression has changed. Using this idea, we can express RPLACA in terms of SETQ as in Figure N9. Note that we depend on EQ to distinguish different results of CONS.

(DEFINE (RPLACA X Y)
        (PROGN ((LAMBDA (OLDCAR)
                        (SETQ CAR
                              (LAMBDA (Z)
                                      (COND ((EQ Z X) Y)
                                            (T (OLDCAR X))))))
                CAR)
               X))

Figure N9
RPLACA in Terms of SETQ Which Modifies CAR