Page:AIM-453.djvu/60

From Wikisource
Jump to navigation Jump to search
This page has been proofread, but needs to be validated.
Steele and Sussman
58
The Art of the Interpreter

(DEFINE (EVAL EXP ENV)
        (COND ((ATOM EXP)
               (COND ((NUMBERP EXP) EXP)
                     (T (VALUE EXP ENV))))
              ((EQ (CAR EXP) 'QUOTE)
               (CADR EXP))
              (EQ (CAR EXP) 'LAMBDA)
              (LIST '&PROCEDURE (CADR EXP) (CADDR EXP) ENV))
        ((EQ (CAR EXP) 'LABELS)
         (EVLABELS (CADR EXP) EXP '() '() ENV))
        ((EQ (CAR EXP) 'COND)
         (EVCOND (CDR EXP) ENV))
        (T (APPLY (EVAL (CAR EXP) ENV)
                  (EVLIS (CDR EXP) ENV))))

(DEFINE (EVLABELS DEFINITIONS EXP NAMES FNS ENV)
        (COND ((NULL DEFINITIONS)
               (EVAL (CADDR EXP) (BIND NAMES FNS ENV)))
              (T (EVLABELS (CDR DEFINITIONS)
                           EXP
                           (CONS (CAAAR DEFINITIONS) NAMES)
                           (CONS (LIST '&LABELED
                                       (CDAAR DEFINITIONS)
                                       (CADAR DEFINITIONS))
                                 FNS)
                           ENV))))

For VALUE, LOOKUP, and BIND see Figure 3.
For EVCOND and EVLIS see Figure 5.
For APPLY see Figure 7.
For LOOKUP1 see Figure 10 (not Figure 3).

Figure N5
An Evaluator For Local Lexical Scoping,
Dynamic Top-Level References,
and Local Definition of Recursive Procedures