\documentstyle[makeidx]{article}
\makeindex
%\setlength{\oddsidemargin}{.5in}
%\setlength{\evensidemargin}{.5in}
%\setlength{\textwidth}{5.8in}
\begin{document}
%\setlength{\parindent}{0pt}
%\newcounter{bean}
%\begin{list}{\arabic{bean}.}{\usecounter{bean}\setlength{\leftmargin}{0pt}\setlength{\rightmargin}{0pt}\setlength{\listparindent}{20pt}\setlength{\parsep}{5pt}}
%\item[]

\begin{verbatim}#|

 Copyright (C) 1994 by Computational Logic, Inc.  All Rights Reserved.

 This script is hereby placed in the public domain, and therefore unlimited
 editing and redistribution is permitted.

 NO WARRANTY

 Computational Logic, Inc. PROVIDES ABSOLUTELY NO WARRANTY.  THE EVENT SCRIPT
 IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED,
 INCLUDING, BUT NOT LIMITED TO, ANY IMPLIED WARRANTIES OF MERCHANTABILITY AND
 FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS TO THE QUALITY AND
 PERFORMANCE OF THE SCRIPT IS WITH YOU.  SHOULD THE SCRIPT PROVE DEFECTIVE, YOU
 ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.

 IN NO EVENT WILL Computational Logic, Inc. BE LIABLE TO YOU FOR ANY DAMAGES,
 ANY LOST PROFITS, LOST MONIES, OR OTHER SPECIAL, INCIDENTAL OR CONSEQUENTIAL
 DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THIS SCRIPT (INCLUDING BUT
 NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES
 SUSTAINED BY THIRD PARTIES), EVEN IF YOU HAVE ADVISED US OF THE POSSIBILITY OF
 SUCH DAMAGES, OR FOR ANY CLAIM BY ANY OTHER PARTY.
|#

; The Formalized Extended Syntax


; SECTION: Introduction

; This file, examples/basic/parser.events, is a formalization of
; the extended syntax as presented in Chapter 4.  We formalize the
; syntax in the logic itself.  Roughly speaking, for every occur-
; rence of ``Terminology'' in Chapter 4 there is an admissible
; function definition here that formalizes the concept defined in
; Chapter 4.  For example, we formally define what it is to be a
; ``numeric sequence'' by introducing a function which returns T or
; F according to whether its argument is such a sequence.

; The outline of our presentation is as follows.  We first develop
; the notion of a ``token tree.''  Token trees in the logic are re-
; presented by integers, literal atoms, and list structures.  The
; text in Chapter 4 then develops the idea of how to ``display'' a
; token tree.  Here we do the inverse: we formalize the notion of
; how to parse a token tree from a sequence of ASCII character
; codes.  This culminates in the definition of READ-TOKEN-TREE
; which takes a list of character codes and returns either F (in-
; dicating that the input sequence is unparsable) or a token tree.
; We then return to the text of Chapter 4 and formalize what it is
; for a token tree to be ``readable,'' what ``readmacro-expansion''
; is, and what an ``s-expression'' is.  This part of the formal-
; ization may illuminate backquote notation for those unfamiliar
; with it.  We finally define what it is for an s-expression to be
; ``well-formed'' and what the ``translation'' of such an
; s-expression is.

; This presentation is meant to clarify the extended syntax.  Thus,
; it would hardly do to express the formalization in terms of the
; extended syntax.  We therefore largely confine ourselves here to
; the formal syntax with the following exceptions:

; 1. We permit ourselves to write natural numbers, e.g., 2, in 
;    place of their formal equivalents, e.g., (ADD1 (ADD1 (ZERO))).

; 2. We permit ourselves to use QUOTE notation to denote literal
;    atom constants.  Thus, we write 'ABC where
;      (PACK (CONS 65 (CONS 66 (CONS 67 0))))
;    would otherwise be needed.

; 3. We occasionally display list constants in QUOTE notation,
;    e.g., '(UPPER-B UPPER-O UPPER-X) is written in place of
;    (CONS 'UPPER-B (CONS 'UPPER-O (CONS 'UPPER-X 'NIL))).  Two
;    large association lists are displayed with QUOTE notation.
;    These displays are in conjunction with the definitions of
;    utility functions whose semantics is intuitively clear, namely
;    a function that maps from our name for an ASCII character to
;    its ASCII code and a function that maps from the name of a
;    function to its arity.

; 4. We permit ourselves to write comments.

; It should be stressed that these are ``exceptions'' only in the
; sense that they are not part of the formal syntax.  These con-
; ventions are entirely supported by the extended syntax and we
; note their use only because they are exceptions to our self-
; imposed restriction to the formal syntax in this file.

; We have followed the text's style of the definition very closely.
; This results in a somewhat ``inefficient'' formalization.  For
; example, it is possible to implement the parsing/readmacro-expan-
; sion process in a single pass, but we have not done so.  While we
; feel our use of the logic here is illustrative of ``good usage''
; the critical reader must keep in mind that we are trying to
; formalize the ideas as presented in the text and not merely code
; a parser in the logic.

; This file may be processed with PROVE-FILE and the resulting
; library may be noted and used in R-LOOP to experiment with the
; syntax.  We recommend that the library be compiled.  If the Nqthm
; installer has so processed the file, the library file may already
; exist as examples/basic/parser.  This source file also contains
; ``commented out'' Common Lisp code that permits more convenient
; experimentation.  Search for occurrences of ``defun'' to find the
; two regions in question.

; Finally, this file serves as a good example of a fairly substan-
; tial Nqthm formalization effort.  We recommend it even to readers
; who know the syntax but who wish to see how Nqthm is used to
; formalize ideas that are already precisely (but informally)
; understood.  We urge such readers to compare the formal defini-
; tions with the corresponding informal definitions of Chapter 4.

; We start by initializing Nqthm's data base to the GROUND-ZERO
; theory.

\end{verbatim}
\noindent{\sc Event}:   Start with the initial {\bf nqthm} theory.

\addvspace{18pt}


\begin{verbatim}; SECTION: Conventions Concerning Characters

; In the text we imagine that we have integers, characters and
; sequences of characters as our atoms.  We then build token trees
; as sequences of these atoms and other token trees.  Thus, the
; sequence consisting of 65, 66, and 67 is uniquely recognized as
; being a sequence of integers, while the sequence consisting of
; the characters A, B, and C, is recognized as being a word.

; But in this formalization, we do not have characters and in fact
; we use their ASCII codes instead.  But the ASCII codes are them-
; selves integers.  Thus, the sequence containing 65, 66, and 67 is
; ambiguous as a token tree: is it a tree containing three integers
; or is it a tree containing the word ABC?  Fortunately, characters
; never enter token trees except as the elements of words and the
; various tokens.  Therefore, in this formalization we use LITATOMs
; to represent the words and the tokens.  That is, where the text
; represents the word ABC as a sequence consisting of the char-
; acters A, B, and C, the formalization will represent it as a
; LITATOM obtained by PACKing the ASCII codes for A, B, and C
; (around a 0).  Similarly, the backquote token in the text is the
; sequence consisting of the backquote character, but here it is
; the LITATOM obtained by packing the ASCII code for that character
; (around a 0).

; We first make it convenient to refer to the ASCII character code
; of all the printable characters.  We will invent a name for each
; character, e.g., UPPER-A, LOWER-B, OPEN-PAREN, and define (ASCII
; name) to be the ASCII integer code for the named character.  Thus
; (ASCII 'UPPER-A) will be 65.  We will also define ASCII so that
; when given a list of names it returns the list of ASCII codes for
; the characters named in the list.  Thus, (ASCII '(UPPER-A
; LOWER-A)) will be '(65 97).  This is just a clumsy way to circumvent
; the omission of character strings from Nqthm's universe of objects.

