There was a problem when proofreading this page.
Steele and Sussman
59
The Art of the Interpreter
{LABELS with Side Effects} Page 37
This implementation of LABELS (see Figure N6) applies the technique of {Note Driver Loop with Side Effects} to the implementation of LABELS in {Note LABELS}. This is in fact how LABELS (or its cousin LABEL) is usually implemented in "real" LISP systems.
(DEFINE (EVLABELS DEFINITIONS EXP NAMES FNS ENV)
(COND ((NULL DEFINITIONS)
(EVLABELS-CLOSE (CADR EXP) EXP NIL (BIND NAMES FNS ENV)))
(T (EVLABELS (CDR DEFINITIONS)
EXP
(CONS (CAAR DEFINITIONS) NAMES)
(CONS '&UNASSIGNED FNS)
ENV))))
(DEFINE (EVLABELS-CLOSE DEFINITIONS EXP VALS ENV)
(COND ((NULL DEFINITIONS)
(EVLABELS-CLOBBER NIL EXP (CDAR ENV) VALS ENV))
(T (EVLABELS-CLOSE (CDR DEFINITIONS)
EXP
(CONS (LIST '&PROCEDURE
(CDAAR DEFINITIONS)
(CADAR DEFINITIONS)
ENV)
VALS)
ENV))))
(DEFINE (EVLABELS-CLOBBER HUNOZ EXP SLOTS VALS ENV)
(COND ((NULL VALS)
(EVAL (CADDR EXP) ENV))
(T (EVLABELS-CLOBBER (RPLACA SLOTS (CAR VALS))
EXP
(CDR SLOTS)
(CDR VALS)
ENV))))
For EVAL
and EVSETQ
see Figure 11.
For LOOKUP1
see Figure 3 (not Figure 10, despite Figure 11!).
Figure N6
Implementation of LABELS
Using Side Effects