There was a problem when proofreading this page.

Steele and Sussman


The Art of the Interpreter

Equipotency of SETQ and RPLACA

We pulled a fast one when we introduced RPLACA and RPLACD for the sake of implementing SETQ (though we actually only used RPLACA). We used a side effect to define the implementation of side effects. While this makes a fine meta-circular description, it doesn't constitute a definition of side effects founded in the original meta-circular recursion equations interpreter.

We could implement an interpreter which would define a side effect without itself using side effects. Such a definition would encapsulate the entire state of the user's data structures into a single interpreter data structure which is passed around by a top-level loop. Constructing such an interpreter would involve turning a regular interpreter inside out (in much the same way GAUSSIAN was everted in {Note Weber}). This is extremely difficult and lengthy, and the module boundaries within the interpreter are so destroyed that the resulting interpreter is nearly impossible to understand. We will spare the reader the details.

We settle for a meta-circular description of side effects. Now that we have seen how to implement SETQ terms of RPLACA and RPLACD, we can also do the reverse, completing the meta-circle (see Figure 13). We use the procedural version of CONS shown earlier, modified to provide two "setting procedures" SA and SD, which provide the ability to alter the car and cdr.

        (LAMBDA (M)
                (M A D (LAMBDA (Z) (SETQ A Z)) (LAMBDA (Z) (SETQ D Z)))))

        (X (LAMBDA (A D SA SD) A))

        (X (LAMBDA (A D SA SD) D))

        (X (LAMBDA (A D SA SD)
                   (PROGN (SA Y) X))))

        (X (LAMBDA (A D SA SD)
                   (PROGN (SD Y) X))))

Figure 13
Procedural ("Actors-like") Implementation of CONS and Friends

We originally introduced side effects such as SETQ to help us build modules such as RANDOM which have local state. Now, using the technique of