; The codes we assign to TAB, NEWLINE, PAGE, SPACE, and RUBOUT are
; those used in AKCL; typically those codes vary from one Common
; Lisp to another.  This variance is not important to our
; formalization, as we are just assigning unique integers to
; certain character names known to our function ASCII.  For
; example, even in a Lisp assigning #\Newline a code other than 10,
; our ASCII function will assign NEWLINE the code 10 and our parser
; will execute as intended on ``strings'' obtained by writing
; (ASCII '(... NEWLINE ...)).  However, the user wishing to
; experiment with the parser may wish to write a Lisp utility that
; converts user typein into lists of character codes, so as to
; avoid the use of our clumsy ASCII function.  Care must be taken
; in the definition of such a utility so that the first five
; characters listed below are assigned the codes shown.

; The names and their ASCII codes are given in the following
; association list:

\end{verbatim}\begin{tabbing}{\sc Definition}:\index{ascii-table} \\  
\=\+{\sc{ascii-table}}\index{ascii-table} \\ 
$=$$\;\;\;\;${\tt{'}}{\tt{(}}\=\+{\tt{(}}{\tt{tab}}{\tt{ .\ }}{\tt{9}}{\tt{)}} \\ 
{\tt{(}}{\tt{newline}}{\tt{ .\ }}{\tt{10}}{\tt{)}} \\ 
{\tt{(}}{\tt{page}}{\tt{ .\ }}{\tt{12}}{\tt{)}} \\ 
{\tt{(}}{\tt{space}}{\tt{ .\ }}{\tt{32}}{\tt{)}} \\ 
{\tt{(}}{\tt{rubout}}{\tt{ .\ }}{\tt{127}}{\tt{)}} \\ 
{\tt{(}}{\tt{exclamation-point}}{\tt{ .\ }}{\tt{33}}{\tt{)}} \\ 
{\tt{(}}{\tt{double-quote}}{\tt{ .\ }}{\tt{34}}{\tt{)}} \\ 
{\tt{(}}{\tt{number-sign}}{\tt{ .\ }}{\tt{35}}{\tt{)}} \\ 
{\tt{(}}{\tt{dollar-sign}}{\tt{ .\ }}{\tt{36}}{\tt{)}} \\ 
{\tt{(}}{\tt{percent-sign}}{\tt{ .\ }}{\tt{37}}{\tt{)}} \\ 
{\tt{(}}{\tt{ampersand}}{\tt{ .\ }}{\tt{38}}{\tt{)}} \\ 
{\tt{(}}{\tt{single-quote}}{\tt{ .\ }}{\tt{39}}{\tt{)}} \\ 
{\tt{(}}{\tt{open-paren}}{\tt{ .\ }}{\tt{40}}{\tt{)}} \\ 
{\tt{(}}{\tt{close-paren}}{\tt{ .\ }}{\tt{41}}{\tt{)}} \\ 
{\tt{(}}{\tt{asterisk}}{\tt{ .\ }}{\tt{42}}{\tt{)}} \\ 
{\tt{(}}{\tt{plus-sign}}{\tt{ .\ }}{\tt{43}}{\tt{)}} \\ 
{\tt{(}}{\tt{comma}}{\tt{ .\ }}{\tt{44}}{\tt{)}} \\ 
{\tt{(}}{\tt{minus-sign}}{\tt{ .\ }}{\tt{45}}{\tt{)}} \\ 
{\tt{(}}{\tt{dot}}{\tt{ .\ }}{\tt{46}}{\tt{)}} \\ 
{\tt{(}}{\tt{slash}}{\tt{ .\ }}{\tt{47}}{\tt{)}} \\ 
{\tt{(}}{\tt{digit-zero}}{\tt{ .\ }}{\tt{48}}{\tt{)}} \\ 
{\tt{(}}{\tt{digit-one}}{\tt{ .\ }}{\tt{49}}{\tt{)}} \\ 
{\tt{(}}{\tt{digit-two}}{\tt{ .\ }}{\tt{50}}{\tt{)}} \\ 
{\tt{(}}{\tt{digit-three}}{\tt{ .\ }}{\tt{51}}{\tt{)}} \\ 
{\tt{(}}{\tt{digit-four}}{\tt{ .\ }}{\tt{52}}{\tt{)}} \\ 
{\tt{(}}{\tt{digit-five}}{\tt{ .\ }}{\tt{53}}{\tt{)}} \\ 
{\tt{(}}{\tt{digit-six}}{\tt{ .\ }}{\tt{54}}{\tt{)}} \\ 
{\tt{(}}{\tt{digit-seven}}{\tt{ .\ }}{\tt{55}}{\tt{)}} \\ 
{\tt{(}}{\tt{digit-eight}}{\tt{ .\ }}{\tt{56}}{\tt{)}} \\ 
{\tt{(}}{\tt{digit-nine}}{\tt{ .\ }}{\tt{57}}{\tt{)}} \\ 
{\tt{(}}{\tt{colon}}{\tt{ .\ }}{\tt{58}}{\tt{)}} \\ 
{\tt{(}}{\tt{semicolon}}{\tt{ .\ }}{\tt{59}}{\tt{)}} \\ 
{\tt{(}}{\tt{less-than-sign}}{\tt{ .\ }}{\tt{60}}{\tt{)}} \\ 
{\tt{(}}{\tt{equal-sign}}{\tt{ .\ }}{\tt{61}}{\tt{)}} \\ 
{\tt{(}}{\tt{greater-than-sign}}{\tt{ .\ }}{\tt{62}}{\tt{)}} \\ 
{\tt{(}}{\tt{question-mark}}{\tt{ .\ }}{\tt{63}}{\tt{)}} \\ 
{\tt{(}}{\tt{at-sign}}{\tt{ .\ }}{\tt{64}}{\tt{)}} \\ 
{\tt{(}}{\tt{upper-a}}{\tt{ .\ }}{\tt{65}}{\tt{)}} \\ 
{\tt{(}}{\tt{upper-b}}{\tt{ .\ }}{\tt{66}}{\tt{)}} \\ 
{\tt{(}}{\tt{upper-c}}{\tt{ .\ }}{\tt{67}}{\tt{)}} \\ 
{\tt{(}}{\tt{upper-d}}{\tt{ .\ }}{\tt{68}}{\tt{)}} \\ 
{\tt{(}}{\tt{upper-e}}{\tt{ .\ }}{\tt{69}}{\tt{)}} \\ 
{\tt{(}}{\tt{upper-f}}{\tt{ .\ }}{\tt{70}}{\tt{)}} \\ 
{\tt{(}}{\tt{upper-g}}{\tt{ .\ }}{\tt{71}}{\tt{)}} \\ 
{\tt{(}}{\tt{upper-h}}{\tt{ .\ }}{\tt{72}}{\tt{)}} \\ 
{\tt{(}}{\tt{upper-i}}{\tt{ .\ }}{\tt{73}}{\tt{)}} \\ 
{\tt{(}}{\tt{upper-j}}{\tt{ .\ }}{\tt{74}}{\tt{)}} \\ 
{\tt{(}}{\tt{upper-k}}{\tt{ .\ }}{\tt{75}}{\tt{)}} \\ 
{\tt{(}}{\tt{upper-l}}{\tt{ .\ }}{\tt{76}}{\tt{)}} \\ 
{\tt{(}}{\tt{upper-m}}{\tt{ .\ }}{\tt{77}}{\tt{)}} \\ 
{\tt{(}}{\tt{upper-n}}{\tt{ .\ }}{\tt{78}}{\tt{)}} \\ 
{\tt{(}}{\tt{upper-o}}{\tt{ .\ }}{\tt{79}}{\tt{)}} \\ 
{\tt{(}}{\tt{upper-p}}{\tt{ .\ }}{\tt{80}}{\tt{)}} \\ 
{\tt{(}}{\tt{upper-q}}{\tt{ .\ }}{\tt{81}}{\tt{)}} \\ 
{\tt{(}}{\tt{upper-r}}{\tt{ .\ }}{\tt{82}}{\tt{)}} \\ 
{\tt{(}}{\tt{upper-s}}{\tt{ .\ }}{\tt{83}}{\tt{)}} \\ 
{\tt{(}}{\tt{upper-t}}{\tt{ .\ }}{\tt{84}}{\tt{)}} \\ 
{\tt{(}}{\tt{upper-u}}{\tt{ .\ }}{\tt{85}}{\tt{)}} \\ 
{\tt{(}}{\tt{upper-v}}{\tt{ .\ }}{\tt{86}}{\tt{)}} \\ 
{\tt{(}}{\tt{upper-w}}{\tt{ .\ }}{\tt{87}}{\tt{)}} \\ 
{\tt{(}}{\tt{upper-x}}{\tt{ .\ }}{\tt{88}}{\tt{)}} \\ 
{\tt{(}}{\tt{upper-y}}{\tt{ .\ }}{\tt{89}}{\tt{)}} \\ 
{\tt{(}}{\tt{upper-z}}{\tt{ .\ }}{\tt{90}}{\tt{)}} \\ 
{\tt{(}}{\tt{open-bracket}}{\tt{ .\ }}{\tt{91}}{\tt{)}} \\ 
{\tt{(}}{\tt{backslash}}{\tt{ .\ }}{\tt{92}}{\tt{)}} \\ 
{\tt{(}}{\tt{close-bracket}}{\tt{ .\ }}{\tt{93}}{\tt{)}} \\ 
{\tt{(}}{\tt{uparrow}}{\tt{ .\ }}{\tt{94}}{\tt{)}} \\ 
{\tt{(}}{\tt{underscore}}{\tt{ .\ }}{\tt{95}}{\tt{)}} \\ 
{\tt{(}}{\tt{backquote}}{\tt{ .\ }}{\tt{96}}{\tt{)}} \\ 
{\tt{(}}{\tt{lower-a}}{\tt{ .\ }}{\tt{97}}{\tt{)}} \\ 
{\tt{(}}{\tt{lower-b}}{\tt{ .\ }}{\tt{98}}{\tt{)}} \\ 
{\tt{(}}{\tt{lower-c}}{\tt{ .\ }}{\tt{99}}{\tt{)}} \\ 
{\tt{(}}{\tt{lower-d}}{\tt{ .\ }}{\tt{100}}{\tt{)}} \\ 
{\tt{(}}{\tt{lower-e}}{\tt{ .\ }}{\tt{101}}{\tt{)}} \\ 
{\tt{(}}{\tt{lower-f}}{\tt{ .\ }}{\tt{102}}{\tt{)}} \\ 
{\tt{(}}{\tt{lower-g}}{\tt{ .\ }}{\tt{103}}{\tt{)}} \\ 
{\tt{(}}{\tt{lower-h}}{\tt{ .\ }}{\tt{104}}{\tt{)}} \\ 
{\tt{(}}{\tt{lower-i}}{\tt{ .\ }}{\tt{105}}{\tt{)}} \\ 
{\tt{(}}{\tt{lower-j}}{\tt{ .\ }}{\tt{106}}{\tt{)}} \\ 
{\tt{(}}{\tt{lower-k}}{\tt{ .\ }}{\tt{107}}{\tt{)}} \\ 
{\tt{(}}{\tt{lower-l}}{\tt{ .\ }}{\tt{108}}{\tt{)}} \\ 
{\tt{(}}{\tt{lower-m}}{\tt{ .\ }}{\tt{109}}{\tt{)}} \\ 
{\tt{(}}{\tt{lower-n}}{\tt{ .\ }}{\tt{110}}{\tt{)}} \\ 
{\tt{(}}{\tt{lower-o}}{\tt{ .\ }}{\tt{111}}{\tt{)}} \\ 
{\tt{(}}{\tt{lower-p}}{\tt{ .\ }}{\tt{112}}{\tt{)}} \\ 
{\tt{(}}{\tt{lower-q}}{\tt{ .\ }}{\tt{113}}{\tt{)}} \\ 
{\tt{(}}{\tt{lower-r}}{\tt{ .\ }}{\tt{114}}{\tt{)}} \\ 
{\tt{(}}{\tt{lower-s}}{\tt{ .\ }}{\tt{115}}{\tt{)}} \\ 
{\tt{(}}{\tt{lower-t}}{\tt{ .\ }}{\tt{116}}{\tt{)}} \\ 
{\tt{(}}{\tt{lower-u}}{\tt{ .\ }}{\tt{117}}{\tt{)}} \\ 
{\tt{(}}{\tt{lower-v}}{\tt{ .\ }}{\tt{118}}{\tt{)}} \\ 
{\tt{(}}{\tt{lower-w}}{\tt{ .\ }}{\tt{119}}{\tt{)}} \\ 
{\tt{(}}{\tt{lower-x}}{\tt{ .\ }}{\tt{120}}{\tt{)}} \\ 
{\tt{(}}{\tt{lower-y}}{\tt{ .\ }}{\tt{121}}{\tt{)}} \\ 
{\tt{(}}{\tt{lower-z}}{\tt{ .\ }}{\tt{122}}{\tt{)}} \\ 
{\tt{(}}{\tt{open-brace}}{\tt{ .\ }}{\tt{123}}{\tt{)}} \\ 
{\tt{(}}{\tt{vertical-bar}}{\tt{ .\ }}{\tt{124}}{\tt{)}} \\ 
{\tt{(}}{\tt{close-brace}}{\tt{ .\ }}{\tt{125}}{\tt{)}} \\ 
{\tt{(}}{\tt{tilde}}{\tt{ .\ }}{\tt{126}}{\tt{)}}{\tt{)}}\-\-
\end{tabbing}	\begin{verbatim}; ~

\end{verbatim}\begin{tabbing}{\sc Definition}:\index{ascii-list} \\  
\=\+{\rm{ascii-list}}\,({\it{lst\/}})\index{ascii-list} \\ 
$=$$\;\;\;\;$\=\+{\bf if }{\it{lst\/}} $\simeq\;${{\bf{nil}}}${}$$\;\;${\bf then }{\bf{nil}} \\ 
{\bf else }{\rm{cons}}\,({\rm{cdr}}\,({\rm{assoc}}\,({\rm{car}}\,({\it{lst\/}}), {\sc{ascii-table}}\index{ascii-table})), {\rm{ascii-list}}\,({\rm{cdr}}\,({\it{lst\/}}))\index{ascii-list})$\;${\bf  endif}\-\-
\end{tabbing}

\begin{tabbing}{\sc Definition}:\index{ascii} \\  
\=\+{\rm{ascii}}\,({\it{x\/}})\index{ascii} \\ 
$=$$\;\;\;\;$\=\+{\bf if }{\rm{litatom}}\,({\it{x\/}})$\;\;${\bf then }{\rm{cdr}}\,({\rm{assoc}}\,({\it{x\/}}, {\sc{ascii-table}}\index{ascii-table})) \\ 
{\bf else }{\rm{ascii-list}}\,({\it{x\/}})\index{ascii-list}$\;${\bf  endif}\-\-
\end{tabbing}

\begin{verbatim}; So now we can write (ASCII 'UPPER-A) for 65 and 
; (ASCII '(UPPER-A LOWER-A)) for '(65 97).


; SECTION: Token Trees

\end{verbatim}\begin{tabbing}{\sc Definition}:\index{upper-digits} \\  
\=\+{\sc{upper-digits}}\index{upper-digits} \\ 
$=$$\;\;\;\;${\rm{ascii}}\,({\tt{'}}{\tt{(}}\=\+{\tt{digit-zero}}{\tt{ }}{\tt{digit-one}}{\tt{ }}{\tt{digit-two}}{\tt{ }}{\tt{digit-three}} \\ 
{\tt{digit-four}}{\tt{ }}{\tt{digit-five}}{\tt{ }}{\tt{digit-six}}{\tt{ }}{\tt{digit-seven}} \\ 
{\tt{digit-eight}}{\tt{ }}{\tt{digit-nine}}{\tt{ }}{\tt{upper-a}}{\tt{ }}{\tt{upper-b}}{\tt{ }}{\tt{upper-c}} \\ 
{\tt{upper-d}}{\tt{ }}{\tt{upper-e}}{\tt{ }}{\tt{upper-f}}{\tt{)}}\-)\index{ascii}\-
\end{tabbing}

\begin{verbatim}; We define (CADRN n LST) to be equivalent to (CADD...DR LST) where
; the number of D's is n.  Thus, (CADRN 2 LST) is (CADDR LST).  An-
; other way to think about CADRN is that it returns the Nth element
; of LST using 0-based enumeration, e.g., (CADRN 3 '(A B C D E F))
; is 'D.

\end{verbatim}\begin{tabbing}{\sc Definition}:\index{cdrn} \\  
\=\+{\rm{cdrn}}\,({\it{n\/}}, {\it{lst\/}})\index{cdrn} \\ 
$=$$\;\;\;\;$\=\+{\bf if }{\it{n\/}} $\simeq {\tt{0}}$$\;\;${\bf then }{\it{lst\/}} \\ 
{\bf else }{\rm{cdrn}}\,({\it{n\/}} $-\;1$, {\rm{cdr}}\,({\it{lst\/}}))\index{cdrn}$\;${\bf  endif}\-\-
\end{tabbing}

\begin{tabbing}{\sc Definition}:\index{cadrn}$\;\;$
{\rm{cadrn}}\,({\it{n\/}}, {\it{lst\/}})\index{cadrn} $=$ {\rm{car}}\,({\rm{cdrn}}\,({\it{n\/}}, {\it{lst\/}})\index{cdrn})
\end{tabbing}

\begin{verbatim}; It is also convenient to have

\end{verbatim}\begin{tabbing}{\sc Definition}:\index{list1}$\;\;$
{\rm{list1}}\,({\it{x\/}})\index{list1} $=$ {\rm{cons}}\,({\it{x\/}}, {\bf{nil}})
\end{tabbing}
\begin{tabbing}{\sc Definition}:\index{list2}$\;\;$
{\rm{list2}}\,({\it{x\/}}, {\it{y\/}})\index{list2} $=$ {\rm{cons}}\,({\it{x\/}}, {\rm{list1}}\,({\it{y\/}})\index{list1})
\end{tabbing}
\begin{tabbing}{\sc Definition}:\index{list3}$\;\;$
{\rm{list3}}\,({\it{x\/}}, {\it{y\/}}, {\it{z\/}})\index{list3} $=$ {\rm{cons}}\,({\it{x\/}}, {\rm{list2}}\,({\it{y\/}}, {\it{z\/}})\index{list2})
\end{tabbing}

\begin{verbatim}; because we are eschewing the use of the abbreviation LIST.

\end{verbatim}\begin{tabbing}{\sc Definition}:\index{first-n} \\  
\=\+{\rm{first-n}}\,({\it{n\/}}, {\it{lst\/}})\index{first-n} \\ 
$=$$\;\;\;\;$\=\+{\bf if }{\it{n\/}} $\simeq {\tt{0}}$$\;\;${\bf then }{\bf{nil}} \\ 
{\bf else }{\rm{cons}}\,({\rm{car}}\,({\it{lst\/}}), {\rm{first-n}}\,({\it{n\/}} $-\;1$, {\rm{cdr}}\,({\it{lst\/}}))\index{first-n})$\;${\bf  endif}\-\-
\end{tabbing}

\begin{tabbing}{\sc Definition}:\index{base-n-digit-character} \\  
\=\+{\rm{base-n-digit-character}}\,({\it{n\/}}, {\it{c\/}})\index{base-n-digit-character} \\ 
$=$$\;\;\;\;$(({\it{n\/}} $\leq$ {\tt{16}}) $\wedge$ ({\it{c\/}} $\in$ {\rm{first-n}}\,({\it{n\/}}, {\sc{upper-digits}}\index{upper-digits})\index{first-n}))\-
\end{tabbing}

\begin{tabbing}{\sc Definition}:\index{position} \\  
\=\+{\rm{position}}\,({\it{x\/}}, {\it{lst\/}})\index{position} \\ 
$=$$\;\;\;\;$\=\+{\bf if }{\it{lst\/}} $\simeq\;${{\bf{nil}}}${}$$\;\;${\bf then }{\tt{0}} \\ 
{\bf elseif }{\it{x\/}} $=$ {\rm{car}}\,({\it{lst\/}})$\;\;${\bf then }{\tt{0}} \\ 
{\bf else }$1\;+$ {\rm{position}}\,({\it{x\/}}, {\rm{cdr}}\,({\it{lst\/}}))\index{position}$\;${\bf  endif}\-\-
\end{tabbing}

\begin{tabbing}{\sc Definition}:\index{base-n-digit-value}$\;\;$
{\rm{base-n-digit-value}}\,({\it{c\/}})\index{base-n-digit-value} $=$ {\rm{position}}\,({\it{c\/}}, {\sc{upper-digits}}\index{upper-digits})\index{position}
\end{tabbing}

\begin{tabbing}{\sc Definition}:\index{all-base-n-digit-characters} \\  
\=\+{\rm{all-base-n-digit-characters}}\,({\it{n\/}}, {\it{lst\/}})\index{all-base-n-digit-characters} \\ 
$=$$\;\;\;\;$\=\+{\bf if }{\it{lst\/}} $\simeq\;${{\bf{nil}}}${}$$\;\;${\bf then }{\bf{t}} \\ 
{\bf else }\=\+{\rm{base-n-digit-character}}\,({\it{n\/}}, {\rm{car}}\,({\it{lst\/}}))\index{base-n-digit-character} \\ 
$\wedge$$\;\;\;\;${\rm{all-base-n-digit-characters}}\,({\it{n\/}}, {\rm{cdr}}\,({\it{lst\/}}))\index{all-base-n-digit-characters}\-$\;${\bf  endif}\-\-
\end{tabbing}

\begin{tabbing}{\sc Definition}:\index{base-n-digit-sequence} \\  
\=\+{\rm{base-n-digit-sequence}}\,({\it{n\/}}, {\it{lst\/}})\index{base-n-digit-sequence} \\ 
$=$$\;\;\;\;$({\rm{listp}}\,({\it{lst\/}}) $\wedge$ {\rm{all-base-n-digit-characters}}\,({\it{n\/}}, {\it{lst\/}})\index{all-base-n-digit-characters})\-
\end{tabbing}

\begin{tabbing}{\sc Definition}:\index{optionally-signed-base-n-digit-!sequence} \\  
\=\+{\rm{optionally-signed-base-n-digit-sequence}}\,({\it{n\/}}, {\it{lst\/}})\index{optionally-signed-base-n-digit-!sequence} \\ 
$=$$\;\;\;\;$(\=\+{\rm{base-n-digit-sequence}}\,({\it{n\/}}, {\it{lst\/}})\index{base-n-digit-sequence} \\ 
$\vee$$\;\;\;\;$(\=\+{\rm{listp}}\,({\it{lst\/}}) \\ 
$\wedge$$\;\;\;\;$(\=\+(\=\+({\rm{car}}\,({\it{lst\/}}) $=$ {\rm{ascii}}\,({\tt{'}}{\tt{plus-sign}})\index{ascii}) \\ 
$\vee$$\;\;\;\;$({\rm{car}}\,({\it{lst\/}}) $=$ {\rm{ascii}}\,({\tt{'}}{\tt{minus-sign}})\index{ascii}))\- \\ 
$\wedge$$\;\;\;\;${\rm{base-n-digit-sequence}}\,({\it{n\/}}, {\rm{cdr}}\,({\it{lst\/}}))\index{base-n-digit-sequence})\-)\-)\-\-
\end{tabbing}

\begin{tabbing}{\sc Definition}:\index{length} \\  
\=\+{\rm{length}}\,({\it{lst\/}})\index{length} \\ 
$=$$\;\;\;\;$\=\+{\bf if }{\it{lst\/}} $\simeq\;${{\bf{nil}}}${}$$\;\;${\bf then }{\tt{0}} \\ 
{\bf else }$1\;+$ {\rm{length}}\,({\rm{cdr}}\,({\it{lst\/}}))\index{length}$\;${\bf  endif}\-\-
\end{tabbing}

\begin{tabbing}{\sc Definition}:\index{exp} \\  
\=\+{\rm{exp}}\,({\it{i\/}}, {\it{j\/}})\index{exp} \\ 
$=$$\;\;\;\;$\=\+{\bf if }{\it{j\/}} $\simeq {\tt{0}}$$\;\;${\bf then }{\tt{1}} \\ 
{\bf else }{\it{i\/}} $*$ {\rm{exp}}\,({\it{i\/}}, {\it{j\/}} $-\;1$)\index{exp}$\;${\bf  endif}\-\-
\end{tabbing}

\begin{tabbing}{\sc Definition}:\index{base-n-value} \\  
\=\+{\rm{base-n-value}}\,({\it{n\/}}, {\it{lst\/}})\index{base-n-value} \\ 
$=$$\;\;\;\;$\=\+{\bf if }{\it{lst\/}} $\simeq\;${{\bf{nil}}}${}$$\;\;${\bf then }{\tt{0}} \\ 
{\bf else }\=\+({\rm{base-n-digit-value}}\,({\rm{car}}\,({\it{lst\/}}))\index{base-n-digit-value} $*$ {\rm{exp}}\,({\it{n\/}}, {\rm{length}}\,({\rm{cdr}}\,({\it{lst\/}}))\index{length})\index{exp}) \\ 
$+$$\;\;\;\;${\rm{base-n-value}}\,({\it{n\/}}, {\rm{cdr}}\,({\it{lst\/}}))\index{base-n-value}\-$\;${\bf  endif}\-\-
\end{tabbing}

\begin{tabbing}{\sc Definition}:\index{numerator-sequence} \\  
\=\+{\rm{numerator-sequence}}\,({\it{lst\/}})\index{numerator-sequence} \\ 
$=$$\;\;\;\;$\=\+{\bf if }{\it{lst\/}} $\simeq\;${{\bf{nil}}}${}$$\;\;${\bf then }{\bf{nil}} \\ 
{\bf elseif }{\rm{car}}\,({\it{lst\/}}) $=$ {\rm{ascii}}\,({\tt{'}}{\tt{slash}})\index{ascii}$\;\;${\bf then }{\bf{nil}} \\ 
{\bf else }{\rm{cons}}\,({\rm{car}}\,({\it{lst\/}}), {\rm{numerator-sequence}}\,({\rm{cdr}}\,({\it{lst\/}}))\index{numerator-sequence})$\;${\bf  endif}\-\-
\end{tabbing}

\begin{tabbing}{\sc Definition}:\index{denominator-sequence} \\  
\=\+{\rm{denominator-sequence}}\,({\it{lst\/}})\index{denominator-sequence} \\ 
$=$$\;\;\;\;$\=\+{\bf if }{\it{lst\/}} $\simeq\;${{\bf{nil}}}${}$$\;\;${\bf then }{\bf{nil}} \\ 
{\bf elseif }{\rm{car}}\,({\it{lst\/}}) $=$ {\rm{ascii}}\,({\tt{'}}{\tt{slash}})\index{ascii}$\;\;${\bf then }{\rm{cdr}}\,({\it{lst\/}}) \\ 
{\bf else }{\rm{denominator-sequence}}\,({\rm{cdr}}\,({\it{lst\/}}))\index{denominator-sequence}$\;${\bf  endif}\-\-
\end{tabbing}

\begin{tabbing}{\sc Definition}:\index{base-n-signed-value} \\  
\=\+{\rm{base-n-signed-value}}\,({\it{n\/}}, {\it{lst\/}})\index{base-n-signed-value} \\ 
$=$$\;\;\;\;$\=\+{\bf if }{\rm{car}}\,({\it{lst\/}}) $=$ {\rm{ascii}}\,({\tt{'}}{\tt{minus-sign}})\index{ascii} \\ 
{\bf then }$-$ {\rm{base-n-value}}\,({\it{n\/}}, {\rm{cdr}}\,({\it{lst\/}}))\index{base-n-value} \\ 
{\bf elseif }{\rm{car}}\,({\it{lst\/}}) $=$ {\rm{ascii}}\,({\tt{'}}{\tt{plus-sign}})\index{ascii} \\ 
{\bf then }{\rm{base-n-value}}\,({\it{n\/}}, {\rm{cdr}}\,({\it{lst\/}}))\index{base-n-value} \\ 
{\bf else }{\rm{base-n-value}}\,({\it{n\/}}, {\it{lst\/}})\index{base-n-value}$\;${\bf  endif}\-\-
\end{tabbing}

\begin{tabbing}{\sc Definition}:\index{number-sign-sequence} \\  
\=\+{\rm{number-sign-sequence}}\,({\it{lst\/}})\index{number-sign-sequence} \\ 
$=$$\;\;\;\;$(\=\+({\rm{length}}\,({\it{lst\/}})\index{length} $\geq$ {\tt{3}}) \\ 
$\wedge$$\;\;\;\;$({\rm{car}}\,({\it{lst\/}}) $=$ {\rm{ascii}}\,({\tt{'}}{\tt{number-sign}})\index{ascii}) \\ 
$\wedge$$\;\;\;\;$({\rm{cadrn}}\,({\tt{1}}, {\it{lst\/}})\index{cadrn} $\in$ {\rm{ascii}}\,({\tt{'}}{\tt{(}}{\tt{upper-b}}{\tt{ }}{\tt{upper-o}}{\tt{ }}{\tt{upper-x}}{\tt{)}})\index{ascii}) \\ 
$\wedge$$\;\;\;\;${\rm{optionally-signed-base-n-digit-sequence}}\,(\=\+\=\+{\bf if }\=\+{\rm{cadrn}}\,({\tt{1}}, {\it{lst\/}})\index{cadrn} \\ 
$=$$\;\;\;\;${\rm{ascii}}\,({\tt{'}}{\tt{upper-b}})\index{ascii}\- \\ 
{\bf then }{\tt{2}} \\ 
{\bf elseif }\=\+{\rm{cadrn}}\,({\tt{1}}, {\it{lst\/}})\index{cadrn} \\ 
$=$$\;\;\;\;${\rm{ascii}}\,({\tt{'}}{\tt{upper-o}})\index{ascii}\- \\ 
{\bf then }{\tt{8}} \\ 
{\bf else }{\tt{16}}$\;${\bf  endif}\-, \\ 
{\rm{cdr}}\,({\rm{cdr}}\,({\it{lst\/}})))\-\index{optionally-signed-base-n-digit-!sequence})\-\-
\end{tabbing}

\begin{tabbing}{\sc Definition}:\index{last} \\  
\=\+{\rm{last}}\,({\it{lst\/}})\index{last} \\ 
$=$$\;\;\;\;$\=\+{\bf if }{\it{lst\/}} $\simeq\;${{\bf{nil}}}${}$$\;\;${\bf then }{\it{lst\/}} \\ 
{\bf elseif }{\rm{cdr}}\,({\it{lst\/}}) $\simeq\;${{\bf{nil}}}${}$$\;\;${\bf then }{\it{lst\/}} \\ 
{\bf else }{\rm{last}}\,({\rm{cdr}}\,({\it{lst\/}}))\index{last}$\;${\bf  endif}\-\-
\end{tabbing}

\begin{tabbing}{\sc Definition}:\index{all-but-last} \\  
\=\+{\rm{all-but-last}}\,({\it{lst\/}})\index{all-but-last} \\ 
$=$$\;\;\;\;$\=\+{\bf if }{\it{lst\/}} $\simeq\;${{\bf{nil}}}${}$$\;\;${\bf then }{\bf{nil}} \\ 
{\bf elseif }{\rm{cdr}}\,({\it{lst\/}}) $\simeq\;${{\bf{nil}}}${}$$\;\;${\bf then }{\bf{nil}} \\ 
{\bf else }{\rm{cons}}\,({\rm{car}}\,({\it{lst\/}}), {\rm{all-but-last}}\,({\rm{cdr}}\,({\it{lst\/}}))\index{all-but-last})$\;${\bf  endif}\-\-
\end{tabbing}

\begin{tabbing}{\sc Definition}:\index{numeric-sequence} \\  
\=\+{\rm{numeric-sequence}}\,({\it{lst\/}})\index{numeric-sequence} \\ 
$=$$\;\;\;\;$(\=\+{\rm{optionally-signed-base-n-digit-sequence}}\,({\tt{10}}, {\it{lst\/}})\index{optionally-signed-base-n-digit-!sequence} \\ 
$\vee$$\;\;\;\;$(\=\+(\=\+({\rm{car}}\,({\rm{last}}\,({\it{lst\/}})\index{last}) $=$ {\rm{ascii}}\,({\tt{'}}{\tt{dot}})\index{ascii}) \\ 
$\wedge$$\;\;\;\;${\rm{optionally-signed-base-n-digit-sequence}}\,(\=\+{\tt{10}}, \\ 
{\rm{all-but-last}}\,({\it{lst\/}})\index{all-but-last})\-\index{optionally-signed-base-n-digit-!sequence})\- \\ 
$\vee$$\;\;\;\;${\rm{number-sign-sequence}}\,({\it{lst\/}})\index{number-sign-sequence})\-)\-\-
\end{tabbing}
	   
\begin{tabbing}{\sc Definition}:\index{numeric-value} \\  
\=\+{\rm{numeric-value}}\,({\it{lst\/}})\index{numeric-value} \\ 
$=$$\;\;\;\;$\=\+{\bf if }{\rm{optionally-signed-base-n-digit-sequence}}\,({\tt{10}}, {\it{lst\/}})\index{optionally-signed-base-n-digit-!sequence} \\ 
{\bf then }{\rm{base-n-signed-value}}\,({\tt{10}}, {\it{lst\/}})\index{base-n-signed-value} \\ 
{\bf elseif }{\rm{car}}\,({\rm{last}}\,({\it{lst\/}})\index{last}) $=$ {\rm{ascii}}\,({\tt{'}}{\tt{dot}})\index{ascii} \\ 
{\bf then }{\rm{base-n-signed-value}}\,({\tt{10}}, {\rm{all-but-last}}\,({\it{lst\/}})\index{all-but-last})\index{base-n-signed-value} \\ 
{\bf else }{\rm{base-n-signed-value}}\,(\=\+\=\+{\bf if }\=\+{\rm{cadrn}}\,({\tt{1}}, {\it{lst\/}})\index{cadrn} \\ 
$=$$\;\;\;\;${\rm{ascii}}\,({\tt{'}}{\tt{upper-b}})\index{ascii}\-$\;\;${\bf then }{\tt{2}} \\ 
{\bf elseif }\=\+{\rm{cadrn}}\,({\tt{1}}, {\it{lst\/}})\index{cadrn} \\ 
$=$$\;\;\;\;${\rm{ascii}}\,({\tt{'}}{\tt{upper-o}})\index{ascii}\- \\ 
{\bf then }{\tt{8}} \\ 
{\bf else }{\tt{16}}$\;${\bf  endif}\-, \\ 
{\rm{cdr}}\,({\rm{cdr}}\,({\it{lst\/}})))\-\index{base-n-signed-value}$\;${\bf  endif}\-\-
\end{tabbing}

\begin{tabbing}{\sc Definition}:\index{single-quote-token} \\  
{\sc{single-quote-token}}\index{single-quote-token} $=$ {\rm{pack}}\,({\rm{cons}}\,({\rm{ascii}}\,({\tt{'}}{\tt{single-quote}})\index{ascii}, {\tt{0}}))
\end{tabbing}
\begin{tabbing}{\sc Definition}:\index{backquote-token} \\  
{\sc{backquote-token}}\index{backquote-token} $=$ {\rm{pack}}\,({\rm{cons}}\,({\rm{ascii}}\,({\tt{'}}{\tt{backquote}})\index{ascii}, {\tt{0}}))
\end{tabbing}
\begin{tabbing}{\sc Definition}:\index{dot-token}$\;\;$
{\sc{dot-token}}\index{dot-token} $=$ {\rm{pack}}\,({\rm{cons}}\,({\rm{ascii}}\,({\tt{'}}{\tt{dot}})\index{ascii}, {\tt{0}}))
\end{tabbing}
\begin{tabbing}{\sc Definition}:\index{comma-token}$\;\;$
{\sc{comma-token}}\index{comma-token} $=$ {\rm{pack}}\,({\rm{cons}}\,({\rm{ascii}}\,({\tt{'}}{\tt{comma}})\index{ascii}, {\tt{0}}))
\end{tabbing}
\begin{tabbing}{\sc Definition}:\index{comma-at-sign-token} \\  
\=\+{\sc{comma-at-sign-token}}\index{comma-at-sign-token} \\ 
$=$$\;\;\;\;${\rm{pack}}\,({\rm{cons}}\,({\rm{ascii}}\,({\tt{'}}{\tt{comma}})\index{ascii}, {\rm{cons}}\,({\rm{ascii}}\,({\tt{'}}{\tt{at-sign}})\index{ascii}, {\tt{0}})))\-
\end{tabbing}
\begin{tabbing}{\sc Definition}:\index{comma-dot-token} \\  
{\sc{comma-dot-token}}\index{comma-dot-token} $=$ {\rm{pack}}\,({\rm{cons}}\,({\rm{ascii}}\,({\tt{'}}{\tt{comma}})\index{ascii}, {\rm{cons}}\,({\rm{ascii}}\,({\tt{'}}{\tt{dot}})\index{ascii}, {\tt{0}})))
\end{tabbing}

\begin{tabbing}{\sc Definition}:\index{word-characters} \\  
\=\+{\sc{word-characters}}\index{word-characters} \\ 
$=$$\;\;\;\;${\rm{ascii}}\,({\tt{'}}{\tt{(}}\=\+{\tt{upper-a}}{\tt{ }}{\tt{upper-b}}{\tt{ }}{\tt{upper-c}}{\tt{ }}{\tt{upper-d}}{\tt{ }}{\tt{upper-e}}{\tt{ }}{\tt{upper-f}} \\ 
{\tt{upper-g}}{\tt{ }}{\tt{upper-h}}{\tt{ }}{\tt{upper-i}}{\tt{ }}{\tt{upper-j}}{\tt{ }}{\tt{upper-k}}{\tt{ }}{\tt{upper-l}} \\ 
{\tt{upper-m}}{\tt{ }}{\tt{upper-n}}{\tt{ }}{\tt{upper-o}}{\tt{ }}{\tt{upper-p}}{\tt{ }}{\tt{upper-q}}{\tt{ }}{\tt{upper-r}} \\ 
{\tt{upper-s}}{\tt{ }}{\tt{upper-t}}{\tt{ }}{\tt{upper-u}}{\tt{ }}{\tt{upper-v}}{\tt{ }}{\tt{upper-w}}{\tt{ }}{\tt{upper-x}} \\ 
{\tt{upper-y}}{\tt{ }}{\tt{upper-z}}{\tt{ }}{\tt{digit-zero}}{\tt{ }}{\tt{digit-one}}{\tt{ }}{\tt{digit-two}} \\ 
{\tt{digit-three}}{\tt{ }}{\tt{digit-four}}{\tt{ }}{\tt{digit-five}}{\tt{ }}{\tt{digit-six}} \\ 
{\tt{digit-seven}}{\tt{ }}{\tt{digit-eight}}{\tt{ }}{\tt{digit-nine}}{\tt{ }}{\tt{dollar-sign}} \\ 
{\tt{uparrow}}{\tt{ }}{\tt{ampersand}}{\tt{ }}{\tt{asterisk}}{\tt{ }}{\tt{underscore}}{\tt{ }}{\tt{minus-sign}} \\ 
{\tt{plus-sign}}{\tt{ }}{\tt{equal-sign}}{\tt{ }}{\tt{tilde}}{\tt{ }}{\tt{open-brace}}{\tt{ }}{\tt{close-brace}} \\ 
{\tt{question-mark}}{\tt{ }}{\tt{less-than-sign}}{\tt{ }}{\tt{greater-than-sign}}{\tt{)}}\-)\index{ascii}\-
\end{tabbing}

\begin{tabbing}{\sc Definition}:\index{subsetp} \\  
\=\+{\rm{subsetp}}\,({\it{x\/}}, {\it{y\/}})\index{subsetp} \\ 
$=$$\;\;\;\;$\=\+{\bf if }{\it{x\/}} $\simeq\;${{\bf{nil}}}${}$$\;\;${\bf then }{\bf{t}} \\ 
{\bf elseif }{\rm{car}}\,({\it{x\/}}) $\in$ {\it{y\/}}$\;\;${\bf then }{\rm{subsetp}}\,({\rm{cdr}}\,({\it{x\/}}), {\it{y\/}})\index{subsetp} \\ 
{\bf else }{\bf{f}}$\;${\bf  endif}\-\-
\end{tabbing}

\begin{tabbing}{\sc Definition}:\index{word} \\  
\=\+{\rm{word}}\,({\it{s\/}})\index{word} \\ 
$=$$\;\;\;\;$(\=\+{\rm{litatom}}\,({\it{s\/}}) \\ 
$\wedge$$\;\;\;\;$(\=\+{\rm{numeric-sequence}}\,({\rm{unpack}}\,({\it{s\/}}))\index{numeric-sequence} \\ 
$\vee$$\;\;\;\;$(\=\+{\rm{listp}}\,({\rm{unpack}}\,({\it{s\/}})) \\ 
$\wedge$$\;\;\;\;${\rm{subsetp}}\,({\rm{unpack}}\,({\it{s\/}}), {\sc{word-characters}}\index{word-characters})\index{subsetp})\-)\-)\-\-
\end{tabbing}

\begin{verbatim}; It is convenient to be able to recognize those words that are
; numeric sequences and to talk about their numeric values, without
; having to think about unpacking them.  So we define NUMERIC-WORD
; and NUMERIC-WORD-VALUE and use them below where the text would
; have us use ``numeric sequence'' and ``numeric value.''

\end{verbatim}\begin{tabbing}{\sc Definition}:\index{numeric-word} \\  
{\rm{numeric-word}}\,({\it{s\/}})\index{numeric-word} $=$ ({\rm{litatom}}\,({\it{s\/}}) $\wedge$ {\rm{numeric-sequence}}\,({\rm{unpack}}\,({\it{s\/}}))\index{numeric-sequence})
\end{tabbing}

\begin{tabbing}{\sc Definition}:\index{numeric-word-value}$\;\;$
{\rm{numeric-word-value}}\,({\it{s\/}})\index{numeric-word-value} $=$ {\rm{numeric-value}}\,({\rm{unpack}}\,({\it{s\/}}))\index{numeric-value}
\end{tabbing}

\begin{tabbing}{\sc Definition}:\index{integerp}$\;\;$
{\rm{integerp}}\,({\it{x\/}})\index{integerp} $=$ (({\it{x\/}} $\in\;${\bf{N}}${}$) $\vee$ {\rm{negativep}}\,({\it{x\/}}))
\end{tabbing}

\begin{tabbing}{\sc Definition}:\index{special-token} \\  
\=\+{\rm{special-token}}\,({\it{x\/}})\index{special-token} \\ 
$=$$\;\;\;\;$(\=\+({\it{x\/}} $=$ {\sc{single-quote-token}}\index{single-quote-token}) \\ 
$\vee$$\;\;\;\;$(\=\+({\it{x\/}} $=$ {\sc{backquote-token}}\index{backquote-token}) \\ 
$\vee$$\;\;\;\;$(\=\+({\it{x\/}} $=$ {\sc{comma-token}}\index{comma-token}) \\ 
$\vee$$\;\;\;\;$(\=\+({\it{x\/}} $=$ {\sc{comma-at-sign-token}}\index{comma-at-sign-token}) \\ 
$\vee$$\;\;\;\;$({\it{x\/}} $=$ {\sc{comma-dot-token}}\index{comma-dot-token}))\-)\-)\-)\-\-
\end{tabbing}

\begin{verbatim}; The following function can be used as follows.  If we test
; (EQLEN X 3) then we know that lst is of the form (x1 x2 x3).

\end{verbatim}\begin{tabbing}{\sc Definition}:\index{eqlen} \\  
\=\+{\rm{eqlen}}\,({\it{lst\/}}, {\it{n\/}})\index{eqlen} \\ 
$=$$\;\;\;\;$\=\+{\bf if }{\it{n\/}} $\simeq {\tt{0}}$$\;\;${\bf then }{\it{lst\/}} $=$ {\bf{nil}} \\ 
{\bf elseif }{\it{lst\/}} $\simeq\;${{\bf{nil}}}${}$$\;\;${\bf then }{\bf{f}} \\ 
{\bf else }{\rm{eqlen}}\,({\rm{cdr}}\,({\it{lst\/}}), {\it{n\/}} $-\;1$)\index{eqlen}$\;${\bf  endif}\-\-
\end{tabbing}

\begin{tabbing}{\sc Definition}:\index{dotted-pair} \\  
{\rm{dotted-pair}}\,({\it{x\/}})\index{dotted-pair} $=$ ({\rm{eqlen}}\,({\it{x\/}}, {\tt{3}})\index{eqlen} $\wedge$ ({\rm{cadrn}}\,({\tt{1}}, {\it{x\/}})\index{cadrn} $=$ {\sc{dot-token}}\index{dot-token}))
\end{tabbing}

\begin{tabbing}{\sc Definition}:\index{dotted-s-expression} \\  
\=\+{\rm{dotted-s-expression}}\,({\it{x\/}})\index{dotted-s-expression} \\ 
$=$$\;\;\;\;$\=\+{\bf if }{\it{x\/}} $\simeq\;${{\bf{nil}}}${}$$\;\;${\bf then }{\bf{f}} \\ 
{\bf elseif }{\rm{dotted-pair}}\,({\it{x\/}})\index{dotted-pair}$\;\;${\bf then }{\bf{t}} \\ 
{\bf else }{\rm{dotted-s-expression}}\,({\rm{cdr}}\,({\it{x\/}}))\index{dotted-s-expression}$\;${\bf  endif}\-\-
\end{tabbing}

\begin{tabbing}{\sc Definition}:\index{singleton}$\;\;$
{\rm{singleton}}\,({\it{x\/}})\index{singleton} $=$ {\rm{eqlen}}\,({\it{x\/}}, {\tt{1}})\index{eqlen}
\end{tabbing}

\begin{verbatim}; We use the following lemma to make the CADRNs go away during the
; termination proof for TOKEN-TREE.

\end{verbatim}\begin{tabbing}{\sc Theorem}:  cdrn-expander \\ \index{cdrn-expander}
{\rm{cdrn}}\,($1\;+$ {\it{n\/}}, {\it{x\/}})\index{cdrn} $=$ {\rm{cdrn}}\,({\it{n\/}}, {\rm{cdr}}\,({\it{x\/}}))\index{cdrn}
\end{tabbing}

\begin{verbatim}; Now we define token trees formally.  We use the logic's LISTPs,
; together with the integers, words and tokens (the last two being
; LITATOMs), to represent token trees.  We are faithful to the
; text's style of representing dotted token trees by lists whose
; second-to-last elements are the dot token.  That is, we don't
; represent such trees by dotted pairs in the logic.  (This would
; not work because the token tree (A B . (C D E)) is legitimate and
; is different from (A B C D E).  The text permits such token trees
; since they may be typed.  They readmacro-expand to the same
; s-expression.)  However, we do not define ``token tree'' in quite
; the same style as the text, though the result is the same.  The
; text recognizes undotted and dotted token trees ``from the
; outside'' -- e.g., an undotted token tree is a nonempty sequence
; of token trees and a dotted one is similar but has a dot as its
; second-to-last element.  To define token trees formally this way
; we would need to use mutual recursion.  Rather than do that, we
; just recurse down dotted and undotted lists and catch the dot
; when we come to it.

\end{verbatim}\begin{tabbing}{\sc Definition}:\index{token-tree} \\  
\=\+{\rm{token-tree}}\,({\it{x\/}})\index{token-tree} \\ 
$=$$\;\;\;\;$\=\+{\bf if }{\it{x\/}} $\simeq\;${{\bf{nil}}}${}$$\;\;${\bf then }{\rm{integerp}}\,({\it{x\/}})\index{integerp} $\vee$ {\rm{word}}\,({\it{x\/}})\index{word} \\ 
{\bf elseif }{\rm{special-token}}\,({\rm{car}}\,({\it{x\/}}))\index{special-token} $\wedge$ ({\rm{length}}\,({\it{x\/}})\index{length} $=$ {\tt{2}}) \\ 
{\bf then }{\rm{token-tree}}\,({\rm{cadrn}}\,({\tt{1}}, {\it{x\/}})\index{cadrn})\index{token-tree} \\ 
{\bf elseif }{\rm{dotted-pair}}\,({\it{x\/}})\index{dotted-pair} \\ 
{\bf then }{\rm{token-tree}}\,({\rm{car}}\,({\it{x\/}}))\index{token-tree} $\wedge$ {\rm{token-tree}}\,({\rm{cadrn}}\,({\tt{2}}, {\it{x\/}})\index{cadrn})\index{token-tree} \\ 
{\bf elseif }{\rm{singleton}}\,({\it{x\/}})\index{singleton}$\;\;${\bf then }{\rm{token-tree}}\,({\rm{car}}\,({\it{x\/}}))\index{token-tree} \\ 
{\bf else }{\rm{token-tree}}\,({\rm{car}}\,({\it{x\/}}))\index{token-tree} $\wedge$ {\rm{token-tree}}\,({\rm{cdr}}\,({\it{x\/}}))\index{token-tree}$\;${\bf  endif}\-\-
\end{tabbing}

\begin{verbatim}; We define a few functions to make token tree manipulation and
; recognition easier.

\end{verbatim}\begin{tabbing}{\sc Definition}:\index{special-token-tree}$\;\;$
{\rm{special-token-tree}}\,({\it{x\/}})\index{special-token-tree} $=$ {\rm{special-token}}\,({\rm{car}}\,({\it{x\/}}))\index{special-token}
\end{tabbing}

\begin{tabbing}{\sc Definition}:\index{single-quote-token-tree} \\  
{\rm{single-quote-token-tree}}\,({\it{x\/}})\index{single-quote-token-tree} $=$ ({\rm{car}}\,({\it{x\/}}) $=$ {\sc{single-quote-token}}\index{single-quote-token})
\end{tabbing}

\begin{tabbing}{\sc Definition}:\index{backquote-token-tree} \\  
{\rm{backquote-token-tree}}\,({\it{x\/}})\index{backquote-token-tree} $=$ ({\rm{car}}\,({\it{x\/}}) $=$ {\sc{backquote-token}}\index{backquote-token})
\end{tabbing}

\begin{tabbing}{\sc Definition}:\index{comma-escape-token-tree} \\  
{\rm{comma-escape-token-tree}}\,({\it{x\/}})\index{comma-escape-token-tree} $=$ ({\rm{car}}\,({\it{x\/}}) $=$ {\sc{comma-token}}\index{comma-token})
\end{tabbing}

\begin{tabbing}{\sc Definition}:\index{splice-escape-token-tree} \\  
\=\+{\rm{splice-escape-token-tree}}\,({\it{x\/}})\index{splice-escape-token-tree} \\ 
$=$$\;\;\;\;$(({\rm{car}}\,({\it{x\/}}) $=$ {\sc{comma-at-sign-token}}\index{comma-at-sign-token}) $\vee$ ({\rm{car}}\,({\it{x\/}}) $=$ {\sc{comma-dot-token}}\index{comma-dot-token}))\-
\end{tabbing}

\begin{tabbing}{\sc Definition}:\index{constituent}$\;\;$
{\rm{constituent}}\,({\it{x\/}})\index{constituent} $=$ {\rm{cadrn}}\,({\tt{1}}, {\it{x\/}})\index{cadrn}
\end{tabbing}


\begin{verbatim}; SECTION:  Reading Token Trees

; At this point in the text, we define how to display a token tree.
; We will skip that here and instead formalize the process of pars-
; ing a token tree from a sequence of characters (i.e., from a dis-
; play of one).

; Our parser is reminiscent of Lisp's read routine with several im-
; portant exceptions.  We do not deal with readmacros in our parser
; -- that is the job of readmacro-expansion (defined later).  We
; also do not produce dotted pairs but rather lists containing the
; dot token.  Finally, we can produce ``unreadable'' token trees
; such as parsed from (PLUS ,X B).

; The parser is called READ-TOKEN-TREE and it is implemented in two
; passes.  The first pass transforms a list of ASCII character
; codes into a list of lexemes.  In our case, all the lexemes are
; LITATOMs, including the numeric sequences that look like inte-
; gers, i.e., we resolve the ambiguity in ``display'' by always
; using numeric sequences.  The second pass parses the lexemes into
; a tree.  In fact, the parser can produce trees that are not token
; trees, such as the one produced by parsing (PLUS # B).  This
; ``pseudo-token tree'' fails to be a token tree because one of the
; atoms in it that ``should'' be a word is not a word.  READ-TOKEN-
; TREE therefore calls the predicate TOKEN-TREE on the parsed tree
; to determine whether the parse was successful.


; SUBSECTION: Pass I of the Reader

; We give convenient names to the lexemes for open and close
; parentheses.  We could call these ``tokens'' but don't want to
; confuse them with the tokens of the text.  The lexemes for the
; tokens, e.g., the dot lexeme, will be the tokens themselves,
; e.g., the value of (DOT-TOKEN).

\end{verbatim}\begin{tabbing}{\sc Definition}:\index{open-paren}$\;\;$
{\sc{open-paren}}\index{open-paren} $=$ {\rm{pack}}\,({\rm{cons}}\,({\rm{ascii}}\,({\tt{'}}{\tt{open-paren}})\index{ascii}, {\tt{0}}))
\end{tabbing}
\begin{tabbing}{\sc Definition}:\index{close-paren}$\;\;$
{\sc{close-paren}}\index{close-paren} $=$ {\rm{pack}}\,({\rm{cons}}\,({\rm{ascii}}\,({\tt{'}}{\tt{close-paren}})\index{ascii}, {\tt{0}}))
\end{tabbing}

\begin{verbatim}; The following function scans past characters until it has passed
; the first newline character.  It is used to scan past semicolon
; comment.  It returns the stream starting just after that newline.
; If no newline is found, it returns the empty stream.  The ques-
; tion then arises: was the comment that started this scan well-
; formed or not?  It is missing its final newline.  It turns out
; that Common Lisp's answer to this is that it is ok.  That is, a
; file can end without there being a final newline on the end of a
; comment on the last line of the file.  The text of Chapter 4 does
; not deal with this issue.

\end{verbatim}\begin{tabbing}{\sc Definition}:\index{skip-past-newline} \\  
\=\+{\rm{skip-past-newline}}\,({\it{stream\/}})\index{skip-past-newline} \\ 
$=$$\;\;\;\;$\=\+{\bf if }{\it{stream\/}} $\simeq\;${{\bf{nil}}}${}$$\;\;${\bf then }{\it{stream\/}} \\ 
{\bf elseif }{\rm{car}}\,({\it{stream\/}}) $=$ {\rm{ascii}}\,({\tt{'}}{\tt{newline}})\index{ascii}$\;\;${\bf then }{\rm{cdr}}\,({\it{stream\/}}) \\ 
{\bf else }{\rm{skip-past-newline}}\,({\rm{cdr}}\,({\it{stream\/}}))\index{skip-past-newline}$\;${\bf  endif}\-\-
\end{tabbing}

\begin{verbatim}; The lexical analyzer will sometimes recurse using this function
; to ``decrement'' the input stream.  We must prove that the stream
; returned is weakly smaller (the semicolon that starts the
; comment will have already been stripped off by an explicit CDR).
; We measure size here with LENGTH instead of COUNT because COUNT
; doesn't decrease for all of the recursions (see the next function
; definition).

\end{verbatim}\begin{tabbing}{\sc Theorem}:  lessp-skip-past-newline \\ \index{lessp-skip-past-newline}
{\rm{length}}\,({\it{stream\/}})\index{length} $\not<$ {\rm{length}}\,({\rm{skip-past-newline}}\,({\it{stream\/}})\index{skip-past-newline})\index{length}
\end{tabbing}

\begin{verbatim}; The next function scans for the end of a just-opened #-comment.
; The function returns the stream just past the closing sequence of
; the comment.  The variable I below counts the number of ``open''
; #| sequences we have seen.  We do not stop until we see a |#
; sequence that closes that one, i.e., decrements I to 0.  I is
; initially 1 because we call this function after reading the
; opening sequence.  Note that this function will scan the entire
; input stream if the balancing sequence is not present.  This is
; treated as an error by Common Lisp.  We therefore have the
; problem of signalling this error.  If we return the empty stream,
; it is indistinguishable from a well-formed comment that ends at
; the very end of the stream.  We therefore use a trick: we return
; the stream containing a single open parenthesis character.  This
; character will cause the lexical analyzer to put an unbalanced
; open parenthesis lexeme as the last lexeme in the stream fed to
; the parser.  That, in turn, will cause an error.  We also signal
; such an error if we find too many |# sequences.  A minor tech-
; nical problem arises: to insure that the lexical analyzer can
; recurse with this skipping function, we have to make sure the
; size of the stream we return is less than the one the lexical
; analyzer started with.  Since the analyzer will have CDRd past
; the opening #| our adding a single open parenthesis in the place
; of those two characters will not matter -- if we measure the size
; of the stream with LENGTH!  If we were to measure with COUNT, we
; would have to worry about the size of the various ASCII codes and
; about the object in the final CDR of the stream.

\end{verbatim}\begin{tabbing}{\sc Definition}:\index{skip-past-balancing-vertical-ba!r-number-sign} \\  
\=\+{\rm{skip-past-balancing-vertical-bar-number-sign}}\,({\it{stream\/}}, {\it{i\/}})\index{skip-past-balancing-vertical-ba!r-number-sign} \\ 
$=$$\;\;\;\;$\=\+{\bf if }{\it{stream\/}} $\simeq\;${{\bf{nil}}}${}$$\;\;${\bf then }{\rm{cons}}\,({\rm{ascii}}\,({\tt{'}}{\tt{open-paren}})\index{ascii}, {\it{stream\/}}) \\ 
{\bf elseif }\=\+({\rm{car}}\,({\it{stream\/}}) $=$ {\rm{ascii}}\,({\tt{'}}{\tt{number-sign}})\index{ascii}) \\ 
$\wedge$$\;\;\;\;$({\rm{cadrn}}\,({\tt{1}}, {\it{stream\/}})\index{cadrn} $=$ {\rm{ascii}}\,({\tt{'}}{\tt{vertical-bar}})\index{ascii})\- \\ 
{\bf then }{\rm{skip-past-balancing-vertical-bar-number-sign}}\,(\=\+{\rm{cdrn}}\,({\tt{2}}, {\it{stream\/}})\index{cdrn}, \\ 
$1\;+$ {\it{i\/}})\-\index{skip-past-balancing-vertical-ba!r-number-sign} \\ 
{\bf elseif }\=\+({\rm{car}}\,({\it{stream\/}}) $=$ {\rm{ascii}}\,({\tt{'}}{\tt{vertical-bar}})\index{ascii}) \\ 
$\wedge$$\;\;\;\;$({\rm{cadrn}}\,({\tt{1}}, {\it{stream\/}})\index{cadrn} $=$ {\rm{ascii}}\,({\tt{'}}{\tt{number-sign}})\index{ascii})\- \\ 
{\bf then }\=\+{\bf if }{\it{i\/}} $=$ {\tt{0}}$\;\;${\bf then }{\rm{cons}}\,({\rm{ascii}}\,({\tt{'}}{\tt{open-paren}})\index{ascii}, {\rm{cdrn}}\,({\tt{2}}, {\it{stream\/}})\index{cdrn}) \\ 
{\bf elseif }{\it{i\/}} $=$ {\tt{1}}$\;\;${\bf then }{\rm{cdrn}}\,({\tt{2}}, {\it{stream\/}})\index{cdrn} \\ 
{\bf else }{\rm{skip-past-balancing-vertical-bar-number-sign}}\,(\=\+{\rm{cdrn}}\,(\=\+{\tt{2}}, \\ 
{\it{stream\/}})\-\index{cdrn}, \\ 
{\it{i\/}} $-\;1$)\-\index{skip-past-balancing-vertical-ba!r-number-sign}$\;${\bf  endif}\- \\ 
{\bf else }{\rm{skip-past-balancing-vertical-bar-number-sign}}\,({\rm{cdr}}\,({\it{stream\/}}), {\it{i\/}})\index{skip-past-balancing-vertical-ba!r-number-sign}$\;${\bf  endif}\-\-
\end{tabbing}

\begin{verbatim}; This is the key inductive fact about the relative LENGTHs of the
; input and output of the function above:

\end{verbatim}\begin{tabbing}{\sc Theorem}:  skip-past-balancing-vertical-bar-number-sign-lemma \\ \index{skip-past-balancing-vertical-ba!r-number-sign-lemma}
\=\+($1\;+$ {\rm{length}}\,({\it{stream\/}})\index{length}) \\ 
$\not<$$\;\;\;\;${\rm{length}}\,({\rm{skip-past-balancing-vertical-bar-number-sign}}\,({\it{stream\/}}, {\it{i\/}})\index{skip-past-balancing-vertical-ba!r-number-sign})\index{length}\-
\end{tabbing}

\begin{verbatim}; However, this is the actual theorem we need to admit the lexical
; analyzer (eventually) below:

\end{verbatim}\begin{tabbing}{\sc Theorem}:  lessp-skip-past-balancing-vertical-bar-number-sign \\ \index{lessp-skip-past-balancing-verti!cal-bar-number-sign}
\=\+(\=\+{\rm{listp}}\,({\it{stream\/}}) \\ 
$\wedge$$\;\;\;\;$(\=\+({\rm{car}}\,({\it{stream\/}}) $=$ {\rm{ascii}}\,({\tt{'}}{\tt{number-sign}})\index{ascii}) \\ 
$\wedge$$\;\;\;\;$({\rm{cadr}}\,({\it{stream\/}}) $=$ {\rm{ascii}}\,({\tt{'}}{\tt{vertical-bar}})\index{ascii}))\-)\- \\ 
$\rightarrow$$\;\;\;\;$(\=\+{\rm{length}}\,({\rm{skip-past-balancing-vertical-bar-number-sign}}\,({\rm{cddr}}\,({\it{stream\/}}), {\tt{1}})\index{skip-past-balancing-vertical-ba!r-number-sign})\index{length} \\ 
$<$$\;\;\;\;${\rm{length}}\,({\it{stream\/}})\index{length})\-\-
\end{tabbing}

\begin{verbatim}; To recognize white space we need:

\end{verbatim}\begin{tabbing}{\sc Definition}:\index{white-spacep} \\  
{\rm{white-spacep}}\,({\it{c\/}})\index{white-spacep} $=$ ({\it{c\/}} $\in$ {\rm{ascii}}\,({\tt{'}}{\tt{(}}{\tt{space}}{\tt{ }}{\tt{tab}}{\tt{ }}{\tt{newline}}{\tt{)}})\index{ascii})
\end{tabbing}

\begin{verbatim}; We will accumulate the characters in a lexeme in a list (with a 0
; at the bottom) and when we have a completed lexeme we will add it
; to a growing list of lexemes.  The characters are accumulated in
; reverse order.  The empty lexeme is never added to the list.

\end{verbatim}\begin{tabbing}{\sc Definition}:\index{rev1} \\  
\=\+{\rm{rev1}}\,({\it{lst\/}}, {\it{ans\/}})\index{rev1} \\ 
$=$$\;\;\;\;$\=\+{\bf if }{\it{lst\/}} $\simeq\;${{\bf{nil}}}${}$$\;\;${\bf then }{\it{ans\/}} \\ 
{\bf else }{\rm{rev1}}\,({\rm{cdr}}\,({\it{lst\/}}), {\rm{cons}}\,({\rm{car}}\,({\it{lst\/}}), {\it{ans\/}}))\index{rev1}$\;${\bf  endif}\-\-
\end{tabbing}

\begin{tabbing}{\sc Definition}:\index{emit} \\  
\=\+{\rm{emit}}\,({\it{pname\/}}, {\it{lst\/}})\index{emit} \\ 
$=$$\;\;\;\;$\=\+{\bf if }{\it{pname\/}} $=$ {\tt{0}}$\;\;${\bf then }{\it{lst\/}} \\ 
{\bf else }{\rm{cons}}\,({\rm{pack}}\,({\rm{rev1}}\,({\it{pname\/}}, {\tt{0}})\index{rev1}), {\it{lst\/}})$\;${\bf  endif}\-\-
\end{tabbing}

\begin{verbatim}; The following function maps lower case alphabetic characters into
; their upper case counterparts.  Thus, (UPCASE (ASCII 'LOWER-A))
; is (ASCII 'UPPER-A), etc.  UPCASE is the identity function on
; characters other than LOWER-A through LOWER-Z.

\end{verbatim}\begin{tabbing}{\sc Definition}:\index{upcase} \\  
\=\+{\rm{upcase}}\,({\it{c\/}})\index{upcase} \\ 
$=$$\;\;\;\;$\=\+{\bf if }({\rm{ascii}}\,({\tt{'}}{\tt{lower-a}})\index{ascii} $\leq$ {\it{c\/}}) $\wedge$ ({\it{c\/}} $\leq$ {\rm{ascii}}\,({\tt{'}}{\tt{lower-z}})\index{ascii}) \\ 
{\bf then }{\it{c\/}} $-$ ({\rm{ascii}}\,({\tt{'}}{\tt{lower-a}})\index{ascii} $-$ {\rm{ascii}}\,({\tt{'}}{\tt{upper-a}})\index{ascii}) \\ 
{\bf else }{\it{c\/}}$\;${\bf  endif}\-\-
\end{tabbing}

\begin{verbatim}; Here then is the lexical analyzer, pass I of the parser.  The
; function returns a list of lexemes parsed from stream, which is a
; list of ASCII codes.  PNAME is the lexeme currently being
; assembled.  It is 0 when ``empty.''

\end{verbatim}\begin{tabbing}{\sc Definition}:\index{lexemes} \\  
\=\+{\rm{lexemes}}\,({\it{stream\/}}, {\it{pname\/}})\index{lexemes} \\ 
$=$$\;\;\;\;$\=\+{\bf if }{\it{stream\/}} $\simeq\;${{\bf{nil}}}${}$$\;\;${\bf then }{\rm{emit}}\,({\it{pname\/}}, {\bf{nil}})\index{emit} \\ 
{\bf elseif }{\rm{car}}\,({\it{stream\/}}) $=$ {\rm{ascii}}\,({\tt{'}}{\tt{semicolon}})\index{ascii} \\ 
{\bf then }{\rm{emit}}\,({\it{pname\/}}, {\rm{lexemes}}\,({\rm{skip-past-newline}}\,({\rm{cdr}}\,({\it{stream\/}}))\index{skip-past-newline}, {\tt{0}})\index{lexemes})\index{emit} \\ 
{\bf elseif }\=\+{\rm{car}}\,({\it{stream\/}}) \\ 
$\in$$\;\;\;\;${\rm{ascii}}\,({\tt{'}}{\tt{(}}\=\+{\tt{backquote}}{\tt{ }}{\tt{single-quote}}{\tt{ }}{\tt{open-paren}} \\ 
{\tt{close-paren}}{\tt{)}}\-)\index{ascii}\- \\ 
{\bf then }{\rm{emit}}\,({\it{pname\/}}, {\rm{emit}}\,({\rm{cons}}\,({\rm{car}}\,({\it{stream\/}}), {\tt{0}}), {\rm{lexemes}}\,({\rm{cdr}}\,({\it{stream\/}}), {\tt{0}})\index{lexemes})\index{emit})\index{emit} \\ 
{\bf elseif }{\rm{car}}\,({\it{stream\/}}) $=$ {\rm{ascii}}\,({\tt{'}}{\tt{comma}})\index{ascii} \\ 
{\bf then }\=\+{\bf if }\=\+({\rm{cadrn}}\,({\tt{1}}, {\it{stream\/}})\index{cadrn} $=$ {\rm{ascii}}\,({\tt{'}}{\tt{at-sign}})\index{ascii}) \\ 
$\vee$$\;\;\;\;$({\rm{cadrn}}\,({\tt{1}}, {\it{stream\/}})\index{cadrn} $=$ {\rm{ascii}}\,({\tt{'}}{\tt{dot}})\index{ascii})\- \\ 
{\bf then }{\rm{emit}}\,(\=\+{\it{pname\/}}, \\ 
{\rm{emit}}\,(\=\+{\rm{cons}}\,({\rm{cadrn}}\,({\tt{1}}, {\it{stream\/}})\index{cadrn}, {\rm{cons}}\,({\rm{car}}\,({\it{stream\/}}), {\tt{0}})), \\ 
{\rm{lexemes}}\,({\rm{cdr}}\,({\rm{cdr}}\,({\it{stream\/}})), {\tt{0}})\index{lexemes})\-\index{emit})\-\index{emit} \\ 
{\bf else }{\rm{emit}}\,(\=\+{\it{pname\/}}, \\ 
{\rm{emit}}\,({\rm{cons}}\,({\rm{car}}\,({\it{stream\/}}), {\tt{0}}), {\rm{lexemes}}\,({\rm{cdr}}\,({\it{stream\/}}), {\tt{0}})\index{lexemes})\index{emit})\-\index{emit}$\;${\bf  endif}\- \\ 
{\bf elseif }{\rm{white-spacep}}\,({\rm{car}}\,({\it{stream\/}}))\index{white-spacep} \\ 
{\bf then }{\rm{emit}}\,({\it{pname\/}}, {\rm{lexemes}}\,({\rm{cdr}}\,({\it{stream\/}}), {\tt{0}})\index{lexemes})\index{emit} \\ 
{\bf elseif }\=\+({\it{pname\/}} $=$ {\tt{0}}) \\ 
$\wedge$$\;\;\;\;$(\=\+({\rm{car}}\,({\it{stream\/}}) $=$ {\rm{ascii}}\,({\tt{'}}{\tt{number-sign}})\index{ascii}) \\ 
$\wedge$$\;\;\;\;$({\rm{cadrn}}\,({\tt{1}}, {\it{stream\/}})\index{cadrn} $=$ {\rm{ascii}}\,({\tt{'}}{\tt{vertical-bar}})\index{ascii}))\-\- \\ 
{\bf then }{\rm{lexemes}}\,(\=\+{\rm{skip-past-balancing-vertical-bar-number-sign}}\,(\=\+{\rm{cdrn}}\,(\=\+{\tt{2}}, \\ 
{\it{stream\/}})\-\index{cdrn}, \\ 
{\tt{1}})\-\index{skip-past-balancing-vertical-ba!r-number-sign}, \\ 
{\tt{0}})\-\index{lexemes} \\ 
{\bf else }{\rm{lexemes}}\,({\rm{cdr}}\,({\it{stream\/}}), {\rm{cons}}\,({\rm{upcase}}\,({\rm{car}}\,({\it{stream\/}}))\index{upcase}, {\it{pname\/}}))\index{lexemes}$\;${\bf  endif}\-\-
\end{tabbing}

\begin{verbatim}; SUBSECTION:  Pass II of the Reader

; We now develop the parser, which maps a list of lexemes into a
; tree -- or returns F if the list does not parse.  One example of
; a list of lexemes that doesn't parse is one containing unbalanced
; parentheses.  Another example is one that contains more lexemes
; than necessary to describe exactly one tree.  That is, our parser
; balks if there are lexemes left over when one tree has been
; parsed.

; The formalization below is just a simple push-down stack auto-
; maton.  It scans the lexemes one at a time from the right all the
; way to the end of the list.  It has a stack of trees it is build-
; ing up.  When it sees an open parenthesis, it pushes an empty
; frame onto the stack.  When it sees a normal lexeme, like the
; word PLUS or the integer 123, it accumulates this onto the right
; end of the top-most frame.  When it sees a close parenthesis, it
; pops the top frame and accumulates it onto the right end of the
; frame below.  We code it so that if any of these stack operations
; is ill-formed, e.g., we pop an empty stack, the result is F.
; Furthermore, we arrange for an F stack to be propagated, i.e.,
; pushing something onto F produces F.  Thus, if a parsing error
; arises early in the scan of the lexemes, e.g., an unbalanced
; close parenthesis is seen, the stack becomes F and even though
; the scan continues until the last lexeme has been processed, the
; F is preserved as the signal that an error occurred.

; When all the lexemes have been processed we inspect the stack and
; verify that it contains a single frame.  If not, then we return
; F.  (If the stack contains less than one frame, then the stack is
; in fact F and an error was detected earlier.  If the stack
; contains more than one frame, we have unbalanced open paren-
; theses.)

; To make this work we have to start the stack as though we are
; accumulating a list, i.e., with one empty frame on the stack.
; Then when we are done we have to check that the list we accumu- 
; lated has exactly one element.  If it has none, the input was
; empty, which is an error.  If it has more than one, the input
; contained more than one tree and that is an error.

; To handle the special tokens single-quote, backquote, comma,
; comma-at-sign, and comma-dot, we generalize the stack slightly so
; that when these tokens are read they push a new frame that con-
; tains the token rather than the empty list.  Then we continue
; parsing.  When the next tree is assembled it is ``accumulated
; onto the right end of the frame below,'' where we actually take
; into account the special tokens that might mark the frame below.
; For example, if x is to be accumulated onto the frame below, and
; the frame below contains the single-quote token, then we create
; the single-quote tree (' x) and recursively accumulate it onto
; the frame below that.

; Finally, the dot token is afforded no such special handling
; except that when a list is accumulated onto another (or returned
; as the answer) we verify that if it contains the dot token as an
; element then the token occurs as the next-to-last element.

; Of course, this whole process is much simpler than the Lisp
; reader because we are not implementing readmacros here, nor do we
; have to do the checks for ``readability.''  We just parse a tree
; and return it for the rest of this system to inspect.

; So here are the functions implementing our stacks

\end{verbatim}\begin{tabbing}{\sc Definition}:\index{top-pstk} \\  
\=\+{\rm{top-pstk}}\,({\it{stack\/}})\index{top-pstk} \\ 
$=$$\;\;\;\;$\=\+{\bf if }{\rm{listp}}\,({\it{stack\/}})$\;\;${\bf then }{\rm{car}}\,({\it{stack\/}}) \\ 
{\bf else }{\bf{f}}$\;${\bf  endif}\-\-
\end{tabbing}
\begin{tabbing}{\sc Definition}:\index{pop-pstk} \\  
\=\+{\rm{pop-pstk}}\,({\it{stack\/}})\index{pop-pstk} \\ 
$=$$\;\;\;\;$\=\+{\bf if }{\rm{listp}}\,({\it{stack\/}})$\;\;${\bf then }{\rm{cdr}}\,({\it{stack\/}}) \\ 
{\bf else }{\bf{f}}$\;${\bf  endif}\-\-
\end{tabbing}
\begin{tabbing}{\sc Definition}:\index{push-pstk} \\  
\=\+{\rm{push-pstk}}\,({\it{x\/}}, {\it{stack\/}})\index{push-pstk} \\ 
$=$$\;\;\;\;$\=\+{\bf if }{\it{stack\/}} $=$ {\bf{f}}$\;\;${\bf then }{\bf{f}} \\ 
{\bf else }{\rm{cons}}\,({\it{x\/}}, {\it{stack\/}})$\;${\bf  endif}\-\-
\end{tabbing}
\begin{tabbing}{\sc Definition}:\index{empty-pstk}$\;\;$
{\rm{empty-pstk}}\,({\it{x\/}})\index{empty-pstk} $=$ ({\it{x\/}} $\simeq\;${{\bf{nil}}}${}$)
\end{tabbing}

\begin{verbatim}; Here is the predicate that verifies that a dotted tree is prop-
; erly formed.  We permit x to be the dot token, even though that
; is not a token tree, so that it can be accumulated just like
; other atoms.  We will filter out the isolated dot at the top.  So
; what we want to check here is that if X is a list and the dot
; token appears as an element then it appears in the next-to-last
; position and there is at least one element before it.  The vari-
; able I below just counts the number of elements we've scanned
; past.

\end{verbatim}\begin{tabbing}{\sc Definition}:\index{dot-criterion} \\  
\=\+{\rm{dot-criterion}}\,({\it{i\/}}, {\it{x\/}})\index{dot-criterion} \\ 
$=$$\;\;\;\;$\=\+{\bf if }{\it{x\/}} $\simeq\;${{\bf{nil}}}${}$$\;\;${\bf then }{\bf{t}} \\ 
{\bf elseif }{\rm{car}}\,({\it{x\/}}) $=$ {\sc{dot-token}}\index{dot-token} \\ 
{\bf then }({\it{i\/}} $\not\simeq {\tt{0}}$) $\wedge$ ({\rm{listp}}\,({\rm{cdr}}\,({\it{x\/}})) $\wedge$ ({\rm{cdr}}\,({\rm{cdr}}\,({\it{x\/}})) $\simeq\;${{\bf{nil}}}${}$)) \\ 
{\bf else }{\rm{dot-criterion}}\,($1\;+$ {\it{i\/}}, {\rm{cdr}}\,({\it{x\/}}))\index{dot-criterion}$\;${\bf  endif}\-\-
\end{tabbing}

\begin{verbatim}; Here is how we accumulate X ``onto the frame below,'' where the
; ``frame below'' is the top of the stack passed into this func-
; tion.  We check first that X satisfies the dot token criterion
; and cause an error if it doesn't.  Then we handle the special
; tokens.

\end{verbatim}\begin{tabbing}{\sc Definition}:\index{add-element-to-top} \\  
\=\+{\rm{add-element-to-top}}\,({\it{x\/}}, {\it{stack\/}})\index{add-element-to-top} \\ 
$=$$\;\;\;\;$\=\+{\bf if }{\rm{empty-pstk}}\,({\it{stack\/}})\index{empty-pstk}$\;\;${\bf then }{\bf{f}} \\ 
{\bf elseif }$\neg$ {\rm{dot-criterion}}\,({\tt{0}}, {\it{x\/}})\index{dot-criterion}$\;\;${\bf then }{\bf{f}} \\ 
{\bf elseif }{\rm{special-token}}\,({\rm{top-pstk}}\,({\it{stack\/}})\index{top-pstk})\index{special-token} \\ 
{\bf then }{\rm{add-element-to-top}}\,({\rm{list2}}\,({\rm{top-pstk}}\,({\it{stack\/}})\index{top-pstk}, {\it{x\/}})\index{list2}, {\rm{pop-pstk}}\,({\it{stack\/}})\index{pop-pstk})\index{add-element-to-top} \\ 
{\bf else }{\rm{push-pstk}}\,({\rm{append}}\,({\rm{top-pstk}}\,({\it{stack\/}})\index{top-pstk}, {\rm{list1}}\,({\it{x\/}})\index{list1}), {\rm{pop-pstk}}\,({\it{stack\/}})\index{pop-pstk})\index{push-pstk}$\;${\bf  endif}\-\-
\end{tabbing}

\begin{verbatim}; When we are all done, the following function is used to verify
; that exactly one whole object was constructed and that it is not
; an isolated dot-token.

\end{verbatim}\begin{tabbing}{\sc Definition}:\index{stop} \\  
\=\+{\rm{stop}}\,({\it{stack\/}})\index{stop} \\ 
$=$$\;\;\;\;$\=\+{\bf if }\=\+{\rm{eqlen}}\,({\it{stack\/}}, {\tt{1}})\index{eqlen} \\ 
$\wedge$$\;\;\;\;$(\=\+{\rm{eqlen}}\,({\rm{top-pstk}}\,({\it{stack\/}})\index{top-pstk}, {\tt{1}})\index{eqlen} \\ 
$\wedge$$\;\;\;\;$({\rm{car}}\,({\rm{top-pstk}}\,({\it{stack\/}})\index{top-pstk}) $\not=$ {\sc{dot-token}}\index{dot-token}))\-\- \\ 
{\bf then }{\rm{car}}\,({\rm{top-pstk}}\,({\it{stack\/}})\index{top-pstk}) \\ 
{\bf else }{\bf{f}}$\;${\bf  endif}\-\-
\end{tabbing}

\begin{verbatim}; Finally, here is the parser.  The proper top-level call of this
; function is (PARSE lexemes (CONS NIL NIL)).  It returns either a
; tree or F.  F indicates that the lexemes either did not parse in-
; to a complete tree or parsed into more than one.  The tree may be
; ``unreadable.''

\end{verbatim}\begin{tabbing}{\sc Definition}:\index{parse} \\  
\=\+{\rm{parse}}\,({\it{lexemes\/}}, {\it{stack\/}})\index{parse} \\ 
$=$$\;\;\;\;$\=\+{\bf if }{\it{lexemes\/}} $\simeq\;${{\bf{nil}}}${}$$\;\;${\bf then }{\rm{stop}}\,({\it{stack\/}})\index{stop} \\ 
{\bf elseif }{\rm{car}}\,({\it{lexemes\/}}) $=$ {\sc{open-paren}}\index{open-paren} \\ 
{\bf then }{\rm{parse}}\,({\rm{cdr}}\,({\it{lexemes\/}}), {\rm{push-pstk}}\,({\bf{nil}}, {\it{stack\/}})\index{push-pstk})\index{parse} \\ 
{\bf elseif }{\rm{special-token}}\,({\rm{car}}\,({\it{lexemes\/}}))\index{special-token} \\ 
{\bf then }{\rm{parse}}\,({\rm{cdr}}\,({\it{lexemes\/}}), {\rm{push-pstk}}\,({\rm{car}}\,({\it{lexemes\/}}), {\it{stack\/}})\index{push-pstk})\index{parse} \\ 
{\bf elseif }{\rm{car}}\,({\it{lexemes\/}}) $=$ {\sc{close-paren}}\index{close-paren} \\ 
{\bf then }{\rm{parse}}\,(\=\+{\rm{cdr}}\,({\it{lexemes\/}}), \\ 
{\rm{add-element-to-top}}\,({\rm{top-pstk}}\,({\it{stack\/}})\index{top-pstk}, {\rm{pop-pstk}}\,({\it{stack\/}})\index{pop-pstk})\index{add-element-to-top})\-\index{parse} \\ 
{\bf else }{\rm{parse}}\,({\rm{cdr}}\,({\it{lexemes\/}}), {\rm{add-element-to-top}}\,({\rm{car}}\,({\it{lexemes\/}}), {\it{stack\/}})\index{add-element-to-top})\index{parse}$\;${\bf  endif}\-\-
\end{tabbing}


\begin{verbatim}; SUBSECTION:  Putting the Two Passes Together

; As noted, the parser may not produce a token tree because the
; lexical analyzer can produce non-word, non-token lexemes.  For
; example, the stream (ASCII '(SPACE NUMBER-SIGN SPACE)) parses as
; the ``word'' we might display as # and which is logically repre-
; sented by the literal atom (PACK (CONS 35 0)).  But this is not a
; word, technically, because the number sign character is not among
; the word characters.  Therefore, after we have parsed the lexemes
; we check that the result is a token tree and return F if it is
; not.  Thus, this function may return F because
; (a) the lexical analyzer found fault with the character stream
;     (e.g., an unbalanced #-comment)
; (b) the parser found fault with the lexeme stream (e.g., an un-
;     balanced open parenthesis), or
; (c) the final tree failed to be a token tree.

\end{verbatim}\begin{tabbing}{\sc Definition}:\index{read-token-tree} \\  
\=\+{\rm{read-token-tree}}\,({\it{stream\/}})\index{read-token-tree} \\ 
$=$$\;\;\;\;$\=\+{\bf if }{\rm{token-tree}}\,({\rm{parse}}\,({\rm{lexemes}}\,({\it{stream\/}}, {\tt{0}})\index{lexemes}, {\rm{cons}}\,({\bf{nil}}, {\bf{nil}}))\index{parse})\index{token-tree} \\ 
{\bf then }{\rm{parse}}\,({\rm{lexemes}}\,({\it{stream\/}}, {\tt{0}})\index{lexemes}, {\rm{cons}}\,({\bf{nil}}, {\bf{nil}}))\index{parse} \\ 
{\bf else }{\bf{f}}$\;${\bf  endif}\-\-
\end{tabbing}

\begin{verbatim}; SECTION:  Readable Token Trees and S-Expressions

; We now resume our formalization of the text.  The definition of
; ``readable from depth'' N assumes X is a token tree or F.  We
; allow F as a possible input only because that is the error signal
; presented by READ-TOKEN-TREE.  F is not a token tree -- the only
; atomic token trees are integers and words.  Our formalization of
; ``readable'' announces that F is not readable, passing the
; ``error'' up.

\end{verbatim}\begin{tabbing}{\sc Definition}:\index{readable} \\  
\=\+{\rm{readable}}\,({\it{x\/}}, {\it{n\/}})\index{readable} \\ 
$=$$\;\;\;\;$\=\+{\bf if }{\it{x\/}} $\simeq\;${{\bf{nil}}}${}$$\;\;${\bf then }{\it{x\/}} $\not=$ {\bf{f}} \\ 
{\bf elseif }{\rm{single-quote-token-tree}}\,({\it{x\/}})\index{single-quote-token-tree}$\;\;${\bf then }{\rm{readable}}\,({\rm{constituent}}\,({\it{x\/}})\index{constituent}, {\it{n\/}})\index{readable} \\ 
{\bf elseif }{\rm{backquote-token-tree}}\,({\it{x\/}})\index{backquote-token-tree} \\ 
{\bf then }\=\+{\rm{readable}}\,({\rm{constituent}}\,({\it{x\/}})\index{constituent}, $1\;+$ {\it{n\/}})\index{readable} \\ 
$\wedge$$\;\;\;\;$($\neg$ {\rm{splice-escape-token-tree}}\,({\rm{constituent}}\,({\it{x\/}})\index{constituent})\index{splice-escape-token-tree})\- \\ 
{\bf elseif }{\rm{comma-escape-token-tree}}\,({\it{x\/}})\index{comma-escape-token-tree} $\vee$ {\rm{splice-escape-token-tree}}\,({\it{x\/}})\index{splice-escape-token-tree} \\ 
{\bf then }({\tt{0}} $<$ {\it{n\/}}) $\wedge$ {\rm{readable}}\,({\rm{constituent}}\,({\it{x\/}})\index{constituent}, {\it{n\/}} $-\;1$)\index{readable} \\ 
{\bf elseif }{\rm{dotted-pair}}\,({\it{x\/}})\index{dotted-pair} \\ 
{\bf then }\=\+{\rm{readable}}\,({\rm{car}}\,({\it{x\/}}), {\it{n\/}})\index{readable} \\ 
$\wedge$$\;\;\;\;$(\=\+{\rm{readable}}\,({\rm{cadrn}}\,({\tt{2}}, {\it{x\/}})\index{cadrn}, {\it{n\/}})\index{readable} \\ 
$\wedge$$\;\;\;\;$($\neg$ {\rm{splice-escape-token-tree}}\,({\rm{cadrn}}\,({\tt{2}}, {\it{x\/}})\index{cadrn})\index{splice-escape-token-tree}))\-\- \\ 
{\bf elseif }{\rm{singleton}}\,({\it{x\/}})\index{singleton}$\;\;${\bf then }{\rm{readable}}\,({\rm{car}}\,({\it{x\/}}), {\it{n\/}})\index{readable} \\ 
{\bf else }{\rm{readable}}\,({\rm{car}}\,({\it{x\/}}), {\it{n\/}})\index{readable} $\wedge$ {\rm{readable}}\,({\rm{cdr}}\,({\it{x\/}}), {\it{n\/}})\index{readable}$\;${\bf  endif}\-\-
\end{tabbing}

\begin{verbatim}; Like our formalization of ``readable,'' our formalization of ``s-
; expression'' allows its argument to be either a token tree or F
; and returns F on F.  Thus, if you apply S-EXPRESSION to the out-
; put of READ-TOKEN-TREE you will get F if the read ``caused an
; error.''  In actual use, we only apply S-EXPRESSION to the output
; of READMACRO-EXPANSION and we only apply that to READABLE token
; trees.  Thus, this aspect of our formalization of s-expressions
; is irrelevant.  We preserve it because it is sometimes nice,
; while testing these definitions, to run S-EXPRESSION on the
; output of the reader.

\end{verbatim}\begin{tabbing}{\sc Definition}:\index{s-expression} \\  
\=\+{\rm{s-expression}}\,({\it{x\/}})\index{s-expression} \\ 
$=$$\;\;\;\;$\=\+{\bf if }{\it{x\/}} $\simeq\;${{\bf{nil}}}${}$ \\ 
{\bf then }\=\+{\bf if }{\it{x\/}} $=$ {\bf{f}}$\;\;${\bf then }{\bf{f}} \\ 
{\bf else }$\neg$ {\rm{numeric-word}}\,({\it{x\/}})\index{numeric-word}$\;${\bf  endif}\- \\ 
{\bf elseif }{\rm{special-token-tree}}\,({\it{x\/}})\index{special-token-tree}$\;\;${\bf then }{\bf{f}} \\ 
{\bf elseif }{\rm{dotted-pair}}\,({\it{x\/}})\index{dotted-pair} \\ 
{\bf then }{\rm{s-expression}}\,({\rm{car}}\,({\it{x\/}}))\index{s-expression} $\wedge$ {\rm{s-expression}}\,({\rm{cadrn}}\,({\tt{2}}, {\it{x\/}})\index{cadrn})\index{s-expression} \\ 
{\bf elseif }{\rm{singleton}}\,({\it{x\/}})\index{singleton}$\;\;${\bf then }{\rm{s-expression}}\,({\rm{car}}\,({\it{x\/}}))\index{s-expression} \\ 
{\bf else }{\rm{s-expression}}\,({\rm{car}}\,({\it{x\/}}))\index{s-expression} $\wedge$ {\rm{s-expression}}\,({\rm{cdr}}\,({\it{x\/}}))\index{s-expression}$\;${\bf  endif}\-\-
\end{tabbing}


\begin{verbatim}; SECTION:  Backquote Expansion

; At this point in the text we give the definition of readmacro-
; expansion.  However, it is presented without first defining the
; notion of backquote expansion.  We therefore skip ahead in the
; text and formalize backquote expansion now so we can then present
; readmacro-expansion.

; Of course, backquote expansion and backquote-list expansion are
; mutually recursive.  If FLG below is T we are defining backquote
; expansion.  Otherwise, we are defining backquote-list expansion.

\end{verbatim}\begin{tabbing}{\sc Definition}:\index{backquote-expansion} \\  
\=\+{\rm{backquote-expansion}}\,({\it{flg\/}}, {\it{x\/}})\index{backquote-expansion} \\ 
$=$$\;\;\;\;$\=\+{\bf if }{\it{flg\/}} \\ 
{\bf then }\=\+{\bf if }{\it{x\/}} $\simeq\;${{\bf{nil}}}${}$$\;\;${\bf then }{\rm{list2}}\,({\tt{'}}{\tt{quote}}, {\it{x\/}})\index{list2} \\ 
{\bf elseif }\=\+{\rm{comma-escape-token-tree}}\,({\it{x\/}})\index{comma-escape-token-tree} \\ 
$\vee$$\;\;\;\;${\rm{splice-escape-token-tree}}\,({\it{x\/}})\index{splice-escape-token-tree}\-$\;\;${\bf then }{\rm{constituent}}\,({\it{x\/}})\index{constituent} \\ 
{\bf else }{\rm{backquote-expansion}}\,({\bf{f}}, {\it{x\/}})\index{backquote-expansion}$\;${\bf  endif}\- \\ 
{\bf elseif }{\it{x\/}} $\simeq\;${{\bf{nil}}}${}$ \\ 
{\bf then }{\tt{'}}{\tt{impossible-if-x-is-a-dotted-or-undotted-token-tree}} \\ 
{\bf else }{\rm{list3}}\,(\=\+\=\+{\bf if }{\rm{splice-escape-token-tree}}\,({\rm{car}}\,({\it{x\/}}))\index{splice-escape-token-tree}$\;\;${\bf then }{\tt{'}}{\tt{append}} \\ 
{\bf else }{\tt{'}}{\tt{cons}}$\;${\bf  endif}\-, \\ 
{\rm{backquote-expansion}}\,({\bf{t}}, {\rm{car}}\,({\it{x\/}}))\index{backquote-expansion}, \\ 
\=\+{\bf if }{\rm{singleton}}\,({\it{x\/}})\index{singleton}$\;\;${\bf then }{\rm{list2}}\,({\tt{'}}{\tt{quote}}, {\tt{'}}{\tt{nil}})\index{list2} \\ 
{\bf elseif }{\rm{dotted-pair}}\,({\it{x\/}})\index{dotted-pair} \\ 
{\bf then }{\rm{backquote-expansion}}\,({\bf{t}}, {\rm{cadrn}}\,({\tt{2}}, {\it{x\/}})\index{cadrn})\index{backquote-expansion} \\ 
{\bf else }{\rm{backquote-expansion}}\,({\bf{f}}, {\rm{cdr}}\,({\it{x\/}}))\index{backquote-expansion}$\;${\bf  endif}\-)\-\index{list3}$\;${\bf  endif}\-\-
\end{tabbing}


\begin{verbatim}; SECTION:  Readmacro Expansion

; Our definition of readmacro-expansion differs from the text in
; that we do all four passes at once.  It is so easy in English to
; say ``replace every ...'' and its formalization requires a recur-
; sive sweep through the tree.  Even if we had higher order func-
; tions (or used V&C$) we would spend about as much space defining
; the generic sweep as we do below just doing it.

\end{verbatim}\begin{tabbing}{\sc Definition}:\index{readmacro-expansion} \\  
\=\+{\rm{readmacro-expansion}}\,({\it{x\/}})\index{readmacro-expansion} \\ 
$=$$\;\;\;\;$\=\+{\bf if }{\it{x\/}} $\simeq\;${{\bf{nil}}}${}$ \\ 
{\bf then }\=\+{\bf if }{\rm{numeric-word}}\,({\it{x\/}})\index{numeric-word}$\;\;${\bf then }{\rm{numeric-word-value}}\,({\it{x\/}})\index{numeric-word-value} \\ 
{\bf else }{\it{x\/}}$\;${\bf  endif}\- \\ 
{\bf elseif }{\rm{single-quote-token-tree}}\,({\it{x\/}})\index{single-quote-token-tree} \\ 
{\bf then }{\rm{list2}}\,({\tt{'}}{\tt{quote}}, {\rm{readmacro-expansion}}\,({\rm{constituent}}\,({\it{x\/}})\index{constituent})\index{readmacro-expansion})\index{list2} \\ 
{\bf elseif }{\rm{backquote-token-tree}}\,({\it{x\/}})\index{backquote-token-tree} \\ 
{\bf then }{\rm{backquote-expansion}}\,({\bf{t}}, {\rm{readmacro-expansion}}\,({\rm{constituent}}\,({\it{x\/}})\index{constituent})\index{readmacro-expansion})\index{backquote-expansion} \\ 
{\bf elseif }{\rm{dotted-pair}}\,({\it{x\/}})\index{dotted-pair} \\ 
{\bf then }\=\+{\bf if }\=\+(\=\+({\rm{readmacro-expansion}}\,({\rm{cadrn}}\,({\tt{2}}, {\it{x\/}})\index{cadrn})\index{readmacro-expansion} $\simeq\;${{\bf{nil}}}${}$) \\ 
$\wedge$$\;\;\;\;$({\rm{readmacro-expansion}}\,({\rm{cadrn}}\,({\tt{2}}, {\it{x\/}})\index{cadrn})\index{readmacro-expansion} $\not=$ {\tt{'}}{\tt{nil}}))\- \\ 
$\vee$$\;\;\;\;${\rm{special-token-tree}}\,({\rm{readmacro-expansion}}\,({\rm{cadrn}}\,({\tt{2}}, {\it{x\/}})\index{cadrn})\index{readmacro-expansion})\index{special-token-tree}\- \\ 
{\bf then }{\rm{list3}}\,(\=\+{\rm{readmacro-expansion}}\,({\rm{car}}\,({\it{x\/}}))\index{readmacro-expansion}, \\ 
{\sc{dot-token}}\index{dot-token}, \\ 
{\rm{readmacro-expansion}}\,({\rm{cadrn}}\,({\tt{2}}, {\it{x\/}})\index{cadrn})\index{readmacro-expansion})\-\index{list3} \\ 
{\bf else }{\rm{cons}}\,(\=\+{\rm{readmacro-expansion}}\,({\rm{car}}\,({\it{x\/}}))\index{readmacro-expansion}, \\ 
{\rm{readmacro-expansion}}\,({\rm{cadrn}}\,({\tt{2}}, {\it{x\/}})\index{cadrn})\index{readmacro-expansion})\-$\;${\bf  endif}\- \\ 
{\bf elseif }{\rm{singleton}}\,({\it{x\/}})\index{singleton}$\;\;${\bf then }{\rm{list1}}\,({\rm{readmacro-expansion}}\,({\rm{car}}\,({\it{x\/}}))\index{readmacro-expansion})\index{list1} \\ 
{\bf else }{\rm{cons}}\,(\=\+{\rm{readmacro-expansion}}\,({\rm{car}}\,({\it{x\/}}))\index{readmacro-expansion}, \\ 
{\rm{readmacro-expansion}}\,({\rm{cdr}}\,({\it{x\/}}))\index{readmacro-expansion})\-$\;${\bf  endif}\-\-
\end{tabbing}


\begin{verbatim}; SECTION:  Some Common Lisp

#|

; This entire section is commented out.  It is here only as a con-
; venience for those wishing to test the token tree reader and
; readmacro-expansion.  The following function reads a token tree
; from a stream of ASCII character codes.  If it did not parse or
; is ``unreadable,'' suitable messages are returned.  Otherwise,
; the token tree is readmacro-expanded.  If an s-expression does
; not result, a suitable message is returned.  THIS ERROR MESSAGE
; SHOULD NEVER HAPPEN because the readmacro-expansion of a readable
; token tree supposedly always produces an s-expression!  If no
; errors are reported, the function returns the resulting s-
; expression.  Thus, this function is essentially a formalization
; of the the Lisp read routine.

(DEFN TEST-READER (STREAM)
  (LET ((X (READ-TOKEN-TREE STREAM)))
    (COND ((NOT X) 'DID-NOT-PARSE)
	  ((NOT (READABLE X 0)) 'NOT-READABLE-FROM-0)
	  (T (LET ((Y (READMACRO-EXPANSION X)))
	       (COND
                ((S-EXPRESSION Y)
                 Y)
                (T (LIST
                    'READMACRO-EXPANSION-PRODUCED-NON-S-EXPRESSION
                    Y))))))))

; The following defines a Lisp routine, not a function in the
; logic.  The routine's name is test-reader and it is just a
; convenient interface to the logical function defined above.  You
; give it a Lisp string and it converts it into a list of ASCII
; codes.  This just lets us type things like (test-reader "(PLUS X
; Y)") to Common Lisp -- not to R-LOOP -- to execute the logic's
; TEST-READER.  This Lisp definition assigns the correct character
; codes in AKCL.  Recall the comment above about the codes for TAB,
; NEWLINE, PAGE, SPACE, and RUBOUT when implementing a utility to
; convert Common Lisp typein into lists of ASCII codes.

 (defun ascii (string)
   (mapcar (function char-code)
           (coerce string 'list)))

 (defun test-reader (string)
   (*1*test-reader (ascii string)))

; We now return to the main flow of this development of the
; extended syntax.

|#


; SECTION: Some Terminology Preliminary to Translation

; We now define the concepts used to describe the process of
; translation from an s-expression to a formal term.

\end{verbatim}\begin{tabbing}{\sc Definition}:\index{corresponding-numberp} \\  
\=\+{\rm{corresponding-numberp}}\,({\it{n\/}})\index{corresponding-numberp} \\ 
$=$$\;\;\;\;$\=\+{\bf if }{\it{n\/}} $\simeq {\tt{0}}$$\;\;${\bf then }{\rm{list1}}\,({\tt{'}}{\tt{zero}})\index{list1} \\ 
{\bf else }{\rm{list2}}\,({\tt{'}}{\tt{add1}}, {\rm{corresponding-numberp}}\,({\it{n\/}} $-\;1$)\index{corresponding-numberp})\index{list2}$\;${\bf  endif}\-\-
\end{tabbing}

\begin{tabbing}{\sc Definition}:\index{corresponding-negativep} \\  
\=\+{\rm{corresponding-negativep}}\,({\it{n\/}})\index{corresponding-negativep} \\ 
$=$$\;\;\;\;${\rm{list2}}\,({\tt{'}}{\tt{minus}}, {\rm{corresponding-numberp}}\,({\rm{negative-guts}}\,({\it{n\/}}))\index{corresponding-numberp})\index{list2}\-
\end{tabbing}

\begin{tabbing}{\sc Definition}:\index{a-d-sequencep} \\  
\=\+{\rm{a-d-sequencep}}\,({\it{lst\/}})\index{a-d-sequencep} \\ 
$=$$\;\;\;\;$\=\+{\bf if }{\it{lst\/}} $\simeq\;${{\bf{nil}}}${}$$\;\;${\bf then }{\bf{t}} \\ 
{\bf elseif }\=\+({\rm{car}}\,({\it{lst\/}}) $=$ {\rm{ascii}}\,({\tt{'}}{\tt{upper-a}})\index{ascii}) \\ 
$\vee$$\;\;\;\;$({\rm{car}}\,({\it{lst\/}}) $=$ {\rm{ascii}}\,({\tt{'}}{\tt{upper-d}})\index{ascii})\- \\ 
{\bf then }{\rm{a-d-sequencep}}\,({\rm{cdr}}\,({\it{lst\/}}))\index{a-d-sequencep} \\ 
{\bf else }{\bf{f}}$\;${\bf  endif}\-\-
\end{tabbing}

\begin{tabbing}{\sc Definition}:\index{car-cdr-symbolp} \\  
\=\+{\rm{car-cdr-symbolp}}\,({\it{x\/}})\index{car-cdr-symbolp} \\ 
$=$$\;\;\;\;$(\=\+{\rm{litatom}}\,({\it{x\/}}) \\ 
$\wedge$$\;\;\;\;$(\=\+({\rm{car}}\,({\rm{unpack}}\,({\it{x\/}})) $=$ {\rm{ascii}}\,({\tt{'}}{\tt{upper-c}})\index{ascii}) \\ 
$\wedge$$\;\;\;\;$(\=\+({\rm{car}}\,({\rm{last}}\,({\rm{unpack}}\,({\it{x\/}}))\index{last}) $=$ {\rm{ascii}}\,({\tt{'}}{\tt{upper-r}})\index{ascii}) \\ 
$\wedge$$\;\;\;\;${\rm{a-d-sequencep}}\,({\rm{all-but-last}}\,({\rm{cdr}}\,({\rm{unpack}}\,({\it{x\/}})))\index{all-but-last})\index{a-d-sequencep})\-)\-)\-\-
\end{tabbing}

\begin{verbatim}; While the text defines the A/D sequence of a CAR/CDR symbol to be
; a sequence of A's and D's, we define it to be a sequence of the
; ASCII codes of A and of D.

\end{verbatim}\begin{tabbing}{\sc Definition}:\index{a-d-sequence}$\;\;$
{\rm{a-d-sequence}}\,({\it{x\/}})\index{a-d-sequence} $=$ {\rm{all-but-last}}\,({\rm{cdr}}\,({\rm{unpack}}\,({\it{x\/}})))\index{all-but-last}
\end{tabbing}

\begin{tabbing}{\sc Definition}:\index{car-cdr-nest} \\  
\=\+{\rm{car-cdr-nest}}\,({\it{lst\/}}, {\it{x\/}})\index{car-cdr-nest} \\ 
$=$$\;\;\;\;$\=\+{\bf if }{\it{lst\/}} $\simeq\;${{\bf{nil}}}${}$$\;\;${\bf then }{\it{x\/}} \\ 
{\bf elseif }{\rm{car}}\,({\it{lst\/}}) $=$ {\rm{ascii}}\,({\tt{'}}{\tt{upper-a}})\index{ascii} \\ 
{\bf then }{\rm{list2}}\,({\tt{'}}{\tt{car}}, {\rm{car-cdr-nest}}\,({\rm{cdr}}\,({\it{lst\/}}), {\it{x\/}})\index{car-cdr-nest})\index{list2} \\ 
{\bf else }{\rm{list2}}\,({\tt{'}}{\tt{cdr}}, {\rm{car-cdr-nest}}\,({\rm{cdr}}\,({\it{lst\/}}), {\it{x\/}})\index{car-cdr-nest})\index{list2}$\;${\bf  endif}\-\-
\end{tabbing}

\begin{verbatim}; Ultimately we will define the translation process.  This will
; involve us in consing together the translations of various com-
; ponents of an s-expression, after making sure those components
; are well-formed.  We signal ill-formed input by returning F in-
; stead of (the quotation of) the formal term.  To make the neces-
; sary well-formedness checks less distracting we define the fol-
; lowing function which we use to create the formal terms.  It is
; like CONS, but observes the convention that if either argument is
; F the result is F.

\end{verbatim}\begin{tabbing}{\sc Definition}:\index{fcons} \\  
\=\+{\rm{fcons}}\,({\it{x\/}}, {\it{y\/}})\index{fcons} \\ 
$=$$\;\;\;\;$\=\+{\bf if }{\it{x\/}} $\wedge$ {\it{y\/}}$\;\;${\bf then }{\rm{cons}}\,({\it{x\/}}, {\it{y\/}}) \\ 
{\bf else }{\bf{f}}$\;${\bf  endif}\-\-
\end{tabbing}

\begin{verbatim}; We also provide ourselves with several LIST-like functions that
; respect this convention.  'Tis a pity we do not have macros in
; the Nqthm logic because we really just want to define a ``func-
; tion'' symbol that takes an arbitrary number of arguments.

\end{verbatim}\begin{tabbing}{\sc Definition}:\index{flist1}$\;\;$
{\rm{flist1}}\,({\it{x\/}})\index{flist1} $=$ {\rm{fcons}}\,({\it{x\/}}, {\bf{nil}})\index{fcons}
\end{tabbing}
\begin{tabbing}{\sc Definition}:\index{flist2}$\;\;$
{\rm{flist2}}\,({\it{x\/}}, {\it{y\/}})\index{flist2} $=$ {\rm{fcons}}\,({\it{x\/}}, {\rm{flist1}}\,({\it{y\/}})\index{flist1})\index{fcons}
\end{tabbing}
\begin{tabbing}{\sc Definition}:\index{flist3}$\;\;$
{\rm{flist3}}\,({\it{x\/}}, {\it{y\/}}, {\it{z\/}})\index{flist3} $=$ {\rm{fcons}}\,({\it{x\/}}, {\rm{flist2}}\,({\it{y\/}}, {\it{z\/}})\index{flist2})\index{fcons}
\end{tabbing}
\begin{tabbing}{\sc Definition}:\index{flist4}$\;\;$
{\rm{flist4}}\,({\it{x\/}}, {\it{y\/}}, {\it{z\/}}, {\it{w\/}})\index{flist4} $=$ {\rm{fcons}}\,({\it{x\/}}, {\rm{flist3}}\,({\it{y\/}}, {\it{z\/}}, {\it{w\/}})\index{flist3})\index{fcons}
\end{tabbing}
\begin{tabbing}{\sc Definition}:\index{flist5}$\;\;$
{\rm{flist5}}\,({\it{x\/}}, {\it{y\/}}, {\it{z\/}}, {\it{w\/}}, {\it{v\/}})\index{flist5} $=$ {\rm{fcons}}\,({\it{x\/}}, {\rm{flist4}}\,({\it{y\/}}, {\it{z\/}}, {\it{w\/}}, {\it{v\/}})\index{flist4})\index{fcons}
\end{tabbing}
\begin{tabbing}{\sc Definition}:\index{flist6}$\;\;$
{\rm{flist6}}\,({\it{x\/}}, {\it{y\/}}, {\it{z\/}}, {\it{w\/}}, {\it{v\/}}, {\it{u\/}})\index{flist6} $=$ {\rm{fcons}}\,({\it{x\/}}, {\rm{flist5}}\,({\it{y\/}}, {\it{z\/}}, {\it{w\/}}, {\it{v\/}}, {\it{u\/}})\index{flist5})\index{fcons}
\end{tabbing}
\begin{tabbing}{\sc Definition}:\index{flist7} \\  
{\rm{flist7}}\,({\it{x\/}}, {\it{y\/}}, {\it{z\/}}, {\it{w\/}}, {\it{v\/}}, {\it{u\/}}, {\it{r\/}})\index{flist7} $=$ {\rm{fcons}}\,({\it{x\/}}, {\rm{flist6}}\,({\it{y\/}}, {\it{z\/}}, {\it{w\/}}, {\it{v\/}}, {\it{u\/}}, {\it{r\/}})\index{flist6})\index{fcons}
\end{tabbing}

\begin{verbatim}; Here is the formalization of the ``fn nest around x for lst'',
; which is presented in the text before we get to the extended
; syntax.  Note that we use our FCONS convention so that if X or
; any element of LST is F, the result is F.

\end{verbatim}\begin{tabbing}{\sc Definition}:\index{fn-nest} \\  
\=\+{\rm{fn-nest}}\,({\it{fn\/}}, {\it{lst\/}}, {\it{x\/}})\index{fn-nest} \\ 
$=$$\;\;\;\;$\=\+{\bf if }{\it{lst\/}} $\simeq\;${{\bf{nil}}}${}$$\;\;${\bf then }{\it{x\/}} \\ 
{\bf else }{\rm{flist3}}\,({\it{fn\/}}, {\rm{car}}\,({\it{lst\/}}), {\rm{fn-nest}}\,({\it{fn\/}}, {\rm{cdr}}\,({\it{lst\/}}), {\it{x\/}})\index{fn-nest})\index{flist3}$\;${\bf  endif}\-\-
\end{tabbing}

\begin{tabbing}{\sc Definition}:\index{corresponding-numberps} \\  
\=\+{\rm{corresponding-numberps}}\,({\it{lst\/}})\index{corresponding-numberps} \\ 
$=$$\;\;\;\;$\=\+{\bf if }{\it{lst\/}} $\simeq\;${{\bf{nil}}}${}$$\;\;${\bf then }{\bf{nil}} \\ 
{\bf else }{\rm{cons}}\,(\=\+{\rm{corresponding-numberp}}\,({\rm{car}}\,({\it{lst\/}}))\index{corresponding-numberp}, \\ 
{\rm{corresponding-numberps}}\,({\rm{cdr}}\,({\it{lst\/}}))\index{corresponding-numberps})\-$\;${\bf  endif}\-\-
\end{tabbing}

\begin{tabbing}{\sc Definition}:\index{explosion} \\  
\=\+{\rm{explosion}}\,({\it{lst\/}})\index{explosion} \\ 
$=$$\;\;\;\;${\rm{fn-nest}}\,({\tt{'}}{\tt{cons}}, {\rm{corresponding-numberps}}\,({\it{lst\/}})\index{corresponding-numberps}, {\rm{list1}}\,({\tt{'}}{\tt{zero}})\index{list1})\index{fn-nest}\-
\end{tabbing}

\begin{tabbing}{\sc Definition}:\index{corresponding-litatom} \\  
{\rm{corresponding-litatom}}\,({\it{x\/}})\index{corresponding-litatom} $=$ {\rm{list2}}\,({\tt{'}}{\tt{pack}}, {\rm{explosion}}\,({\rm{unpack}}\,({\it{x\/}}))\index{explosion})\index{list2}
\end{tabbing}

\begin{verbatim}; The following function tacks the *1* prefix onto the front of
; LITATOMs.  Thus, (star-one-star 'true) is the LITATOM '*1*TRUE --
; EXCEPT we can't write that literal atom that way because it is
; not a symbolp.  It must be written as (PACK '(42 49 42 84 82 85
; 69 . 0)) or, equivalently, '(*1*QUOTE PACK (42 49 42 84 82 85 69
; . 0)).

\end{verbatim}\begin{tabbing}{\sc Definition}:\index{star-one-star} \\  
\=\+{\rm{star-one-star}}\,({\it{x\/}})\index{star-one-star} \\ 
$=$$\;\;\;\;${\rm{pack}}\,({\rm{append}}\,({\rm{ascii}}\,({\tt{'}}{\tt{(}}{\tt{asterisk}}{\tt{ }}{\tt{digit-one}}{\tt{ }}{\tt{asterisk}}{\tt{)}})\index{ascii}, {\rm{unpack}}\,({\it{x\/}})))\-
\end{tabbing}

\begin{verbatim}; We need to define what it is to be a symbol.  The text does this
; quite early, while introducing formal terms.  Here is the
; formalization.

\end{verbatim}\begin{tabbing}{\sc Definition}:\index{ascii-upper-alphabetics} \\  
\=\+{\sc{ascii-upper-alphabetics}}\index{ascii-upper-alphabetics} \\ 
$=$$\;\;\;\;${\rm{ascii}}\,({\tt{'}}{\tt{(}}\=\+{\tt{upper-a}}{\tt{ }}{\tt{upper-b}}{\tt{ }}{\tt{upper-c}}{\tt{ }}{\tt{upper-d}}{\tt{ }}{\tt{upper-e}}{\tt{ }}{\tt{upper-f}} \\ 
{\tt{upper-g}}{\tt{ }}{\tt{upper-h}}{\tt{ }}{\tt{upper-i}}{\tt{ }}{\tt{upper-j}}{\tt{ }}{\tt{upper-k}}{\tt{ }}{\tt{upper-l}} \\ 
{\tt{upper-m}}{\tt{ }}{\tt{upper-n}}{\tt{ }}{\tt{upper-o}}{\tt{ }}{\tt{upper-p}}{\tt{ }}{\tt{upper-q}}{\tt{ }}{\tt{upper-r}} \\ 
{\tt{upper-s}}{\tt{ }}{\tt{upper-t}}{\tt{ }}{\tt{upper-u}}{\tt{ }}{\tt{upper-v}}{\tt{ }}{\tt{upper-w}}{\tt{ }}{\tt{upper-x}} \\ 
{\tt{upper-y}}{\tt{ }}{\tt{upper-z}}{\tt{)}}\-)\index{ascii}\-
\end{tabbing}

\begin{tabbing}{\sc Definition}:\index{ascii-digits-and-signs} \\  
\=\+{\sc{ascii-digits-and-signs}}\index{ascii-digits-and-signs} \\ 
$=$$\;\;\;\;${\rm{ascii}}\,({\tt{'}}{\tt{(}}\=\+{\tt{digit-one}}{\tt{ }}{\tt{digit-two}}{\tt{ }}{\tt{digit-three}}{\tt{ }}{\tt{digit-four}} \\ 
{\tt{digit-five}}{\tt{ }}{\tt{digit-six}}{\tt{ }}{\tt{digit-seven}}{\tt{ }}{\tt{digit-eight}} \\ 
{\tt{digit-nine}}{\tt{ }}{\tt{dollar-sign}}{\tt{ }}{\tt{uparrow}}{\tt{ }}{\tt{ampersand}}{\tt{ }}{\tt{asterisk}} \\ 
{\tt{underscore}}{\tt{ }}{\tt{minus-sign}}{\tt{ }}{\tt{plus-sign}}{\tt{ }}{\tt{equal-sign}}{\tt{ }}{\tt{tilde}} \\ 
{\tt{open-brace}}{\tt{ }}{\tt{close-brace}}{\tt{ }}{\tt{question-mark}} \\ 
{\tt{less-than-sign}}{\tt{ }}{\tt{greater-than-sign}}{\tt{)}}\-)\index{ascii}\-
\end{tabbing}

\begin{tabbing}{\sc Definition}:\index{all-upper-alphabetics-digits-or!-signs} \\  
\=\+{\rm{all-upper-alphabetics-digits-or-signs}}\,({\it{l\/}})\index{all-upper-alphabetics-digits-or!-signs} \\ 
$=$$\;\;\;\;$\=\+{\bf if }{\it{l\/}} $\simeq\;${{\bf{nil}}}${}$$\;\;${\bf then }{\bf{t}} \\ 
{\bf else }\=\+(\=\+({\rm{car}}\,({\it{l\/}}) $\in$ {\sc{ascii-upper-alphabetics}}\index{ascii-upper-alphabetics}) \\ 
$\vee$$\;\;\;\;$({\rm{car}}\,({\it{l\/}}) $\in$ {\sc{ascii-digits-and-signs}}\index{ascii-digits-and-signs}))\- \\ 
$\wedge$$\;\;\;\;${\rm{all-upper-alphabetics-digits-or-signs}}\,({\rm{cdr}}\,({\it{l\/}}))\index{all-upper-alphabetics-digits-or!-signs}\-$\;${\bf  endif}\-\-
\end{tabbing}

\begin{tabbing}{\sc Definition}:\index{legal-char-code-seq} \\  
\=\+{\rm{legal-char-code-seq}}\,({\it{l\/}})\index{legal-char-code-seq} \\ 
$=$$\;\;\;\;$(\=\+{\rm{listp}}\,({\it{l\/}}) \\ 
$\wedge$$\;\;\;\;$(\=\+({\rm{cdr}}\,({\rm{last}}\,({\it{l\/}})\index{last}) $=$ {\tt{0}}) \\ 
$\wedge$$\;\;\;\;$(\=\+({\rm{car}}\,({\it{l\/}}) $\in$ {\sc{ascii-upper-alphabetics}}\index{ascii-upper-alphabetics}) \\ 
$\wedge$$\;\;\;\;${\rm{all-upper-alphabetics-digits-or-signs}}\,({\rm{cdr}}\,({\it{l\/}}))\index{all-upper-alphabetics-digits-or!-signs})\-)\-)\-\-
\end{tabbing}

\begin{tabbing}{\sc Definition}:\index{symbolp} \\  
{\rm{symbolp}}\,({\it{x\/}})\index{symbolp} $=$ ({\rm{litatom}}\,({\it{x\/}}) $\wedge$ {\rm{legal-char-code-seq}}\,({\rm{unpack}}\,({\it{x\/}}))\index{legal-char-code-seq})
\end{tabbing}


\begin{verbatim}; SECTION:  Formalizing Aspects of the History

; At this point in the text we define well-formedness and trans-
; lation.  But the text delays until later the definitions of
; several concepts used.  These delayed concepts are: QUOTE
; notation, the *1*QUOTE escape mechanism, and abbreviated FORs.
; We have to formalize these before we can define translation.
; Unfortunately, before we can formalize *1*QUOTE notation we must
; formalize certain concepts relating to the ``history'' in which
; the translation is occurring.  For example, (FN X Y) is well-
; formed and has a translation only if FN is a function symbol of
; arity 2.  We must formalize arity.  We must also formalize the
; notions of what it is to be a shell constructor, a base object,
; and to satisfy the ``type- restrictions'' of a shell.

; But functions that depend upon the ``current history'' cannot be
; defined unless we wish to make the ``current history'' an ex-
; plicit object in the formalization.  That is a reasonable thing
; to do but is beyond the scope of this book because the only DEFN
; events (for example) permitted in a history are those that are
; admissible, which involves the notion of proof.  Thus, to formal-
; ize histories accurately we would have to formalize the rules of
; inference (not just the syntax) and what it is to be a theorem.
; This has been done for other logics in the Nqthm logic.  See for
; example Shankar's work in examples/shankar or the bibliographic
; entries for Shankar.

; Rather than formalize histories in order to formalize the syntax,
; we will formalize the syntax for a particular history.  The his-
; tory we choose is the GROUND-ZERO history extended with one il-
; lustrative user-defined shell, the stacks as illustrated in the
; text, plus one illustrative user-defined function, CONCAT, which
; is just APPEND by another name.  We introduce these functions be-
; low into the theory.  They are nowhere used in this development
; and thus by searching for references to them you can see every-
; thing that must be known about a function symbol for it to be
; usable in the extended syntax.

; An irrelevant shell added to illustrate user-defined shells:

\end{verbatim}
\noindent{\sc Event}:   Add the shell {\it{push\/}}\index{push}, with bottom object function symbol {\it{empty-stack\/}}, with recognizer function symbol {\it{stackp\/}}, and 2 accessors: {\it{top\/}}, with type restriction (one-of numberp) and default value zero; {\it{pop\/}}, with type restriction (one-of stackp) and default value empty-stack.

\addvspace{18pt}

\begin{verbatim}; An irrelevant function added to illustrate user-defined
; functions:

\end{verbatim}\begin{tabbing}{\sc Definition}:\index{concat} \\  
\=\+{\rm{concat}}\,({\it{x\/}}, {\it{y\/}})\index{concat} \\ 
$=$$\;\;\;\;$\=\+{\bf if }{\it{x\/}} $\simeq\;${{\bf{nil}}}${}$$\;\;${\bf then }{\it{y\/}} \\ 
{\bf else }{\rm{cons}}\,({\rm{car}}\,({\it{x\/}}), {\rm{concat}}\,({\rm{cdr}}\,({\it{x\/}}), {\it{y\/}})\index{concat})$\;${\bf  endif}\-\-
\end{tabbing}

\begin{verbatim}; So consider the GROUND-ZERO logic extended with the two logical
; acts above.  We will now define some functions that answer ques-
; tions about that history, e.g., what are the base function
; symbols?

; The following function returns non-F if its argument is (the quo-
; tation of) a shell base function symbol.  When it returns non-F
; it actually returns (the quotation of) the recognizer for the
; relevant shell.

\end{verbatim}\begin{tabbing}{\sc Definition}:\index{shell-base-function} \\  
\=\+{\rm{shell-base-function}}\,({\it{x\/}})\index{shell-base-function} \\ 
$=$$\;\;\;\;$\=\+{\bf if }{\it{x\/}} $=$ {\tt{'}}{\tt{true}}$\;\;${\bf then }{\tt{'}}{\tt{truep}} \\ 
{\bf elseif }{\it{x\/}} $=$ {\tt{'}}{\tt{false}}$\;\;${\bf then }{\tt{'}}{\tt{falsep}} \\ 
{\bf elseif }{\it{x\/}} $=$ {\tt{'}}{\tt{zero}}$\;\;${\bf then }{\tt{'}}{\tt{numberp}} \\ 
{\bf elseif }{\it{x\/}} $=$ {\tt{'}}{\tt{empty-stack}}$\;\;${\bf then }{\tt{'}}{\tt{stackp}} \\ 
{\bf else }{\bf{f}}$\;${\bf  endif}\-\-
\end{tabbing}

\begin{verbatim}; The next function is the analogous one for shell constructor
; function symbols.

\end{verbatim}\begin{tabbing}{\sc Definition}:\index{shell-constructor-function} \\  
\=\+{\rm{shell-constructor-function}}\,({\it{x\/}})\index{shell-constructor-function} \\ 
$=$$\;\;\;\;$\=\+{\bf if }{\it{x\/}} $=$ {\tt{'}}{\tt{add1}}$\;\;${\bf then }{\tt{'}}{\tt{numberp}} \\ 
{\bf elseif }{\it{x\/}} $=$ {\tt{'}}{\tt{cons}}$\;\;${\bf then }{\tt{'}}{\tt{listp}} \\ 
{\bf elseif }{\it{x\/}} $=$ {\tt{'}}{\tt{pack}}$\;\;${\bf then }{\tt{'}}{\tt{litatom}} \\ 
{\bf elseif }{\it{x\/}} $=$ {\tt{'}}{\tt{minus}}$\;\;${\bf then }{\tt{'}}{\tt{negativep}} \\ 
{\bf elseif }{\it{x\/}} $=$ {\tt{'}}{\tt{push}}$\;\;${\bf then }{\tt{'}}{\tt{stackp}} \\ 
{\bf else }{\bf{f}}$\;${\bf  endif}\-\-
\end{tabbing}

\begin{verbatim}; The following function returns the list of type restrictions for
; a shell constructor.  The list is in 1:1 correspondence with the
; accessor names, i.e., the arguments of the constructor.  For ex-
; ample, for PUSH the result is '((ONE-OF NUMBERP) (ONE-OF STACKP))
; which tells us the first argument to PUSH must be a NUMBERP and
; the second must be a STACKP.

\end{verbatim}\begin{tabbing}{\sc Definition}:\index{shell-type-restrictions} \\  
\=\+{\rm{shell-type-restrictions}}\,({\it{x\/}})\index{shell-type-restrictions} \\ 
$=$$\;\;\;\;$\=\+{\bf if }({\it{x\/}} $=$ {\tt{'}}{\tt{add1}}) $\vee$ ({\it{x\/}} $=$ {\tt{'}}{\tt{minus}}) \\ 
{\bf then }{\rm{list1}}\,({\rm{list2}}\,({\tt{'}}{\tt{one-of}}, {\tt{'}}{\tt{numberp}})\index{list2})\index{list1} \\ 
{\bf elseif }{\it{x\/}} $=$ {\tt{'}}{\tt{cons}}$\;\;${\bf then }{\rm{list2}}\,({\rm{list1}}\,({\tt{'}}{\tt{none-of}})\index{list1}, {\rm{list1}}\,({\tt{'}}{\tt{none-of}})\index{list1})\index{list2} \\ 
{\bf elseif }{\it{x\/}} $=$ {\tt{'}}{\tt{pack}}$\;\;${\bf then }{\rm{list1}}\,({\rm{list1}}\,({\tt{'}}{\tt{none-of}})\index{list1})\index{list1} \\ 
{\bf elseif }{\it{x\/}} $=$ {\tt{'}}{\tt{push}} \\ 
{\bf then }{\rm{list2}}\,({\rm{list2}}\,({\tt{'}}{\tt{one-of}}, {\tt{'}}{\tt{numberp}})\index{list2}, {\rm{list2}}\,({\tt{'}}{\tt{one-of}}, {\tt{'}}{\tt{stackp}})\index{list2})\index{list2} \\ 
{\bf else }{\bf{f}}$\;${\bf  endif}\-\-
\end{tabbing}

\begin{verbatim}; This function takes a shell constructor or base function symbol
; and determines whether it satisfies a given type-restriction.
; Thus, FN might be ADD1 and TYPE-RESTRICTION might be '(ONE-OF
; NUMBERP) -- in which case SATISFIES returns T.  If the type
; restriction were '(ONE-OF STACKP), SATISFIES would return F for
; FN 'ADD1.

\end{verbatim}\begin{tabbing}{\sc Definition}:\index{satisfies} \\  
\=\+{\rm{satisfies}}\,({\it{fn\/}}, {\it{type-restriction\/}})\index{satisfies} \\ 
$=$$\;\;\;\;$\=\+{\bf if }{\rm{car}}\,({\it{type-restriction\/}}) $=$ {\tt{'}}{\tt{one-of}} \\ 
{\bf then }\=\+\=\+{\bf if }{\rm{shell-base-function}}\,({\it{fn\/}})\index{shell-base-function}$\;\;${\bf then }{\rm{shell-base-function}}\,({\it{fn\/}})\index{shell-base-function} \\ 
{\bf else }{\rm{shell-constructor-function}}\,({\it{fn\/}})\index{shell-constructor-function}$\;${\bf  endif}\- \\ 
$\in$$\;\;\;\;${\rm{cdr}}\,({\it{type-restriction\/}})\- \\ 
{\bf else }\=\+\=\+{\bf if }{\rm{shell-base-function}}\,({\it{fn\/}})\index{shell-base-function}$\;\;${\bf then }{\rm{shell-base-function}}\,({\it{fn\/}})\index{shell-base-function} \\ 
{\bf else }{\rm{shell-constructor-function}}\,({\it{fn\/}})\index{shell-constructor-function}$\;${\bf  endif}\- \\ 
$\not\in$$\;\;\;\;${\rm{cdr}}\,({\it{type-restriction\/}})\-$\;${\bf  endif}\-\-
\end{tabbing}

\begin{verbatim}; This function takes a list of function symbols and a list of type
; restrictions in 1:1 correspondence and determines whether all of
; the type restrictions are satisfied by the corresponding function
; symbols.

\end{verbatim}\begin{tabbing}{\sc Definition}:\index{all-satisfy} \\  
\=\+{\rm{all-satisfy}}\,({\it{fn-lst\/}}, {\it{type-restriction-lst\/}})\index{all-satisfy} \\ 
$=$$\;\;\;\;$\=\+{\bf if }{\it{fn-lst\/}} $\simeq\;${{\bf{nil}}}${}$$\;\;${\bf then }{\bf{t}} \\ 
{\bf else }\=\+{\rm{satisfies}}\,({\rm{car}}\,({\it{fn-lst\/}}), {\rm{car}}\,({\it{type-restriction-lst\/}}))\index{satisfies} \\ 
$\wedge$$\;\;\;\;${\rm{all-satisfy}}\,({\rm{cdr}}\,({\it{fn-lst\/}}), {\rm{cdr}}\,({\it{type-restriction-lst\/}}))\index{all-satisfy}\-$\;${\bf  endif}\-\-
\end{tabbing}

\begin{verbatim}; The next two functions define the arity of each of the function
; symbols in the particular history we are considering.  We use the
; extended syntax here, namely QUOTE notation, to write down the
; alist.  Readers using this formalization as a means of mastering
; the notation should simply understand that as a result of the
; definition below, (ARITY 'IF) = 3, (ARITY 'STACKP) = 1 and (ARITY
; 'ANY-NEW-SYMBOL) = F.  That is, if (fn . n) appears in the defi-
; nition of ARITY-ALIST then (ARITY 'fn) = n.  Otherwise, (ARITY
; 'fn) = F.

\end{verbatim}\begin{tabbing}{\sc Definition}:\index{arity-alist} \\  
\=\+{\sc{arity-alist}}\index{arity-alist} \\ 
$=$$\;\;\;\;${\tt{'}}{\tt{(}}\=\+{\tt{(}}{\tt{if}}{\tt{ .\ }}{\tt{3}}{\tt{)}} \\ 
{\tt{(}}{\tt{equal}}{\tt{ .\ }}{\tt{2}}{\tt{)}} \\ 
{\tt{(}}{\tt{count}}{\tt{ .\ }}{\tt{1}}{\tt{)}} \\ 
{\tt{(}}{\tt{false}}{\tt{ .\ }}{\tt{0}}{\tt{)}} \\ 
{\tt{(}}{\tt{falsep}}{\tt{ .\ }}{\tt{1}}{\tt{)}} \\ 
{\tt{(}}{\tt{true}}{\tt{ .\ }}{\tt{0}}{\tt{)}} \\ 
{\tt{(}}{\tt{truep}}{\tt{ .\ }}{\tt{1}}{\tt{)}} \\ 
{\tt{(}}{\tt{not}}{\tt{ .\ }}{\tt{1}}{\tt{)}} \\ 
{\tt{(}}{\tt{and}}{\tt{ .\ }}{\tt{2}}{\tt{)}} \\ 
{\tt{(}}{\tt{or}}{\tt{ .\ }}{\tt{2}}{\tt{)}} \\ 
{\tt{(}}{\tt{implies}}{\tt{ .\ }}{\tt{2}}{\tt{)}} \\ 
{\tt{(}}{\tt{add1}}{\tt{ .\ }}{\tt{1}}{\tt{)}} \\ 
{\tt{(}}{\tt{numberp}}{\tt{ .\ }}{\tt{1}}{\tt{)}} \\ 
{\tt{(}}{\tt{sub1}}{\tt{ .\ }}{\tt{1}}{\tt{)}} \\ 
{\tt{(}}{\tt{zero}}{\tt{ .\ }}{\tt{0}}{\tt{)}} \\ 
{\tt{(}}{\tt{lessp}}{\tt{ .\ }}{\tt{2}}{\tt{)}} \\ 
{\tt{(}}{\tt{greaterp}}{\tt{ .\ }}{\tt{2}}{\tt{)}} \\ 
{\tt{(}}{\tt{leq}}{\tt{ .\ }}{\tt{2}}{\tt{)}} \\ 
{\tt{(}}{\tt{geq}}{\tt{ .\ }}{\tt{2}}{\tt{)}} \\ 
{\tt{(}}{\tt{zerop}}{\tt{ .\ }}{\tt{1}}{\tt{)}} \\ 
{\tt{(}}{\tt{fix}}{\tt{ .\ }}{\tt{1}}{\tt{)}} \\ 
{\tt{(}}{\tt{plus}}{\tt{ .\ }}{\tt{2}}{\tt{)}} \\ 
{\tt{(}}{\tt{pack}}{\tt{ .\ }}{\tt{1}}{\tt{)}} \\ 
{\tt{(}}{\tt{litatom}}{\tt{ .\ }}{\tt{1}}{\tt{)}} \\ 
{\tt{(}}{\tt{unpack}}{\tt{ .\ }}{\tt{1}}{\tt{)}} \\ 
{\tt{(}}{\tt{cons}}{\tt{ .\ }}{\tt{2}}{\tt{)}} \\ 
{\tt{(}}{\tt{listp}}{\tt{ .\ }}{\tt{1}}{\tt{)}} \\ 
{\tt{(}}{\tt{car}}{\tt{ .\ }}{\tt{1}}{\tt{)}} \\ 
{\tt{(}}{\tt{cdr}}{\tt{ .\ }}{\tt{1}}{\tt{)}} \\ 
{\tt{(}}{\tt{nlistp}}{\tt{ .\ }}{\tt{1}}{\tt{)}} \\ 
{\tt{(}}{\tt{minus}}{\tt{ .\ }}{\tt{1}}{\tt{)}} \\ 
{\tt{(}}{\tt{negativep}}{\tt{ .\ }}{\tt{1}}{\tt{)}} \\ 
{\tt{(}}{\tt{negative-guts}}{\tt{ .\ }}{\tt{1}}{\tt{)}} \\ 
{\tt{(}}{\tt{difference}}{\tt{ .\ }}{\tt{2}}{\tt{)}} \\ 
{\tt{(}}{\tt{times}}{\tt{ .\ }}{\tt{2}}{\tt{)}} \\ 
{\tt{(}}{\tt{quotient}}{\tt{ .\ }}{\tt{2}}{\tt{)}} \\ 
{\tt{(}}{\tt{remainder}}{\tt{ .\ }}{\tt{2}}{\tt{)}} \\ 
{\tt{(}}{\tt{member}}{\tt{ .\ }}{\tt{2}}{\tt{)}} \\ 
{\tt{(}}{\tt{iff}}{\tt{ .\ }}{\tt{2}}{\tt{)}} \\ 
{\tt{(}}{\tt{ord-lessp}}{\tt{ .\ }}{\tt{2}}{\tt{)}} \\ 
{\tt{(}}{\tt{ordinalp}}{\tt{ .\ }}{\tt{1}}{\tt{)}} \\ 
{\tt{(}}{\tt{assoc}}{\tt{ .\ }}{\tt{2}}{\tt{)}} \\ 
{\tt{(}}{\tt{pairlist}}{\tt{ .\ }}{\tt{2}}{\tt{)}} \\ 
{\tt{(}}{\tt{subrp}}{\tt{ .\ }}{\tt{1}}{\tt{)}} \\ 
{\tt{(}}{\tt{apply-subr}}{\tt{ .\ }}{\tt{2}}{\tt{)}} \\ 
{\tt{(}}{\tt{formals}}{\tt{ .\ }}{\tt{1}}{\tt{)}} \\ 
{\tt{(}}{\tt{body}}{\tt{ .\ }}{\tt{1}}{\tt{)}} \\ 
{\tt{(}}{\tt{fix-cost}}{\tt{ .\ }}{\tt{2}}{\tt{)}} \\ 
{\tt{(}}{\tt{strip-cars}}{\tt{ .\ }}{\tt{1}}{\tt{)}} \\ 
{\tt{(}}{\tt{sum-cdrs}}{\tt{ .\ }}{\tt{1}}{\tt{)}} \\ 
{\tt{(}}{\tt{v\&c\$}}{\tt{ .\ }}{\tt{3}}{\tt{)}} \\ 
{\tt{(}}{\tt{v\&c-apply\$}}{\tt{ .\ }}{\tt{2}}{\tt{)}} \\ 
{\tt{(}}{\tt{apply\$}}{\tt{ .\ }}{\tt{2}}{\tt{)}} \\ 
{\tt{(}}{\tt{eval\$}}{\tt{ .\ }}{\tt{3}}{\tt{)}} \\ 
{\tt{(}}{\tt{quantifier-initial-value}}{\tt{ .\ }}{\tt{1}}{\tt{)}} \\ 
{\tt{(}}{\tt{add-to-set}}{\tt{ .\ }}{\tt{2}}{\tt{)}} \\ 
{\tt{(}}{\tt{append}}{\tt{ .\ }}{\tt{2}}{\tt{)}} \\ 
{\tt{(}}{\tt{max}}{\tt{ .\ }}{\tt{2}}{\tt{)}} \\ 
{\tt{(}}{\tt{union}}{\tt{ .\ }}{\tt{2}}{\tt{)}} \\ 
{\tt{(}}{\tt{quantifier-operation}}{\tt{ .\ }}{\tt{3}}{\tt{)}} \\ 
{\tt{(}}{\tt{for}}{\tt{ .\ }}{\tt{6}}{\tt{)}} \\ 
{\tt{(}}{\tt{push}}{\tt{ .\ }}{\tt{2}}{\tt{)}} \\ 
{\tt{(}}{\tt{empty-stack}}{\tt{ .\ }}{\tt{0}}{\tt{)}} \\ 
{\tt{(}}{\tt{stackp}}{\tt{ .\ }}{\tt{1}}{\tt{)}} \\ 
{\tt{(}}{\tt{top}}{\tt{ .\ }}{\tt{1}}{\tt{)}} \\ 
{\tt{(}}{\tt{pop}}{\tt{ .\ }}{\tt{2}}{\tt{)}} \\ 
{\tt{(}}{\tt{concat}}{\tt{ .\ }}{\tt{2}}{\tt{)}}{\tt{)}}\-\-
\end{tabbing}

\begin{tabbing}{\sc Definition}:\index{arity} \\  
\=\+{\rm{arity}}\,({\it{fn\/}})\index{arity} \\ 
$=$$\;\;\;\;$\=\+{\bf if }{\rm{assoc}}\,({\it{fn\/}}, {\sc{arity-alist}}\index{arity-alist})$\;\;${\bf then }{\rm{cdr}}\,({\rm{assoc}}\,({\it{fn\/}}, {\sc{arity-alist}}\index{arity-alist})) \\ 
{\bf else }{\bf{f}}$\;${\bf  endif}\-\-
\end{tabbing}

\begin{verbatim}; That concludes the definitions of history dependent concepts.  We
; now return to the text.

; SECTION:  QUOTE Notation and the *1*QUOTE Escape

; The essence of the QUOTE notation is the notion of ``explicit
; value descriptor.''  In the text, that notion is defined in terms
; of ``explicit value escape descriptor'' without the latter notion
; being defined.  We then define the latter notion and its defi-
; nition involves the former.  Thus, the two are mutually recur-
; sive.  We formalize the mutual recursion with our traditional FLG
; argument.  Normally, one would expect one value of the flag to
; indicate we were defining ``explicit value descriptor'' and the
; other value to indicate ``explicit value escape descriptor.''
; But it turns out that the basic form of mutual recursion here is
; ``explicit value descriptor'' versus ``list of explicit value
; descriptors'' and the notion of ``explicit value escape de-
; scriptor'' is written ``in-line.''

; So when FLG is T below, we check that X is an explicit value
; descriptor and if so we return the formal term it denotes.  We
; return F if X is not such a descriptor.  When FLG is F we check
; that X is a list of explicit value descriptors and we return
; either the list of denoted formal terms or F if X fails to be a
; list of descriptors.

; The following three events have no logical significance.  They
; do, however, permit Nqthm to process the next definition without
; inordinate delay.  We disable all function definitions except
; CADRN and CDRN.

\end{verbatim}
\noindent{\sc Event}:   Set the status of all events.  The status of each event is to be set as follows.  disabled.  Anything not otherwise mentioned is to be left ``as-is''.   Name this event `pre-explicit-value-descriptor'.\index{pre-explicit-value-descriptor}

\addvspace{18pt}


\noindent{\sc Event}:   Enable cadrn.

\addvspace{18pt}

\noindent{\sc Event}:   Enable cdrn.

\addvspace{18pt}

%\item 
\begin{verbatim}


(DEFN EXPLICIT-VALUE-DESCRIPTOR (FLG X)
  (IF FLG

; Here we define what it is for X to be an explicit value de-
; scriptor and what formal term it denotes.

      (IF (NLISTP X)
          (IF (INTEGERP X)
              (IF (NUMBERP X)
                  (CORRESPONDING-NUMBERP X)
                  (CORRESPONDING-NEGATIVEP X))
          (IF (EQUAL X (STAR-ONE-STAR 'TRUE))
              (LIST1 'TRUE)
          (IF (EQUAL X (STAR-ONE-STAR 'FALSE))
              (LIST1 'FALSE)
          (IF (SYMBOLP X)
              (CORRESPONDING-LITATOM X)
              F))))
      (IF (EQUAL (CAR X) (STAR-ONE-STAR 'QUOTE))

; The test of the following IF contains the formalization of
; ``explicit value escape descriptor.''

          (IF (AND (OR (SHELL-CONSTRUCTOR-FUNCTION (CADRN 1 X))
                       (SHELL-BASE-FUNCTION (CADRN 1 X)))
               (AND (EQLEN (CDRN 2 X) (ARITY (CADRN 1 x)))
                (AND (EQUAL (CDR (LAST X)) NIL)
                 (AND (NOT (EQUAL (CADRN 1 X) 'ADD1))
                  (AND (NOT (EQUAL (CADRN 1 X) 'ZERO))
                   (AND (NOT (EQUAL (CADRN 1 X) 'CONS))
                    (AND (EXPLICIT-VALUE-DESCRIPTOR F (CDRN 2 X))
                     (AND
                      (IF (SHELL-CONSTRUCTOR-FUNCTION (CADRN 1 X))
                          (ALL-SATISFY
                           (STRIP-CARS
                            (EXPLICIT-VALUE-DESCRIPTOR F
                             (CDRN 2 X)))
                           (SHELL-TYPE-RESTRICTIONS (CADRN 1 X)))
                          T)
                      (IF (EQUAL (CADRN 1 X) 'PACK)
                          (NOT (LEGAL-CHAR-CODE-SEQ (CADRN 2 X)))
                          (IF (EQUAL (CADRN 1 X) 'MINUS)
                              (EQUAL (CADRN 2 X) (ZERO))
                              T))))))))))
	      (CONS (CADRN 1 X)
		    (EXPLICIT-VALUE-DESCRIPTOR F (CDRN 2 X)))
	      F)
      (IF (DOTTED-PAIR X)
          (FLIST3 'CONS
                  (EXPLICIT-VALUE-DESCRIPTOR T (CAR X))
                  (EXPLICIT-VALUE-DESCRIPTOR T (CADRN 2 X)))
      (IF (SINGLETON X)
          (FLIST3 'CONS
                  (EXPLICIT-VALUE-DESCRIPTOR T (CAR X))
                  (CORRESPONDING-LITATOM NIL))
          (FLIST3 'CONS
                  (EXPLICIT-VALUE-DESCRIPTOR T (CAR X))
                  (EXPLICIT-VALUE-DESCRIPTOR T (CDR X)))))))

; Here we define what it is for X to be a list of explicit value
; descriptors and the list of terms denoted by them.

      (IF (NLISTP X)
          NIL
          (FCONS (EXPLICIT-VALUE-DESCRIPTOR T (CAR X))
                 (EXPLICIT-VALUE-DESCRIPTOR F (CDR X))))))
\end{verbatim}

      

\noindent{\sc Event}:   Set the status of all events.  The status of each event is to be set as follows.  enabled.  Anything not otherwise mentioned is to be left ``as-is''.   Name this event `post-explicit-value-descriptor'.\index{post-explicit-value-descriptor}

\addvspace{18pt}

\begin{verbatim}; The function QT is just a convenient way to refer to the explicit
; value term denoted by an explicit value descriptor (or F if its
; argument is not such a descriptor).  Thus, (QT 'ABC) is '(PACK
; (CONS 65 (CONS 66 (CONS 67 0)))), except that the integers are
; actually ADD1 nests.  Read ``quotation'' for QT.

\end{verbatim}\begin{tabbing}{\sc Definition}:\index{qt}$\;\;$
{\rm{qt}}\,({\it{x\/}})\index{qt} $=$ {\rm{explicit-value-descriptor}}\,({\bf{t}}, {\it{x\/}})\index{explicit-value-descriptor}
\end{tabbing}

\begin{verbatim}; SECTION:  In Support of COND, CASE, and LET

; The next batch of functions are all involved in the translation
; of COND, CASE, and LET.  We are interested in recognizing lists
; of doublets, e.g., ((w1 v1) (w2 v2) ...), the absence of
; duplication among the wi, etc.

\end{verbatim}\begin{tabbing}{\sc Definition}:\index{doublets} \\  
\=\+{\rm{doublets}}\,({\it{lst\/}})\index{doublets} \\ 
$=$$\;\;\;\;$\=\+{\bf if }{\it{lst\/}} $\simeq\;${{\bf{nil}}}${}$$\;\;${\bf then }{\it{lst\/}} $=$ {\bf{nil}} \\ 
{\bf else }{\rm{eqlen}}\,({\rm{car}}\,({\it{lst\/}}), {\tt{2}})\index{eqlen} $\wedge$ {\rm{doublets}}\,({\rm{cdr}}\,({\it{lst\/}}))\index{doublets}$\;${\bf  endif}\-\-
\end{tabbing}

\begin{tabbing}{\sc Definition}:\index{duplicatesp} \\  
\=\+{\rm{duplicatesp}}\,({\it{lst\/}})\index{duplicatesp} \\ 
$=$$\;\;\;\;$\=\+{\bf if }{\it{lst\/}} $\simeq\;${{\bf{nil}}}${}$$\;\;${\bf then }{\bf{f}} \\ 
{\bf elseif }{\rm{car}}\,({\it{lst\/}}) $\in$ {\rm{cdr}}\,({\it{lst\/}})$\;\;${\bf then }{\bf{t}} \\ 
{\bf else }{\rm{duplicatesp}}\,({\rm{cdr}}\,({\it{lst\/}}))\index{duplicatesp}$\;${\bf  endif}\-\-
\end{tabbing}

\begin{tabbing}{\sc Definition}:\index{strip-cadrs} \\  
\=\+{\rm{strip-cadrs}}\,({\it{lst\/}})\index{strip-cadrs} \\ 
$=$$\;\;\;\;$\=\+{\bf if }{\it{lst\/}} $\simeq\;${{\bf{nil}}}${}$$\;\;${\bf then }{\bf{nil}} \\ 
{\bf else }{\rm{cons}}\,({\rm{cadrn}}\,({\tt{1}}, {\rm{car}}\,({\it{lst\/}}))\index{cadrn}, {\rm{strip-cadrs}}\,({\rm{cdr}}\,({\it{lst\/}}))\index{strip-cadrs})$\;${\bf  endif}\-\-
\end{tabbing}

\begin{tabbing}{\sc Definition}:\index{symbolps} \\  
\=\+{\rm{symbolps}}\,({\it{lst\/}})\index{symbolps} \\ 
$=$$\;\;\;\;$\=\+{\bf if }{\it{lst\/}} $\simeq\;${{\bf{nil}}}${}$$\;\;${\bf then }{\bf{t}} \\ 
{\bf else }{\rm{symbolp}}\,({\rm{car}}\,({\it{lst\/}}))\index{symbolp} $\wedge$ {\rm{symbolps}}\,({\rm{cdr}}\,({\it{lst\/}}))\index{symbolps}$\;${\bf  endif}\-\-
\end{tabbing}

\begin{verbatim}; This function applies the substitution ALIST to TERM (FLG=T) or
; to a list of terms (FLG=F).

\end{verbatim}\begin{tabbing}{\sc Definition}:\index{sublis-var} \\  
\=\+{\rm{sublis-var}}\,({\it{flg\/}}, {\it{alist\/}}, {\it{term\/}})\index{sublis-var} \\ 
$=$$\;\;\;\;$\=\+{\bf if }{\it{flg\/}} \\ 
{\bf then }\=\+{\bf if }{\it{term\/}} $\simeq\;${{\bf{nil}}}${}$ \\ 
{\bf then }\=\+{\bf if }{\rm{assoc}}\,({\it{term\/}}, {\it{alist\/}})$\;\;${\bf then }{\rm{cdr}}\,({\rm{assoc}}\,({\it{term\/}}, {\it{alist\/}})) \\ 
{\bf else }{\it{term\/}}$\;${\bf  endif}\- \\ 
{\bf elseif }{\rm{car}}\,({\it{term\/}}) $=$ {\tt{'}}{\tt{quote}}$\;\;${\bf then }{\it{term\/}} \\ 
{\bf else }{\rm{cons}}\,({\rm{car}}\,({\it{term\/}}), {\rm{sublis-var}}\,({\bf{f}}, {\it{alist\/}}, {\rm{cdr}}\,({\it{term\/}}))\index{sublis-var})$\;${\bf  endif}\- \\ 
{\bf elseif }{\it{term\/}} $\simeq\;${{\bf{nil}}}${}$$\;\;${\bf then }{\bf{nil}} \\ 
{\bf else }{\rm{cons}}\,(\=\+{\rm{sublis-var}}\,({\bf{t}}, {\it{alist\/}}, {\rm{car}}\,({\it{term\/}}))\index{sublis-var}, \\ 
{\rm{sublis-var}}\,({\bf{f}}, {\it{alist\/}}, {\rm{cdr}}\,({\it{term\/}}))\index{sublis-var})\-$\;${\bf  endif}\-\-
\end{tabbing}


\begin{verbatim}; SECTION:  In Support of FOR

; The text delays the discussion of FOR statements until after V&C$
; has been presented.  We have to deal with them now.  The fol-
; lowing functions access or check certain parts of an abbreviated
; FOR.

\end{verbatim}\begin{tabbing}{\sc Definition}:\index{abbreviated-for-var}$\;\;$
{\rm{abbreviated-for-var}}\,({\it{x\/}})\index{abbreviated-for-var} $=$ {\rm{cadrn}}\,({\tt{1}}, {\it{x\/}})\index{cadrn}
\end{tabbing}

\begin{tabbing}{\sc Definition}:\index{abbreviated-for-range}$\;\;$
{\rm{abbreviated-for-range}}\,({\it{x\/}})\index{abbreviated-for-range} $=$ {\rm{cadrn}}\,({\tt{3}}, {\it{x\/}})\index{cadrn}
\end{tabbing}

\begin{tabbing}{\sc Definition}:\index{abbreviated-for-when} \\  
\=\+{\rm{abbreviated-for-when}}\,({\it{x\/}})\index{abbreviated-for-when} \\ 
$=$$\;\;\;\;$\=\+{\bf if }{\rm{eqlen}}\,({\it{x\/}}, {\tt{8}})\index{eqlen}$\;\;${\bf then }{\rm{cadrn}}\,({\tt{5}}, {\it{x\/}})\index{cadrn} \\ 
{\bf else }{\tt{'}}{\tt{t}}$\;${\bf  endif}\-\-
\end{tabbing}

\begin{tabbing}{\sc Definition}:\index{abbreviated-for-op} \\  
\=\+{\rm{abbreviated-for-op}}\,({\it{x\/}})\index{abbreviated-for-op} \\ 
$=$$\;\;\;\;$\=\+{\bf if }{\rm{eqlen}}\,({\it{x\/}}, {\tt{8}})\index{eqlen}$\;\;${\bf then }{\rm{cadrn}}\,({\tt{6}}, {\it{x\/}})\index{cadrn} \\ 
{\bf else }{\rm{cadrn}}\,({\tt{4}}, {\it{x\/}})\index{cadrn}$\;${\bf  endif}\-\-
\end{tabbing}

\begin{tabbing}{\sc Definition}:\index{abbreviated-for-body}$\;\;$
{\rm{abbreviated-for-body}}\,({\it{x\/}})\index{abbreviated-for-body} $=$ {\rm{car}}\,({\rm{last}}\,({\it{x\/}})\index{last})
\end{tabbing}

\begin{tabbing}{\sc Definition}:\index{for-operationp} \\  
\=\+{\rm{for-operationp}}\,({\it{x\/}})\index{for-operationp} \\ 
$=$$\;\;\;\;$(\=\+({\it{x\/}} $=$ {\tt{'}}{\tt{add-to-set}}) \\ 
$\vee$$\;\;\;\;$(\=\+({\it{x\/}} $=$ {\tt{'}}{\tt{always}}) \\ 
$\vee$$\;\;\;\;$(\=\+({\it{x\/}} $=$ {\tt{'}}{\tt{append}}) \\ 
$\vee$$\;\;\;\;$(\=\+({\it{x\/}} $=$ {\tt{'}}{\tt{collect}}) \\ 
$\vee$$\;\;\;\;$(\=\+({\it{x\/}} $=$ {\tt{'}}{\tt{count}}) \\ 
$\vee$$\;\;\;\;$(\=\+({\it{x\/}} $=$ {\tt{'}}{\tt{do-return}}) \\ 
$\vee$$\;\;\;\;$(\=\+({\it{x\/}} $=$ {\tt{'}}{\tt{exists}}) \\ 
$\vee$$\;\;\;\;$(\=\+({\it{x\/}} $=$ {\tt{'}}{\tt{max}}) \\ 
$\vee$$\;\;\;\;$(\=\+({\it{x\/}} $=$ {\tt{'}}{\tt{sum}}) \\ 
$\vee$$\;\;\;\;$(\=\+({\it{x\/}} $=$ {\tt{'}}{\tt{multiply}}) \\ 
$\vee$$\;\;\;\;$({\it{x\/}} $=$ {\tt{'}}{\tt{union}}))\-)\-)\-)\-)\-)\-)\-)\-)\-)\-\-
\end{tabbing}

\begin{verbatim}; We now define the function that recognizes an abbreviated FOR.

\end{verbatim}%\item 
\begin{verbatim}


; We now define the function that recognizes an abbreviated FOR.

(DEFN ABBREVIATED-FORP (X)
  (AND (LISTP X)
   (AND (EQUAL (CAR X) 'FOR)
    (AND (OR (EQLEN X 8)
	     (EQLEN X 6))
     (AND (SYMBOLP (ABBREVIATED-FOR-VAR X))
      (AND (NOT (EQUAL (ABBREVIATED-FOR-VAR X) NIL))
       (AND (NOT (EQUAL (ABBREVIATED-FOR-VAR X) 'T))
	(AND (NOT (EQUAL (ABBREVIATED-FOR-VAR X) 'F))
	 (AND (EQUAL (CADRN 2 X) 'IN)
	  (AND (OR (EQLEN X 6)
		   (EQUAL (CADRN 4 x) 'WHEN))
	       (FOR-OPERATIONP
		(ABBREVIATED-FOR-OP X))))))))))))
\end{verbatim}


\begin{verbatim}; To translate an abbreviated FOR we must sort the list of vari-
; ables used in the WHEN clause and the BODY.

\end{verbatim}\begin{tabbing}{\sc Definition}:\index{alphabetic-lessp1} \\  
\=\+{\rm{alphabetic-lessp1}}\,({\it{l1\/}}, {\it{l2\/}})\index{alphabetic-lessp1} \\ 
$=$$\;\;\;\;$\=\+{\bf if }{\it{l1\/}} $\simeq\;${{\bf{nil}}}${}$$\;\;${\bf then }{\bf{t}} \\ 
{\bf elseif }{\it{l2\/}} $\simeq\;${{\bf{nil}}}${}$$\;\;${\bf then }{\bf{f}} \\ 
{\bf elseif }{\rm{car}}\,({\it{l1\/}}) $<$ {\rm{car}}\,({\it{l2\/}})$\;\;${\bf then }{\bf{t}} \\ 
{\bf elseif }{\rm{car}}\,({\it{l1\/}}) $=$ {\rm{car}}\,({\it{l2\/}})$\;\;${\bf then }{\rm{alphabetic-lessp1}}\,({\rm{cdr}}\,({\it{l1\/}}), {\rm{cdr}}\,({\it{l2\/}}))\index{alphabetic-lessp1} \\ 
{\bf else }{\bf{f}}$\;${\bf  endif}\-\-
\end{tabbing}

\begin{tabbing}{\sc Definition}:\index{alphabetic-lessp} \\  
{\rm{alphabetic-lessp}}\,({\it{x\/}}, {\it{y\/}})\index{alphabetic-lessp} $=$ {\rm{alphabetic-lessp1}}\,({\rm{unpack}}\,({\it{x\/}}), {\rm{unpack}}\,({\it{y\/}}))\index{alphabetic-lessp1}
\end{tabbing}

\begin{tabbing}{\sc Definition}:\index{alphabetic-insert} \\  
\=\+{\rm{alphabetic-insert}}\,({\it{x\/}}, {\it{l\/}})\index{alphabetic-insert} \\ 
$=$$\;\;\;\;$\=\+{\bf if }{\it{l\/}} $\simeq\;${{\bf{nil}}}${}$$\;\;${\bf then }{\rm{list1}}\,({\it{x\/}})\index{list1} \\ 
{\bf elseif }{\rm{alphabetic-lessp}}\,({\it{x\/}}, {\rm{car}}\,({\it{l\/}}))\index{alphabetic-lessp}$\;\;${\bf then }{\rm{cons}}\,({\it{x\/}}, {\it{l\/}}) \\ 
{\bf else }{\rm{cons}}\,({\rm{car}}\,({\it{l\/}}), {\rm{alphabetic-insert}}\,({\it{x\/}}, {\rm{cdr}}\,({\it{l\/}}))\index{alphabetic-insert})$\;${\bf  endif}\-\-
\end{tabbing}

\begin{tabbing}{\sc Definition}:\index{alphabetize} \\  
\=\+{\rm{alphabetize}}\,({\it{l\/}})\index{alphabetize} \\ 
$=$$\;\;\;\;$\=\+{\bf if }{\it{l\/}} $\simeq\;${{\bf{nil}}}${}$$\;\;${\bf then }{\it{l\/}} \\ 
{\bf else }{\rm{alphabetic-insert}}\,({\rm{car}}\,({\it{l\/}}), {\rm{alphabetize}}\,({\rm{cdr}}\,({\it{l\/}}))\index{alphabetize})\index{alphabetic-insert}$\;${\bf  endif}\-\-
\end{tabbing}

\begin{verbatim}; To collect the variable symbols that occur in a term (or list of
; terms) we use ALL-VARS.

\end{verbatim}\begin{tabbing}{\sc Definition}:\index{all-vars} \\  
\=\+{\rm{all-vars}}\,({\it{flg\/}}, {\it{x\/}})\index{all-vars} \\ 
$=$$\;\;\;\;$\=\+{\bf if }{\it{flg\/}} \\ 
{\bf then }\=\+{\bf if }{\it{x\/}} $\simeq\;${{\bf{nil}}}${}$$\;\;${\bf then }{\rm{cons}}\,({\it{x\/}}, {\bf{nil}}) \\ 
{\bf else }{\rm{all-vars}}\,({\bf{f}}, {\rm{cdr}}\,({\it{x\/}}))\index{all-vars}$\;${\bf  endif}\- \\ 
{\bf elseif }{\it{x\/}} $\simeq\;${{\bf{nil}}}${}$$\;\;${\bf then }{\bf{nil}} \\ 
{\bf else }{\rm{all-vars}}\,({\bf{t}}, {\rm{car}}\,({\it{x\/}}))\index{all-vars} $\cup$ {\rm{all-vars}}\,({\bf{f}}, {\rm{cdr}}\,({\it{x\/}}))\index{all-vars}$\;${\bf  endif}\-\-
\end{tabbing}

\begin{tabbing}{\sc Definition}:\index{standard-alist} \\  
\=\+{\rm{standard-alist}}\,({\it{vars\/}})\index{standard-alist} \\ 
$=$$\;\;\;\;$\=\+{\bf if }{\it{vars\/}} $\simeq\;${{\bf{nil}}}${}$$\;\;${\bf then }{\rm{qt}}\,({\bf{nil}})\index{qt} \\ 
{\bf else }{\rm{list3}}\,(\=\+{\tt{'}}{\tt{cons}}, \\ 
{\rm{list3}}\,({\tt{'}}{\tt{cons}}, {\rm{qt}}\,({\rm{car}}\,({\it{vars\/}}))\index{qt}, {\rm{car}}\,({\it{vars\/}}))\index{list3}, \\ 
{\rm{standard-alist}}\,({\rm{cdr}}\,({\it{vars\/}}))\index{standard-alist})\-\index{list3}$\;${\bf  endif}\-\-
\end{tabbing}

\begin{tabbing}{\sc Definition}:\index{delete} \\  
\=\+{\rm{delete}}\,({\it{x\/}}, {\it{l\/}})\index{delete} \\ 
$=$$\;\;\;\;$\=\+{\bf if }{\it{l\/}} $\simeq\;${{\bf{nil}}}${}$$\;\;${\bf then }{\it{l\/}} \\ 
{\bf elseif }{\it{x\/}} $=$ {\rm{car}}\,({\it{l\/}})$\;\;${\bf then }{\rm{cdr}}\,({\it{l\/}}) \\ 
{\bf else }{\rm{cons}}\,({\rm{car}}\,({\it{l\/}}), {\rm{delete}}\,({\it{x\/}}, {\rm{cdr}}\,({\it{l\/}}))\index{delete})$\;${\bf  endif}\-\-
\end{tabbing}

\begin{tabbing}{\sc Definition}:\index{make-alist} \\  
\=\+{\rm{make-alist}}\,({\it{var\/}}, {\it{when\/}}, {\it{body\/}})\index{make-alist} \\ 
$=$$\;\;\;\;${\rm{standard-alist}}\,({\rm{alphabetize}}\,({\rm{delete}}\,(\=\+{\it{var\/}}, \\ 
\=\+{\rm{all-vars}}\,({\bf{t}}, {\it{when\/}})\index{all-vars} \\ 
$\cup$$\;\;\;\;${\rm{all-vars}}\,({\bf{t}}, {\it{body\/}})\index{all-vars}\-)\-\index{delete})\index{alphabetize})\index{standard-alist}\-
\end{tabbing}

\begin{verbatim}; The following lemmas are used in the justification of the defi-
; nition of TRANSLATE.

\end{verbatim}\begin{tabbing}{\sc Theorem}:  lessp-abbreviated-for-range \\ \index{lessp-abbreviated-for-range}
({\rm{car}}\,({\it{x\/}}) $=$ {\tt{'}}{\tt{for}}) $\rightarrow$ ({\rm{count}}\,({\rm{abbreviated-for-range}}\,({\it{x\/}})\index{abbreviated-for-range}) $<$ {\rm{count}}\,({\it{x\/}}))
\end{tabbing}

\begin{tabbing}{\sc Theorem}:  lessp-abbreviated-for-when \\ \index{lessp-abbreviated-for-when}
({\rm{car}}\,({\it{x\/}}) $=$ {\tt{'}}{\tt{for}}) $\rightarrow$ ({\rm{count}}\,({\rm{abbreviated-for-when}}\,({\it{x\/}})\index{abbreviated-for-when}) $<$ {\rm{count}}\,({\it{x\/}}))
\end{tabbing}

\begin{tabbing}{\sc Theorem}:  lessp-last \\ \index{lessp-last}
{\rm{count}}\,({\it{x\/}}) $\not<$ {\rm{count}}\,({\rm{last}}\,({\it{x\/}})\index{last})
\end{tabbing}

\begin{tabbing}{\sc Theorem}:  lessp-abbreviated-for-body \\ \index{lessp-abbreviated-for-body}
({\rm{car}}\,({\it{x\/}}) $=$ {\tt{'}}{\tt{for}}) $\rightarrow$ ({\rm{count}}\,({\rm{abbreviated-for-body}}\,({\it{x\/}})\index{abbreviated-for-body}) $<$ {\rm{count}}\,({\it{x\/}}))
\end{tabbing}

\begin{tabbing}{\sc Theorem}:  lessp-count-strip-cars \\ \index{lessp-count-strip-cars}
{\rm{doublets}}\,({\it{lst\/}})\index{doublets} $\rightarrow$ ({\rm{count}}\,({\it{lst\/}}) $\not<$ {\rm{count}}\,({\rm{strip-cars}}\,({\it{lst\/}})))
\end{tabbing}

\begin{tabbing}{\sc Theorem}:  lessp-count-strip-cadrs \\ \index{lessp-count-strip-cadrs}
{\rm{doublets}}\,({\it{lst\/}})\index{doublets} $\rightarrow$ ({\rm{count}}\,({\it{lst\/}}) $\not<$ {\rm{count}}\,({\rm{strip-cadrs}}\,({\it{lst\/}})\index{strip-cadrs}))
\end{tabbing}

\begin{tabbing}{\sc Theorem}:  listp-cddr-x-count-x \\ \index{listp-cddr-x-count-x}
\=\+{\rm{listp}}\,({\rm{cddr}}\,({\it{x\/}})) \\ 
$\rightarrow$$\;\;\;\;$(\=\+{\rm{count}}\,({\it{x\/}}) \\ 
$=$$\;\;\;\;$($1\;+$ ($1\;+$ (\=\+{\rm{count}}\,({\rm{car}}\,({\it{x\/}})) \\ 
$+$$\;\;\;\;$({\rm{count}}\,({\rm{cadr}}\,({\it{x\/}})) $+$ {\rm{count}}\,({\rm{cddr}}\,({\it{x\/}}))))\-)))\-\-
\end{tabbing}

\begin{tabbing}{\sc Theorem}:  listp-cdddr-x-count-x \\ \index{listp-cdddr-x-count-x}
\=\+{\rm{listp}}\,({\rm{cdddr}}\,({\it{x\/}})) \\ 
$\rightarrow$$\;\;\;\;$(\=\+{\rm{count}}\,({\it{x\/}}) \\ 
$=$$\;\;\;\;$($1\;+$ ($1\;+$ ($1\;+$ (\=\+{\rm{count}}\,({\rm{car}}\,({\it{x\/}})) \\ 
$+$$\;\;\;\;$(\=\+{\rm{count}}\,({\rm{cadr}}\,({\it{x\/}})) \\ 
$+$$\;\;\;\;$(\=\+{\rm{count}}\,({\rm{caddr}}\,({\it{x\/}})) \\ 
$+$$\;\;\;\;${\rm{count}}\,({\rm{cdddr}}\,({\it{x\/}})))\-)\-)\-))))\-\-
\end{tabbing}


\begin{verbatim}; SECTION:  Translation

; We disable all definitions except CADRN and CDRN.

\end{verbatim}
\noindent{\sc Event}:   Set the status of all events.  The status of each event is to be set as follows.  disabled.  Anything not otherwise mentioned is to be left ``as-is''.   Name this event `pre-translate'.\index{pre-translate}

\addvspace{18pt}

\noindent{\sc Event}:   Enable cadrn.

\addvspace{18pt}

\noindent{\sc Event}:   Enable cdrn.

\addvspace{18pt}

\begin{verbatim}; Here, finally, is the formalization of what it is to be well-
; formed and what the translation of a well-formed term is.  If
; TRANSLATE (FLG=T) returns F, then X is not well-formed; other-
; wise, TRANSLATE (FLG=T) returns the (quotation of the) formal
; term denoted by X.  Because a formal term is either a variable
; symbol (i.e., LITATOM) or function application (i.e., LISTP), an
; answer of F unambiguously identifies the input as ill-formed.
; When FLG=F, TRANSLATE operates on a list of purported terms and
; returns either F, meaning at least one of the elements is
; ill-formed, or returns the list of their translations.

\end{verbatim}\begin{tabbing}{\sc Definition}:\index{translate} \\  
\=\+{\rm{translate}}\,({\it{flg\/}}, {\it{x\/}})\index{translate} \\ 
$=$$\;\;\;\;$\=\+{\bf if }{\it{flg\/}} \\ 
{\bf then }\=\+{\bf if }{\it{x\/}} $\simeq\;${{\bf{nil}}}${}$ \\ 
{\bf then }\=\+{\bf if }{\rm{integerp}}\,({\it{x\/}})\index{integerp}$\;\;${\bf then }{\rm{qt}}\,({\it{x\/}})\index{qt} \\ 
{\bf elseif }{\rm{symbolp}}\,({\it{x\/}})\index{symbolp} \\ 
{\bf then }\=\+{\bf if }{\it{x\/}} $=$ {\tt{'}}{\tt{t}}$\;\;${\bf then }{\rm{list1}}\,({\tt{'}}{\tt{true}})\index{list1} \\ 
{\bf elseif }{\it{x\/}} $=$ {\tt{'}}{\tt{f}}$\;\;${\bf then }{\rm{list1}}\,({\tt{'}}{\tt{false}})\index{list1} \\ 
{\bf elseif }{\it{x\/}} $=$ {\bf{nil}}$\;\;${\bf then }{\rm{qt}}\,({\bf{nil}})\index{qt} \\ 
{\bf else }{\it{x\/}}$\;${\bf  endif}\- \\ 
{\bf else }{\bf{f}}$\;${\bf  endif}\- \\ 
{\bf elseif }{\rm{dotted-s-expression}}\,({\it{x\/}})\index{dotted-s-expression}$\;\;${\bf then }{\bf{f}} \\ 
{\bf elseif }{\rm{car}}\,({\it{x\/}}) $=$ {\tt{'}}{\tt{quote}} \\ 
{\bf then }\=\+{\bf if }{\rm{eqlen}}\,({\it{x\/}}, {\tt{2}})\index{eqlen}$\;\;${\bf then }{\rm{qt}}\,({\rm{cadrn}}\,({\tt{1}}, {\it{x\/}})\index{cadrn})\index{qt} \\ 
{\bf else }{\bf{f}}$\;${\bf  endif}\- \\ 
{\bf elseif }{\rm{car}}\,({\it{x\/}}) $=$ {\tt{'}}{\tt{cond}} \\ 
{\bf then }\=\+{\bf if }\=\+{\rm{eqlen}}\,({\it{x\/}}, {\tt{2}})\index{eqlen} \\ 
$\wedge$$\;\;\;\;$(\=\+{\rm{eqlen}}\,({\rm{cadrn}}\,({\tt{1}}, {\it{x\/}})\index{cadrn}, {\tt{2}})\index{eqlen} \\ 
$\wedge$$\;\;\;\;$({\rm{car}}\,({\rm{cadrn}}\,({\tt{1}}, {\it{x\/}})\index{cadrn}) $=$ {\tt{'}}{\tt{t}}))\-\- \\ 
{\bf then }{\rm{translate}}\,({\bf{t}}, {\rm{cadrn}}\,({\tt{1}}, {\rm{cadrn}}\,({\tt{1}}, {\it{x\/}})\index{cadrn})\index{cadrn})\index{translate} \\ 
{\bf elseif }\=\+{\rm{eqlen}}\,({\rm{cadrn}}\,({\tt{1}}, {\it{x\/}})\index{cadrn}, {\tt{2}})\index{eqlen} \\ 
$\wedge$$\;\;\;\;$(\=\+({\rm{car}}\,({\rm{cadrn}}\,({\tt{1}}, {\it{x\/}})\index{cadrn}) $\not=$ {\tt{'}}{\tt{t}}) \\ 
$\wedge$$\;\;\;\;${\rm{listp}}\,({\rm{cdrn}}\,({\tt{2}}, {\it{x\/}})\index{cdrn}))\-\- \\ 
{\bf then }{\rm{flist4}}\,(\=\+{\tt{'}}{\tt{if}}, \\ 
{\rm{translate}}\,({\bf{t}}, {\rm{car}}\,({\rm{cadrn}}\,({\tt{1}}, {\it{x\/}})\index{cadrn}))\index{translate}, \\ 
{\rm{translate}}\,({\bf{t}}, {\rm{cadrn}}\,({\tt{1}}, {\rm{cadrn}}\,({\tt{1}}, {\it{x\/}})\index{cadrn})\index{cadrn})\index{translate}, \\ 
{\rm{translate}}\,({\bf{t}}, {\rm{cons}}\,({\tt{'}}{\tt{cond}}, {\rm{cdrn}}\,({\tt{2}}, {\it{x\/}})\index{cdrn}))\index{translate})\-\index{flist4} \\ 
{\bf else }{\bf{f}}$\;${\bf  endif}\- \\ 
{\bf elseif }{\rm{car}}\,({\it{x\/}}) $=$ {\tt{'}}{\tt{case}} \\ 
{\bf then }\=\+{\bf if }\=\+{\rm{eqlen}}\,({\it{x\/}}, {\tt{3}})\index{eqlen} \\ 
$\wedge$$\;\;\;\;$(\=\+{\rm{eqlen}}\,({\rm{cadrn}}\,({\tt{2}}, {\it{x\/}})\index{cadrn}, {\tt{2}})\index{eqlen} \\ 
$\wedge$$\;\;\;\;$(\=\+({\rm{car}}\,({\rm{cadrn}}\,({\tt{2}}, {\it{x\/}})\index{cadrn}) $=$ {\tt{'}}{\tt{otherwise}}) \\ 
$\wedge$$\;\;\;\;${\rm{translate}}\,({\bf{t}}, {\rm{cadrn}}\,({\tt{1}}, {\it{x\/}})\index{cadrn})\index{translate})\-)\-\- \\ 
{\bf then }{\rm{translate}}\,({\bf{t}}, {\rm{cadrn}}\,({\tt{1}}, {\rm{cadrn}}\,({\tt{2}}, {\it{x\/}})\index{cadrn})\index{cadrn})\index{translate} \\ 
{\bf elseif }\=\+{\rm{eqlen}}\,({\rm{cadrn}}\,({\tt{2}}, {\it{x\/}})\index{cadrn}, {\tt{2}})\index{eqlen} \\ 
$\wedge$$\;\;\;\;$(\=\+{\rm{listp}}\,({\rm{cdrn}}\,({\tt{3}}, {\it{x\/}})\index{cdrn}) \\ 
$\wedge$$\;\;\;\;$(\=\+{\rm{car}}\,({\rm{cadrn}}\,({\tt{2}}, {\it{x\/}})\index{cadrn}) \\ 
$\not\in$$\;\;\;\;${\rm{strip-cars}}\,({\rm{cdrn}}\,({\tt{3}}, {\it{x\/}})\index{cdrn}))\-)\-\- \\ 
{\bf then }{\rm{flist4}}\,(\=\+{\tt{'}}{\tt{if}}, \\ 
{\rm{flist3}}\,(\=\+{\tt{'}}{\tt{equal}}, \\ 
{\rm{translate}}\,({\bf{t}}, {\rm{cadrn}}\,({\tt{1}}, {\it{x\/}})\index{cadrn})\index{translate}, \\ 
{\rm{qt}}\,({\rm{car}}\,({\rm{cadrn}}\,({\tt{2}}, {\it{x\/}})\index{cadrn}))\index{qt})\-\index{flist3}, \\ 
{\rm{translate}}\,({\bf{t}}, {\rm{cadrn}}\,({\tt{1}}, {\rm{cadrn}}\,({\tt{2}}, {\it{x\/}})\index{cadrn})\index{cadrn})\index{translate}, \\ 
{\rm{translate}}\,(\=\+{\bf{t}}, \\ 
{\rm{cons}}\,(\=\+{\tt{'}}{\tt{case}}, \\ 
{\rm{cons}}\,({\rm{cadrn}}\,({\tt{1}}, {\it{x\/}})\index{cadrn}, {\rm{cdrn}}\,({\tt{3}}, {\it{x\/}})\index{cdrn}))\-)\-\index{translate})\-\index{flist4} \\ 
{\bf else }{\bf{f}}$\;${\bf  endif}\- \\ 
{\bf elseif }{\rm{car}}\,({\it{x\/}}) $=$ {\tt{'}}{\tt{let}} \\ 
{\bf then }\=\+{\bf if }{\rm{doublets}}\,({\rm{cadrn}}\,({\tt{1}}, {\it{x\/}})\index{cadrn})\index{doublets} \\ 
{\bf then }\=\+{\bf if }\=\+{\rm{eqlen}}\,({\it{x\/}}, {\tt{3}})\index{eqlen} \\ 
$\wedge$$\;\;\;\;$(\=\+{\rm{translate}}\,({\bf{f}}, {\rm{strip-cars}}\,({\rm{cadrn}}\,({\tt{1}}, {\it{x\/}})\index{cadrn}))\index{translate} \\ 
$\wedge$$\;\;\;\;$(\=\+{\rm{translate}}\,(\=\+{\bf{f}}, \\ 
{\rm{strip-cadrs}}\,({\rm{cadrn}}\,({\tt{1}}, {\it{x\/}})\index{cadrn})\index{strip-cadrs})\-\index{translate} \\ 
$\wedge$$\;\;\;\;$(\=\+{\rm{translate}}\,({\bf{t}}, {\rm{cadrn}}\,({\tt{2}}, {\it{x\/}})\index{cadrn})\index{translate} \\ 
$\wedge$$\;\;\;\;$(\=\+{\rm{symbolps}}\,({\rm{translate}}\,(\=\+{\bf{f}}, \\ 
{\rm{strip-cars}}\,({\rm{cadrn}}\,(\=\+{\tt{1}}, \\ 
{\it{x\/}})\-\index{cadrn}))\-\index{translate})\index{symbolps} \\ 
$\wedge$$\;\;\;\;$($\neg$ {\rm{duplicatesp}}\,({\rm{translate}}\,(\=\+{\bf{f}}, \\ 
{\rm{strip-cars}}\,({\rm{cadrn}}\,(\=\+{\tt{1}}, \\ 
{\it{x\/}})\-\index{cadrn}))\-\index{translate})\index{duplicatesp}))\-)\-)\-)\-\- \\ 
{\bf then }{\rm{sublis-var}}\,(\=\+{\bf{t}}, \\ 
{\rm{pairlist}}\,(\=\+{\rm{translate}}\,(\=\+{\bf{f}}, \\ 
{\rm{strip-cars}}\,({\rm{cadrn}}\,(\=\+{\tt{1}}, \\ 
{\it{x\/}})\-\index{cadrn}))\-\index{translate}, \\ 
{\rm{translate}}\,(\=\+{\bf{f}}, \\ 
{\rm{strip-cadrs}}\,({\rm{cadrn}}\,(\=\+{\tt{1}}, \\ 
{\it{x\/}})\-\index{cadrn})\index{strip-cadrs})\-\index{translate})\-, \\ 
{\rm{translate}}\,({\bf{t}}, {\rm{cadrn}}\,({\tt{2}}, {\it{x\/}})\index{cadrn})\index{translate})\-\index{sublis-var} \\ 
{\bf else }{\bf{f}}$\;${\bf  endif}\- \\ 
{\bf else }{\bf{f}}$\;${\bf  endif}\- \\ 
{\bf elseif }$\neg$ {\rm{translate}}\,({\bf{f}}, {\rm{cdr}}\,({\it{x\/}}))\index{translate}$\;\;${\bf then }{\bf{f}} \\ 
{\bf elseif }\=\+({\rm{car}}\,({\it{x\/}}) $=$ {\bf{nil}}) \\ 
$\vee$$\;\;\;\;$(({\rm{car}}\,({\it{x\/}}) $=$ {\tt{'}}{\tt{t}}) $\vee$ ({\rm{car}}\,({\it{x\/}}) $=$ {\tt{'}}{\tt{f}}))\-$\;\;${\bf then }{\bf{f}} \\ 
{\bf elseif }{\rm{car}}\,({\it{x\/}}) $=$ {\tt{'}}{\tt{list}} \\ 
{\bf then }{\rm{fn-nest}}\,({\tt{'}}{\tt{cons}}, {\rm{translate}}\,({\bf{f}}, {\rm{cdr}}\,({\it{x\/}}))\index{translate}, {\rm{qt}}\,({\bf{nil}})\index{qt})\index{fn-nest} \\ 
{\bf elseif }{\rm{car}}\,({\it{x\/}}) $=$ {\tt{'}}{\tt{list*}} \\ 
{\bf then }\=\+{\bf if }{\rm{eqlen}}\,({\it{x\/}}, {\tt{1}})\index{eqlen}$\;\;${\bf then }{\bf{f}} \\ 
{\bf else }{\rm{fn-nest}}\,(\=\+{\tt{'}}{\tt{cons}}, \\ 
{\rm{all-but-last}}\,({\rm{translate}}\,({\bf{f}}, {\rm{cdr}}\,({\it{x\/}}))\index{translate})\index{all-but-last}, \\ 
{\rm{car}}\,({\rm{last}}\,({\rm{translate}}\,({\bf{f}}, {\rm{cdr}}\,({\it{x\/}}))\index{translate})\index{last}))\-\index{fn-nest}$\;${\bf  endif}\- \\ 
{\bf elseif }{\rm{car-cdr-symbolp}}\,({\rm{car}}\,({\it{x\/}}))\index{car-cdr-symbolp} \\ 
{\bf then }\=\+{\bf if }{\rm{eqlen}}\,({\it{x\/}}, {\tt{2}})\index{eqlen} \\ 
{\bf then }{\rm{car-cdr-nest}}\,(\=\+{\rm{a-d-sequence}}\,({\rm{car}}\,({\it{x\/}}))\index{a-d-sequence}, \\ 
{\rm{translate}}\,({\bf{t}}, {\rm{cadrn}}\,({\tt{1}}, {\it{x\/}})\index{cadrn})\index{translate})\-\index{car-cdr-nest} \\ 
{\bf else }{\bf{f}}$\;${\bf  endif}\- \\ 
{\bf elseif }{\rm{eqlen}}\,({\rm{cdr}}\,({\it{x\/}}), {\rm{arity}}\,({\rm{car}}\,({\it{x\/}}))\index{arity})\index{eqlen} \\ 
{\bf then }{\rm{fcons}}\,({\rm{car}}\,({\it{x\/}}), {\rm{translate}}\,({\bf{f}}, {\rm{cdr}}\,({\it{x\/}}))\index{translate})\index{fcons} \\ 
{\bf elseif }{\rm{car}}\,({\it{x\/}}) $=$ {\tt{'}}{\tt{for}} \\ 
{\bf then }\=\+{\bf if }{\rm{abbreviated-forp}}\,({\it{x\/}})\index{abbreviated-forp} \\ 
{\bf then }{\rm{flist7}}\,(\=\+{\tt{'}}{\tt{for}}, \\ 
{\rm{qt}}\,({\rm{abbreviated-for-var}}\,({\it{x\/}})\index{abbreviated-for-var})\index{qt}, \\ 
{\rm{translate}}\,({\bf{t}}, {\rm{abbreviated-for-range}}\,({\it{x\/}})\index{abbreviated-for-range})\index{translate}, \\ 
{\rm{qt}}\,({\rm{translate}}\,({\bf{t}}, {\rm{abbreviated-for-when}}\,({\it{x\/}})\index{abbreviated-for-when})\index{translate})\index{qt}, \\ 
{\rm{qt}}\,({\rm{abbreviated-for-op}}\,({\it{x\/}})\index{abbreviated-for-op})\index{qt}, \\ 
{\rm{qt}}\,({\rm{translate}}\,({\bf{t}}, {\rm{abbreviated-for-body}}\,({\it{x\/}})\index{abbreviated-for-body})\index{translate})\index{qt}, \\ 
{\rm{make-alist}}\,(\=\+{\rm{abbreviated-for-var}}\,({\it{x\/}})\index{abbreviated-for-var}, \\ 
{\rm{translate}}\,({\bf{t}}, {\rm{abbreviated-for-when}}\,({\it{x\/}})\index{abbreviated-for-when})\index{translate}, \\ 
{\rm{translate}}\,({\bf{t}}, {\rm{abbreviated-for-body}}\,({\it{x\/}})\index{abbreviated-for-body})\index{translate})\-\index{make-alist})\-\index{flist7} \\ 
{\bf else }{\bf{f}}$\;${\bf  endif}\- \\ 
{\bf elseif }\=\+({\tt{2}} $<$ {\rm{length}}\,({\rm{cdr}}\,({\it{x\/}}))\index{length}) \\ 
$\wedge$$\;\;\;\;$(\=\+({\rm{car}}\,({\it{x\/}}) $=$ {\tt{'}}{\tt{and}}) \\ 
$\vee$$\;\;\;\;$(\=\+({\rm{car}}\,({\it{x\/}}) $=$ {\tt{'}}{\tt{or}}) \\ 
$\vee$$\;\;\;\;$(\=\+({\rm{car}}\,({\it{x\/}}) $=$ {\tt{'}}{\tt{plus}}) \\ 
$\vee$$\;\;\;\;$({\rm{car}}\,({\it{x\/}}) $=$ {\tt{'}}{\tt{times}}))\-)\-)\-\- \\ 
{\bf then }{\rm{fn-nest}}\,(\=\+{\rm{car}}\,({\it{x\/}}), \\ 
{\rm{all-but-last}}\,({\rm{translate}}\,({\bf{f}}, {\rm{cdr}}\,({\it{x\/}}))\index{translate})\index{all-but-last}, \\ 
{\rm{car}}\,({\rm{last}}\,({\rm{translate}}\,({\bf{f}}, {\rm{cdr}}\,({\it{x\/}}))\index{translate})\index{last}))\-\index{fn-nest} \\ 
{\bf else }{\bf{f}}$\;${\bf  endif}\- \\ 
{\bf elseif }{\it{x\/}} $\simeq\;${{\bf{nil}}}${}$$\;\;${\bf then }{\bf{nil}} \\ 
{\bf else }{\rm{fcons}}\,({\rm{translate}}\,({\bf{t}}, {\rm{car}}\,({\it{x\/}}))\index{translate}, {\rm{translate}}\,({\bf{f}}, {\rm{cdr}}\,({\it{x\/}}))\index{translate})\index{fcons}$\;${\bf  endif}\-\-
\end{tabbing}


\noindent{\sc Event}:   Set the status of all events.  The status of each event is to be set as follows.  enabled.  Anything not otherwise mentioned is to be left ``as-is''.   Name this event `post-translate'.\index{post-translate}

\addvspace{18pt}


\begin{verbatim}; SECTION:  The Extended Syntax

; Finally, here is EXSYN, which reads an s-expression from a stream
; of ASCII character codes and translates it into a formal term or
; returns F if the stream is not the display of a term in the ex-
; tended syntax.

\end{verbatim}\begin{tabbing}{\sc Definition}:\index{exsyn} \\  
\=\+{\rm{exsyn}}\,({\it{stream\/}})\index{exsyn} \\ 
$=$$\;\;\;\;$\=\+{\bf if }{\rm{readable}}\,({\rm{read-token-tree}}\,({\it{stream\/}})\index{read-token-tree}, {\tt{0}})\index{readable} \\ 
{\bf then }{\rm{translate}}\,({\bf{t}}, {\rm{readmacro-expansion}}\,({\rm{read-token-tree}}\,({\it{stream\/}})\index{read-token-tree})\index{readmacro-expansion})\index{translate} \\ 
{\bf else }{\bf{f}}$\;${\bf  endif}\-\-
\end{tabbing}

\begin{verbatim}; EXSYN returns F if the stream cannot be parsed.  The explanation
; of this remark is that an unparsable stream causes READ-TOKEN-
; TREE to return F and READABLE returns F on that input.

; SECTION:  Slightly Abbreviated Formal Terms

; It is exceedingly difficult to read the output of TRANSLATE and
; EXSYN because quoted literal atoms and numbers are exploded.
; Thus 'ABC translates to (PACK (CONS (ADD1 ...)  ...))  where the
; ellipses are very large nests of CONSes and ADD1s.  Below, we
; develop a function that can be used to massage the output of
; TRANSLATE to introduce QUOTE notation for LITATOMs and to intro-
; duce the normal decimal representation for ADD1 nests.  While
; this convention is employed in Chapter 4, e.g., when we exhibit
; two token trees with the same translation, the concepts
; formalized below are not defined in the text.

; If X is an ADD1-nest n deep with a (ZERO) at the bottom, we
; return n; otherwise F.  The variable I is used as an accumulator
; and should be 0 at the top-level.

\end{verbatim}\begin{tabbing}{\sc Definition}:\index{add1-nestp} \\  
\=\+{\rm{add1-nestp}}\,({\it{x\/}}, {\it{i\/}})\index{add1-nestp} \\ 
$=$$\;\;\;\;$\=\+{\bf if }{\it{x\/}} $\simeq\;${{\bf{nil}}}${}$$\;\;${\bf then }{\bf{f}} \\ 
{\bf elseif }({\rm{car}}\,({\it{x\/}}) $=$ {\tt{'}}{\tt{zero}}) $\wedge$ {\rm{eqlen}}\,({\it{x\/}}, {\tt{1}})\index{eqlen}$\;\;${\bf then }{\it{i\/}} \\ 
{\bf elseif }({\rm{car}}\,({\it{x\/}}) $=$ {\tt{'}}{\tt{add1}}) $\wedge$ {\rm{eqlen}}\,({\it{x\/}}, {\tt{2}})\index{eqlen} \\ 
{\bf then }{\rm{add1-nestp}}\,({\rm{cadrn}}\,({\tt{1}}, {\it{x\/}})\index{cadrn}, $1\;+$ {\it{i\/}})\index{add1-nestp} \\ 
{\bf else }{\bf{f}}$\;${\bf  endif}\-\-
\end{tabbing}
	       
\begin{tabbing}{\sc Definition}:\index{cons-add1-nestp} \\  
\=\+{\rm{cons-add1-nestp}}\,({\it{x\/}})\index{cons-add1-nestp} \\ 
$=$$\;\;\;\;$\=\+{\bf if }{\it{x\/}} $\simeq\;${{\bf{nil}}}${}$$\;\;${\bf then }{\bf{f}} \\ 
{\bf elseif }({\rm{car}}\,({\it{x\/}}) $=$ {\tt{'}}{\tt{zero}}) $\wedge$ {\rm{eqlen}}\,({\it{x\/}}, {\tt{1}})\index{eqlen}$\;\;${\bf then }{\tt{0}} \\ 
{\bf elseif }({\rm{car}}\,({\it{x\/}}) $=$ {\tt{'}}{\tt{cons}}) $\wedge$ {\rm{eqlen}}\,({\it{x\/}}, {\tt{3}})\index{eqlen} \\ 
{\bf then }{\rm{fcons}}\,({\rm{add1-nestp}}\,({\rm{cadrn}}\,({\tt{1}}, {\it{x\/}})\index{cadrn}, {\tt{0}})\index{add1-nestp}, {\rm{cons-add1-nestp}}\,({\rm{cadrn}}\,({\tt{2}}, {\it{x\/}})\index{cadrn})\index{cons-add1-nestp})\index{fcons} \\ 
{\bf else }{\bf{f}}$\;${\bf  endif}\-\-
\end{tabbing}
	      
\begin{tabbing}{\sc Definition}:\index{exploded-litatom} \\  
\=\+{\rm{exploded-litatom}}\,({\it{x\/}})\index{exploded-litatom} \\ 
$=$$\;\;\;\;$\=\+{\bf if }\=\+{\rm{eqlen}}\,({\it{x\/}}, {\tt{2}})\index{eqlen} \\ 
$\wedge$$\;\;\;\;$(({\rm{car}}\,({\it{x\/}}) $=$ {\tt{'}}{\tt{pack}}) $\wedge$ {\rm{cons-add1-nestp}}\,({\rm{cadrn}}\,({\tt{1}}, {\it{x\/}})\index{cadrn})\index{cons-add1-nestp})\- \\ 
{\bf then }{\rm{list2}}\,({\tt{'}}{\tt{quote}}, {\rm{pack}}\,({\rm{cons-add1-nestp}}\,({\rm{cadrn}}\,({\tt{1}}, {\it{x\/}})\index{cadrn})\index{cons-add1-nestp}))\index{list2} \\ 
{\bf else }{\bf{f}}$\;${\bf  endif}\-\-
\end{tabbing}

\begin{tabbing}{\sc Definition}:\index{abbrev} \\  
\=\+{\rm{abbrev}}\,({\it{flg\/}}, {\it{x\/}})\index{abbrev} \\ 
$=$$\;\;\;\;$\=\+{\bf if }{\it{flg\/}} \\ 
{\bf then }\=\+{\bf if }{\it{x\/}} $\simeq\;${{\bf{nil}}}${}$$\;\;${\bf then }{\it{x\/}} \\ 
{\bf elseif }{\rm{add1-nestp}}\,({\it{x\/}}, {\tt{0}})\index{add1-nestp}$\;\;${\bf then }{\rm{add1-nestp}}\,({\it{x\/}}, {\tt{0}})\index{add1-nestp} \\ 
{\bf elseif }{\rm{exploded-litatom}}\,({\it{x\/}})\index{exploded-litatom}$\;\;${\bf then }{\rm{exploded-litatom}}\,({\it{x\/}})\index{exploded-litatom} \\ 
{\bf else }{\rm{cons}}\,({\rm{car}}\,({\it{x\/}}), {\rm{abbrev}}\,({\bf{f}}, {\rm{cdr}}\,({\it{x\/}}))\index{abbrev})$\;${\bf  endif}\- \\ 
{\bf elseif }{\it{x\/}} $\simeq\;${{\bf{nil}}}${}$$\;\;${\bf then }{\bf{nil}} \\ 
{\bf else }{\rm{cons}}\,({\rm{abbrev}}\,({\bf{t}}, {\rm{car}}\,({\it{x\/}}))\index{abbrev}, {\rm{abbrev}}\,({\bf{f}}, {\rm{cdr}}\,({\it{x\/}}))\index{abbrev})$\;${\bf  endif}\-\-
\end{tabbing}

\begin{verbatim}; Here is a version of EXSYN that uses abbreviations.

\end{verbatim}\begin{tabbing}{\sc Definition}:\index{aexsyn} \\  
\=\+{\rm{aexsyn}}\,({\it{stream\/}})\index{aexsyn} \\ 
$=$$\;\;\;\;$\=\+{\bf if }{\rm{readable}}\,({\rm{read-token-tree}}\,({\it{stream\/}})\index{read-token-tree}, {\tt{0}})\index{readable} \\ 
{\bf then }{\rm{abbrev}}\,(\=\+{\bf{t}}, \\ 
{\rm{translate}}\,({\bf{t}}, {\rm{readmacro-expansion}}\,({\rm{read-token-tree}}\,({\it{stream\/}})\index{read-token-tree})\index{readmacro-expansion})\index{translate})\-\index{abbrev} \\ 
{\bf else }{\bf{f}}$\;${\bf  endif}\-\-
\end{tabbing}      

\begin{verbatim}#|

Here are Common Lisp interfaces to EXSYN and AEXSYN.

 (defun exsyn (string)
  (*1*exsyn (ascii string)))

 (defun aexsyn (string)
  (*1*aexsyn (ascii string)))

|#

; We conclude by making a compiled library containing the current
; data base.  If one executes (NOTE-LIB ".../examples/basic/parser"
; T) in Nqthm, where the ellipsis is meant to be the local
; directory containing our examples subdirectory, then one can use
; R-LOOP to execute these function.  For example, one can type to
; R-LOOP:

;(AEXSYN
; (ASCII
; '(OPEN-PAREN
;   LOWER-A LOWER-D LOWER-D DIGIT-ONE
;   SPACE
;   NUMBER-SIGN VERTICAL-BAR
;   UPPER-C LOWER-O LOWER-M LOWER-M LOWER-E LOWER-N LOWER-T
;   VERTICAL-BAR NUMBER-SIGN
;   LOWER-X
;   CLOSE-PAREN)))

; and get the result '(ADD X).

; This is sufficiently cumbersome that we find the Lisp interface
; functions much more convenient.  If the ``defuns'' in this file
; are executed in an acceptable Common Lisp, then it is possible to
; type to Common Lisp (rather than R-LOOP):

; (aexsyn "(add1 #|Comment|#x)")

; and get the result (ADD1 X).  The Lisp routine aexsyn actually
; executes our logical function AEXSYN but it first converts the
; string argument into a list of ASCII characters.

\end{verbatim}
\noindent{\sc Event}:   Make the library {\tt{"parser"}} and compile it.

\addvspace{18pt}

%\end{list}
\printindex
\end{document}
