Page:Scheme - An interpreter for extended lambda calculus.djvu/3

This page has been validated.
Sussman and Steele December 22, 1975 2 The SCHEME Reference Manual
one to count the cdr, as follows:
(DEFINE COUNT
    (LAMBDA (L)
        (LABELS ((COUNTCAR
                  (LAMBDA (L)
                      (IF (ATOM L) 1
                          (+ (COUNTCAR (CAR L))
                             (COUNTCDR (CDR L))))))
                 (COUNTCDR
                  (LAMBDA (L)
                      (IF (ATOM L)
                          (IF (NULL L) 0 1)
                          (+ (COUNTCAR (CAR L))
                             (COUNTCDR (CDR L)))))))
                (COUNTCDR L))))         ;Note: COUNTCDR is defined here.
ASET
This is the side effect primitive. It is analogous to the LISP function SET. For example, to define a cell [Smith and Hewitt], we may use ASET as follows:
(DEFINE CONS-CELL
    (LAMBDA (CONTENTS)
        (LABELS ((THE-CELL
                  (LAMBDA (MSG)
                      (IF (EQ MSG 'CONTENTS?) CONTENTS
                          (IF (EQ MSG 'CELL?) 'YES
                              (IF (EQ (CAR MSG) '<-)
                                  (BLOCK (ASET 'CONTENTS (CADR MSG))
                                         THE-CELL)
                                  (ERROR '|UNRECOGNIZED MESSAGE - CELL|
                                          MSG
                                          'WRNG-TYPE-ARG)))))))
                THE-CELL)))

Those of you who may complain about the lack of ASETQ are invited to write (ASET' foo bar) instead of (ASET 'foo bar).

EVALUATE
This is similar to the LISP function EVAL. It evaluates its argument, and then evaluates the resulting s-expression as SCHEME code.
CATCH
This is the "escape operator" which gives the user a handle on the control structure of the interpreter. The expression:
(CATCH <identifier> <expression>)