DataMuseum.dk

Presents historical artifacts from the history of:

DKUUG/EUUG Conference tapes

This is an automatic "excavation" of a thematic subset of
artifacts from Datamuseum.dk's BitArchive.

See our Wiki for more about DKUUG/EUUG Conference tapes

Excavated with: AutoArchaeologist - Free & Open Source Software.


top - download
Index: ┃ T r

⟦350f7f63c⟧ TextFile

    Length: 141434 (0x2287a)
    Types: TextFile
    Names: »rrrs.ytex.327«

Derivation

└─⟦a0efdde77⟧ Bits:30001252 EUUGD11 Tape, 1987 Spring Conference Helsinki
    └─ ⟦this⟧ »EUUGD11/gnu-31mar87/scheme/rrrs.ytex.327« 

TextFile

% for YTex
\typesize=11pt
\noheaders
\runninghead={The Revised Revised Report on Scheme}

\vskip 5pc

\tcenter{\the\titlefont The Revised Revised Report on Scheme}

\vskip 1pc

\tcenter{\the\titlefont or}

\vskip 1pc

\tcenter{\the\titlefont An UnCommon Lisp}

\vskip 1pc

\tcenter{\biggsize\rm August 1985}

\vskip 1truein
\centerline{
\begintable[ll]
Hal Abelson&Chris Haynes\cr
Norman Adams&Eugene Kohlbecker\cr
David Bartley&Don Oxley\cr
Gary Brooks&Kent Pitman\cr
William Clinger [editor]&Jonathan Rees\cr
Dan Friedman&Bill Rozas\cr
Robert Halstead&Gerald Jay Sussman\cr
Chris Hanson&Mitchell Wand\cr
\endtable
}
\vskip 4pc

\heading{\bf Abstract}
\vskip 1pc
\vpar
\begintext
       Data and procedures and the values they amass,
       Higher-order functions to combine and mix and match,
       Objects with their local state, the messages they pass,
       A property, a package, the control point for a catch---
       In the Lambda Order they are all first-class.
       One Thing to name them all, One Thing to define them,
       One Thing to place them in environments and bind them,
       In the Lambda Order they are all first-class.
\endtext
\filpage


\tcenter{\bf Table of Contents}
 
\vskip 2pc

\vpar
Acknowledgements\space\space\space 3
\vpar

Part I: Introduction to Scheme\space\space\space 4

\begintext
     I.0     Brief history of Scheme   4
     I.1     Syntax of Scheme   5
     I.2     Semantics of Scheme   7

\endtext

\vpar
Part II: A catalog of Scheme\space\space\space 9

\begintext
    II.0    Notational conventions   9
    II.1    Special forms   11
    II.2    Booleans   22
    II.3    Equivalence predicates   24
    II.4    Pairs and lists   26
    II.5    Symbols   33
    II.6    Numbers   35
    II.7    Characters   48
    II.8    Strings   51
    II.9    Vectors   54
    II.10   The object table   56
    II.11   Procedures   57
    II.12   Ports   61
    II.13   Input   63
    II.14   Output   65

\endtext
\vpar

Bibliography and References\space\space\space 67
 
\vpar
Index\space\space\space 70

\filpage


\section{\bf Acknowledgements}

\unvpar
This report is primarily the work of a group of people who met at
Brandeis University for two days in October 1984.  Participating in
that workshop were Hal Abelson, Norman Adams, David Bartley, Gary
Brooks, William Clinger, Dan Friedman, Robert Halstead, Chris Hanson,
Chris Haynes, Eugene Kohlbecker, Don Oxley, Jonathan Rees, Bill Rozas,
Gerald Sussman, and Mitchell Wand.  Kent Pitman made valuable
contributions to the agenda for the workshop but was unable to attend
the sessions.

\vskip 1pc
\vpar
We would like to thank the following people for their comments and
criticisms in the months following the workshop: George Carrette, Kent
Dybvig, Andy Freeman, Yekta Gursel, Paul Hudak, Chris Lindblad, John
Ramsdell, and Guy Steele Jr.

\vskip 1pc
\vpar
We thank Carol Fessenden, Dan Friedman, and Chris Haynes for
permission to use text from the Scheme 311 Version 4 reference manual.
We thank Gerry Sussman for drafting the chapter on numbers, Chris
Hanson for drafting the chapters on characters and strings, and Gary
Brooks and William Clinger for drafting the chapters on input and
output.  We gladly acknowledge the influence of manuals for MIT
Scheme, T, Scheme 84, and Common Lisp.

\vskip 1pc
\vpar
We also thank Betty Dexter for the extreme effort she
put into setting this report in \ytex, and Don Knuth for designing the
program that caused her troubles.

\vskip 1pc
\vpar
We intend this report to belong to the entire Scheme community, and so
we grant permission to copy it in whole or in part without fee.  In
particular, we encourage implementors of Scheme to use this report as
a starting point for manuals and other documentation, modifying it as
necessary.

\vskip 1pc
\vpar
{\it Editor's note:} This report records the unanimous decisions made
through a remarkable spirit of compromise at Brandeis, together with
the fruits of subsequent committee work and discussions made possible
by various computer networks.  I have tried to edit these into a
coherent document while remaining faithful to the workshop's decisions
and the community's consensus.  I apologize for any cases in which I
have misinterpreted the authors or misjudged the consensus.

\spread { }{William Clinger}
\filpage

\chapter{Part I:  Introduction to Scheme}
 
 
\section{I.0  Brief history of Scheme}

\unvpar Scheme is a statically scoped and properly tail-recursive
dialect of the Lisp programming language invented by Guy Lewis Steele
Jr and Gerald Jay Sussman.  It was designed to have an exceptionally
clear and simple semantics and very few different methods of
expression formation.

\vskip 1pc
\vpar
The first description of Scheme was written in 1975 [28].  A Revised
Report [24] appeared in 1978, which described the evolution of the
language as its MIT implementation was upgraded to support an
innovative compiler [21].  Three distinct projects began in 1981 and
1982 to use variants of Scheme for courses at MIT, Yale, and Indiana
University [11, 14, 4].  An introductory computer science
textbook using Scheme was published in 1984 [1].

\vskip 1pc
\vpar
As might be expected of a language used primarily for education and
research, Scheme has always evolved rapidly.  This was no problem when
Scheme was used only within MIT, but as Scheme became more widespread
local subdialects began to diverge until students and researchers
occasionally found it difficult to understand code written at other
sites.  Fifteen representatives of the major implementations of Scheme
therefore met in October 1984 to work toward a better and more widely
accepted standard for Scheme.  This paper reports their unanimous
recommendations augmented by committee work in the areas of
arithmetic, characters, strings, and input/output.

\vskip 1pc
\vpar
Scheme shares with Common Lisp [23] the goal of a core language common
to several implementations.  Scheme differs from Common Lisp in its
emphasis upon simplicity and function over compatibility with older
dialects of Lisp.
\filpage


\section{I.1  Syntax}
 
\unvpar
Formal definitions of the lexical and context-free syntaxes of Scheme
will be included in a separate report.
 

\section{Identifiers}

\unvpar
Most identifiers allowed by other programming languages are also
acceptable to Scheme.  The precise rules for forming identifiers vary
among implementations of Scheme, but in all implementations a sequence
of characters that contains no special characters and begins with a
character that cannot begin a number is an identifier.  There may be
other identifiers as well, and in particular the following are
identifiers:

\tcenter
{\tt + $\ $ - $\ $ 1+ $\ $ -1+}

\noindent
It is guaranteed that the following characters cannot begin a number,
so identifiers other than the four listed above should begin with one
of:

\begintcenter
{\tt
a b c d e f g h i j k l m n o p q r s t u v w x y z \\
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z \\
! \verb"$" \verb"%" \verb"&" * / : < = > ? \verb"~"}
\endtcenter


\noindent
Subsequent characters of the identifier should be drawn from:

\begintcenter
{\tt
a b c d e f g h i j k l m n o p q r s t u v w x y z\cr
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z\cr
0 1 2 3 4 5 6 7 8 9\cr
! \verb"$" \verb"%" \verb"&" * / : < = > ? \verb"^" \verb"_" . \verb"~"}
\endtcenter

\vpar
The case in which the letters of an identifier are typed is
immaterial.  For example, {\tt Foo} is the same identifier as {\tt FOO}.

\vskip 1pc
\vpar
The following characters are special, and should never be used in an
identifier:

\begintcenter{\tt
\verb_) ( ] [ } {  " ;_ {\it blank}}
\endtcenter

\vpar
Scheme deliberately does not specify whether the following characters
can be used in identifiers:

\begintcenter{\tt
\verb"#" ' ` , @ \verb"\" |}
\endtcenter

\vpar
{\it Rationale:} Some implementations might want to use backslash
($\backslash$) and
vertical bar \verb_(|)_ as in Common Lisp.  As for the others there are two
schools of thought.  One school argues that disallowing special
characters in identifiers allows the computer to catch more typing
errors.  The other school agrees only for special characters that come
in pairs, on the grounds that errors involving only the unpaired
special characters are easier to see.
 
 
\section{Numbers}

\unvpar
For a description of the notations used for numbers, see section II.6.

\section{Comments}

\unvpar
A semicolon indicates the start of a comment.  The comment continues
to the end of the line on which the semicolon appears.  Comments are
invisible to Scheme, but the end of the line is visible as whitespace.
This prevents a comment from appearing in the middle of an identifier
or number.

\section{Other notations}

\unvpar
Left and right parentheses are used for grouping and to notate lists
as described in section II.4.  Left and right square brackets and
curly braces are not used in Scheme right now but are reserved for
unspecified future uses.

\vskip 1pc
\vpar
The quote \verb_(')_ and backquote \verb_(`)_ characters are used to indicate
constant or almost-constant data as described in section II.1.  The
comma is used together with the backquote, and the atsign \verb_(@)_ is used
together with the comma.

\vskip 1pc
\vpar
The doublequote character is used to notate strings as described in
section II.8.

\vskip 1pc
\vpar
The sharp sign (\verb"#") is used for a variety of purposes depending on the
character that follows it.  A sharp sign followed by a left
parenthesis signals the beginning of a vector, as described in section
II.9.  A sharp sign followed by an exclamation point is used to notate
one of the special values \verb"#!true", \verb"#!false", and \verb"#!null".  A sharp sign
followed by a backslash is used to notate characters as described in
section II.7.  A sharp sign followed by any of a number of letters is
used in the notation for numbers as described in section II.6.
 
 
\section{
Context free grammar for Scheme
}

The following grammar is ambiguous because a {\tt <special form>} looks like
a {\tt <procedure call>}.  Some implementations resolve the ambiguity by
reserving the identifiers that serve as keywords of special forms,
while other implementations allow the keyword meaning of an identifier
to be shadowed by lexical bindings.

\beginlisp
<expression> ::= <constant> | <identifier> |
                 <special form> | <procedure call>
;\pbrk
<constant> ::= <numeral> | <string> |
               (quote <datum>) | '<datum> |
               \verb"#!true" | \verb"#!false" | \verb"#!null"
;\pbrk
<special form> ::= (<keyword> <syntactic component> ...)
;\pbrk
<procedure call> ::= (<operator> <operands>)
;\pbrk
<operator> ::= <expression>
;\pbrk
<operands> ::= <empty> | <expression> <operands>
\endlisp

\vskip 1pc
\vpar
{\tt <datum>} stands for any written representation of a Scheme
object, as described in the sections that follow.  {\tt <identifier>}
has already been described informally.  {\tt <numeral>} is described
in section II.6, and {\tt <string>} is described in section II.8.
{\tt <special form>} stands for one of the special forms whose syntax
is described in section II.1.  For uniformity the other kinds of
expressions are also described in that section as though they were
special forms.

\section{I.2  Semantics}

\unvpar
A formal definition of the semantics of Scheme will be included in a
separate report.  The detailed informal semantics of Scheme is the
subject of Part II.  This section gives a quick review of Scheme's
major characteristics.

\vskip 1pc
\vpar
Scheme is a statically scoped programming language.  Each
use of an identifier is associated with a lexically apparent binding
of that identifier.  In this respect Scheme is like Algol 60, Pascal,
and C but unlike dynamically scoped languages such as APL and
traditional Lisp.

\vskip 1pc
\vpar
Scheme has latent as opposed to manifest types.  Types
are associated with values (also called objects) rather than with
variables. (Some authors refer to languages with latent types as
weakly typed or dynamically typed languages.)  Other languages with
latent types are APL, Snobol, and other dialects of Lisp.  Languages
with manifest types (sometimes referred to as strongly typed or
statically typed languages) include Algol 60, Pascal, and C.

\vskip 1pc
\vpar
All objects created in the course of a Scheme computation, including
all procedures and variables, have unlimited extent.
No Scheme object is ever destroyed.  The reason that
implementations of Scheme do not (usually!) run out of storage is that
they are permitted to reclaim the storage occupied by an object if
they can prove that the object cannot possibly matter to any future
computation.  Other languages in which most objects have unlimited
extent include APL and other Lisp dialects.

\vskip 1pc
\vpar
Implementations of Scheme are required to be properly tail-recursive.
This allows the execution of an iterative process in constant space,
even if the iterative process is described by a syntactically
recursive procedure.  Thus with a tail-recursive implementation,
iteration can be expressed using the ordinary procedure-call
mechanics, so that special iteration constructs are useful only as
syntactic sugar.

\vskip 1pc
\vpar
Scheme procedures are objects in their own right.  Procedures can be
created dynamically, stored in data structures, returned as results of
procedures, and so on.  Other languages with these properties include
Common Lisp and ML.

\vskip 1pc
\vpar
Arguments to Scheme procedures are always passed by value, which means
that the actual argument expressions are evaluated before the
procedure gains control, whether the procedure needs the result of the
evaluation or not.  ML, C, and APL are three other languages that
always pass arguments by value.  Lazy ML passes arguments by name, so
that an argument expression is evaluated only if its value is needed
by the procedure.
\filpage

\chapter{Part II:  A catalog of Scheme} 

\section{II.0  Notational conventions} 

\unvpar
This part of the report is a catalog of the special forms and
procedures that make up Scheme.  The special forms are described in
section II.1, and the procedures are described in the following
sections.  Each section is organized into entries, with one entry
(usually) for each special form or procedure.  Each entry begins with
a header line that includes the name of the special form or procedure
in {\bf boldface} type within a template for the special form or a call to
the procedure.  The names of the arguments to a procedure are
{\it italicized}, as are the syntactic components of a special form.  A
notation such as

\begintcenter
{\it expr $\ldots$}
\endtcenter

\vpar
indicates zero or more occurrences of {\it expr}.  Thus

\begintcenter
{\tt {\it expr1} {\it expr2} $\ldots$}
\endtcenter

\vpar
indicates at least one {\it expr}.
At the right of the header line one of the following categories will
appear:
\begintext
special form
constant
variable
procedure
essential special form
essential constant
essential variable
essential procedure
\endtext

\vskip 1pc
\vpar
A special form is a syntactic class of expressions, usually identified by a
keyword.  A constant is something that is lexically recognizable as a constant. 
A variable is a location in which values (also
called objects) can be stored.  An identifier may be bound to a variable.
Those variables that initially hold procedure
values are identified as procedures.

\vskip 1pc
\vpar
It is guaranteed that every implementation of Scheme will support the essential
special forms, constants, variables, and procedures. Implementations are free to
omit other features of Scheme or to add extensions, provided the extensions are
not in conflict with the language reported here. 

\vskip 1pc
\vpar
Any Scheme value can be used as a boolean expression for the purpose
of a conditional test.  As explained in section II.2, most values
count as true, but a few---notably {\tt \verb"#!false"}---count as
false.  This manual uses the word ``true'' to refer to any Scheme value
that counts as true in a conditional expression, and the word ``false''
to refer to any Scheme value that counts as false.

\vskip 1pc
\vpar
When speaking of an error condition, this manual uses the phrase ``an
error is signalled'' to indicate that implementations must detect and
report the error.  If the magic word ``signalled'' does not appear in
the discussion of an error, then implementations are not required to
detect or report the error, though they are encouraged to do so.  An
error condition that implementations are not required to detect is
usually referred to simply as ``an error''.

\vskip 1pc
\vpar
For example, it is an error for a procedure to be passed an argument that the
procedure is not explicitly specified to handle, even though such domain errors
are seldom mentioned in this manual.  Implementations may extend a procedure's
domain of definition to include other arguments.
\filpage

\section{II.1.  Special forms}

\unvpar
Identifiers have two uses within Scheme programs.  When an identifier
appears within a quoted constant (see {\tt quote}), it is being used
as data as described in the section on symbols. Otherwise it is being
used as a name.  There are two kinds of things that an identifier can
name in Scheme: {\it special forms} and {\it variables}.  A special
form is a syntactic class of expressions, and an identifier that names
a special form is called the {\it keyword} of that special form.  A
variable, on the other hand, is a location where a value can be
stored.  An identifier that names a variable is said to be {\it bound}
to that location.  The set of all such bindings in effect at some
point in a program is known as the {\it environment} in effect at that
point.
 
\vskip 1pc
\vpar
Certain special forms are used to allocate storage for new variables and to bind
identifiers to those new variables.  The most fundamental of these {\it binding
constructs} is the {\tt lambda} special form, because all other binding constructs can
be explained in terms of lambda expressions.  The other binding constructs are
the {\tt let, let*, letrec}, internal definition (see {\tt define}),
{\tt rec, named-lambda}, and
{\tt do} special forms.
 
\vskip 1pc
\vpar
Like Algol or Pascal, and unlike most other dialects of Lisp except for Common
Lisp, Scheme is a statically scoped language with block structure.  To each
place where an identifier is bound in a program there corresponds a
{\it region}  of
the program within which the binding is effective.  The region varies according
to the binding construct that establishes the binding; if the binding is
established by a lambda expression, for example, then the region is the entire
lambda expression.  Every use of an identifier in a variable reference or
assignment refers to the binding of the identifier that established the
innermost of the regions containing the use.  If there is no binding of the
identifier whose region contains the use, then the use refers to the binding for
the identifier that was in effect when Scheme started up, if any; if there is no
binding for the identifier, it is said to be {\it unbound}.

\vskip 1pc
\spread {\it variable}{essential special form}

\unvpar
An expression consisting of an identifier that is not the keyword of a special
form is a variable reference.  The value obtained for the variable reference is
the value stored in the location to which {\it variable} is bound.  It is an error to
reference an unbound {\it variable}.
\filpage

\vskip 1pc
\spread{\tt({\it operator} {\it operand1} $\ldots$)}{essential special form}

\unvpar
A list whose first element is not the keyword of a special form indicates a
procedure call.  The operator and operand expressions are evaluated
and the resulting
procedure is passed the resulting arguments.  In contrast to
other dialects of Lisp the order of evaluation is not specified, and the
operator expression and the operand expressions are always evaluated
with the same evaluation rules.
\beginlisp
                (+ 3 4)                  -->  7
                ((if \verb"#!false" + *) 3 4)   -->  12
\endlisp
\vskip 1pc
\spread
{\tt ({\bf quote} {\it datum})}{essential special form}

\spread {\it 'datum}{essential special form}

\unvpar
Evaluates to {\it datum}.  This notation is used to include literal constants in
Scheme code.
\beginlisp
                (quote a)               -->  a
                (quote \verb"#"(a b c))        -->  \verb"#"(a b c)
                (quote (+ 1 2))         -->  (+ 1 2)
\endlisp

\vpar
{\tt ({\bf quote} {\it datum})} may be abbreviated as {\it 'datum}.  The two
notations are equivalent in all respects.
\beginlisp
                'a                      -->  a
                '\verb"#"(a b c)               -->  \verb"#"(a b c)
                '(+ 1 2)                -->  (+ 1 2)
                '(quote a)              -->  (quote a)
                ''a                     -->  (quote a)
\endlisp

\vpar
Numeric constants, string constants, character constants, vector constants,
and the constants \verb"#!true", \verb"#!false", and  \verb"#!null" need not be
quoted.
\beginlisp
                '"abc"                  -->  "abc"
                "abc"                   -->  "abc"
                '145932                 -->  145932
                145932                  -->  145932
                '\verb"#!true"                 -->  \verb"#!true"
                \verb"#!true"                  -->  \verb"#!true"
\endlisp 
 
\vskip 1pc
\spread
{\tt ({\bf lambda} ({\it var1} $\ldots$) {\it expr})}{essential special form}

\unvpar
Each {\it var} must be an identifier.  The lambda expression evaluates to a
procedure with formal argument list {\it (var1 $\ldots$)} and procedure body
{\it expr}.  The environment in effect when the lambda expression was
evaluated is remembered as part of the procedure.  When the procedure
is later called with some actual arguments, the environment in which
the lambda expression was evaluated will be extended by binding the
identifiers in the formal argument list to fresh locations, the
corresponding actual argument values will be stored in those
locations, and {\it expr} will then be evaluated in the extended
environment.  The result of {\it expr} will be returned as the result of the
procedure call.
\beginlisp
        (lambda (x) (+ x x))            -->  \verb"#"<PROCEDURE>
        ((lambda (x) (+ x x)) 4)        -->  8
 ;\pbrk
        (define reverse-subtract
          (lambda (x y) (- y x)))       -->  {\it unspecified}
        (reverse-subtract 7 10)         -->  3
 ;\pbrk
        (define foo
          (let ((x 4))
            (lambda (y) (+ x y))))      -->  {\it unspecified}
        (foo 6)                         -->  10
\endlisp

\vskip 1pc
 
\spread
{\tt ({\bf lambda} ({\it var1} $\ldots$) {\it expr1} {\it expr2} $\ldots$)}{essential special form}
 
\unvpar
Equivalent to {\tt (lambda ({\it var1} $\ldots$) (begin {\it expr1}
{\it expr2} $\ldots$))}.

\vskip 1pc
\spread {\tt ({\bf lambda} {\it var} {\it expr1} {\it expr2}
$\ldots$)}{essential special form}

\unvpar
Returns a procedure that when later called with some arguments will
bind {\it var} to
a fresh location, convert the sequence of actual arguments into a list, and
store that list in the binding of {\it var}.
\beginlisp
        ((lambda x x) 3 4 5 6)          -->  (3 4 5 6)
\endlisp

\vpar
One last variation on the formal argument list provides for a so-called ``rest''
argument. If a space/dot/space sequence precedes the last argument in the formal
argument list, then the value stored in the binding of the last formal argument
will be a list of the actual arguments left over after all the other actual
arguments have been matched up against the formal arguments.
\beginlisp 
        ((lambda (x y . z) z) 3 4 5 6)  -->  (5 6)
\endlisp
\vskip 1pc

\spread
{\tt ({\bf if} {\it condition} {\it consequent} {\it
alternative})}{essential special form}
\spread
{\tt ({\bf if} {\it condition} {\it consequent})}{special form}
 
\unvpar
First evaluates {\it condition}.   If it yields a true value (see section II.2), then
{\it consequent} is evaluated and its value is returned.  Otherwise
{\it alternative} is
evaluated and its value is returned.  If no {\it alternative} is specified, then the
if expression is evaluated only for its effect, and the
result of the expression is unspecified.
\beginlisp 
        (if (>? 3 2) 'yes 'no)          -->  yes
        (if (>? 2 3) 'yes 'no)          -->  no
        (if (>? 3 2) (- 3 2) (+ 3 2))   -->  1
\endlisp
\vskip 1pc

\spread {\tt ({\bf cond} {\it clause1} {\it clause2} $\ldots$)}{essential special form}

\unvpar
Each {\it clause}  must be a list of one or more expressions.  The first expression in
each {\it clause}  is a boolean expression that serves as the {\it guard}  for the {\it clause}. 
The {\it guard}s are evaluated in order until one of them evaluates to a true value
(see section II.2).  When a {\it guard}  evaluates true, then the remaining
expressions in its {\it clause}  are evaluated in order, and the result of the last
expression in the selected {\it clause}  is returned as the result of the entire
expression.  If the selected {\it clause}  contains only the {\it guard}, then the value of
the {\it guard} is returned as the result.  If all {\it guard}s evaluate to false values,
then the result of the conditional expression is unspecified.
\beginlisp
        (cond ((>? 3 2) 'greater)
              ((<? 3 2) 'less))         --> greater
\endlisp

\vpar
The keyword or variable {\tt else} may be used as a {\it guard} to obtain the effect of a
guard that always evaluates true.
\beginlisp 
        (cond ((>? 3 3) 'greater)
              ((<? 3 3) 'less)
              (else 'equal))            -->  equal
\endlisp

\vpar
The above forms for the {\it clause}s are essential. Some implementations support yet
another form of {\it clause} such that
\beginlisp 
        (cond (form1 => form2) ...)
\endlisp

\vpar
is equivalent to
\beginlisp
        (let ((form1-result form1)
              (thunk2 (lambda () form2))
              (thunk3 (lambda () (cond ...))))
          (if form1-result
              ((thunk2) form1-result)
              (thunk3)))
\endlisp
\vskip 1pc


\spread {({\bf case} {\it expr} {\it clause1} {\it clause2} $\ldots$)}{special form}

\unvpar 
Each {\it clause} is a list whose first element is a {\it selector} followed by one or more
expressions.  Each {\it selector} should be a list of values.  The
{\it selector}s are not
evaluated.  Instead {\it expr} is evaluated and its result is
compared against successive {\it selector}s using the {\tt memv} procedure until a match is
found.  Then the expressions in the selected {\it clause} are evaluated from left to
right and the result of the last expression in the {\it clause}  is returned as the
result of the case expression.  If no {\it selector} matches then the result of the
case expression is unspecified.
\beginlisp
        (case (* 2 3)
          ((2 3 5 7) 'prime)
          ((1 4 6 8 9) 'composite))     -->  composite
        (case (car '(c d))
          ((a) 'a)
          ((b) 'b))                     -->  {\it unspecified}
\endlisp

\vpar
The special keyword {\tt else} may be used as a {\it selector} to obtain the effect of a
selector that always matches.
\beginlisp
        (case (car '(c d))
          ((a e i o u) 'vowel)
          ((y) 'y)
          (else 'consonant))            -->  consonant
\endlisp
\vskip 1pc
 
\spread {({\bf and} {\it expr1} $\ldots$)}{special form}

\unvpar
Evaluates the {\it expr}s from left to right, returning false as soon as one evaluates
to a false value (see section II.2). Any remaining expressions are not
evaluated.  If all the expressions evaluate to true values, the value of the
last expression is returned.
\beginlisp
        (and (=? 2 2) (>? 2 1))         -->  \verb"#!true"
        (and (=? 2 2) (<? 2 1))         -->  \verb"#!false"
        (and 1 2 'c '(f g))             -->  (f g)
\endlisp
\vskip 1pc

\spread{({\bf or} {\it expr1} $\ldots$)}{special form}

\unvpar 
Evaluates the {\it expr}s from left to right, returning the value of the first {\it expr}
that evaluates to a true value (see section II.2).  Any remaining expressions
are not evaluated.  If all expressions evaluate to false values, false is
returned.
\beginlisp
        (or (=? 2 2) (>? 2 1))          -->  \verb"#!true"
        (or (=? 2 2) (<? 2 1))          -->  \verb"#!true"
        (or \verb"#!false" \verb"#!false" \verb"#!false")    -->  \verb"#!false"
        (or (memq 'b '(a b c)) (/ 3 0)) -->  (b c)
\endlisp
\vskip 1pc
 
\spread
{\tt ({\bf let} (({\it var1} {\it form1}) $\ldots$) {\it expr1} {\it
expr2} $\ldots$)}{essential special form}

\unvpar
Evaluates the {\it form}s in the current environment (in some unspecified order),
binds the {\it var}s to fresh locations holding the results, and then evaluates the
{\it expr}s in the extended environment from left to right, returning the value of the
last one.  Each binding of a {\it var} has {\it expr1} {\it expr2} $\ldots$ as its region.
\beginlisp
        (let ((x 2) (y 3))
          (* x y))                      -->  6
 ;\pbrk
        (let ((x 2) (y 3))
          (let ((foo (lambda (z) (+ x y z)))
                (x 7))
            (foo 4)))                   -->  9
\endlisp

\vpar
{\tt let} and {\tt letrec} give Scheme a block structure.  The
difference between {\tt let} and
{\tt letrec} is that in a {\tt let} the {\it form}s are not within the
region of the {\it var}s being
bound.  See {\tt letrec}.

\vskip 1pc
\vpar
Some implementations of Scheme permit a ``named let'' syntax in which

\begintcenter 
{\tt ({\bf let} {\it name} (({\it var1} {\it form1}) $\ldots$) {\it
expr1} {\it expr2} $\ldots$)}
\endtcenter

\vpar 
is equivalent to
 
\begintcenter
{\tt ((rec {\it name} (lambda ({\it var1} $\ldots$) {\it expr1} {\it
expr2} $\ldots$ ))} {\it form1} $\ldots$)
\endtcenter

\vskip 1pc
\spread {\tt ({\bf let*} (({\it var1} {\it form1}) $\ldots$) {\it expr1} {\it expr2} $\ldots$)}{special form}

\unvpar
Similar to {\it let}, but the bindings are performed sequentially from left to right
and the region of a binding indicated by ({\it var} {\it form}) is that
part of the {\tt let*}
expression to the right of the binding.  Thus the second binding is done in an
environment in which the first binding is visible, and so on.
 
\vskip 1pc
\spread {\tt ({\bf letrec} (({\it var1} {\it form1}) $\ldots$){\tt
{\it expr1} {\it expr2} $\ldots$)}}{essential special form}

\unvpar
Binds the {\it var}s to fresh locations holding undefined values, evaluates the {\it form}s
in the resulting environment (in some unspecified order), assigns to
each {\it var}
the result of the corresponding {\it form}, evaluates the {\it expr}s sequentially in the
resulting environment, and returns the value of the last
{\it expr}.  Each binding of a {\it var} has the entire letrec expression as its region,
making it possible to define mutually recursive procedures.  See {\tt
let}.
\beginlisp
        (letrec ((x 2) (y 3))
          (letrec ((foo (lambda (z) (+ x y z))) (x 7))
            (foo 4)))                   -->  14
 ;\pbrk
        (letrec  ((even?
                   (lambda (n)
                     (if (zero? n)
                         \verb"#!true"
                         (odd? (-1+ n)))))
                  (odd?
                   (lambda (n)
                     (if (zero? n)
                         \verb"#!false"
                         (even? (-1+ n))))))
          (even? 88))
                                        -->  \verb"#!true"
\endlisp

\vpar
One restriction on {\tt letrec} is very important: it must be possible to evaluate
each {\it form} without referring to the value of a {\it var}.  If this restriction is
violated, then the effect is undefined, and an error may be reported during
evaluation of the {\it form}s.  The restriction is necessary because Scheme passes
arguments by value rather than by name. In the most common uses of letrec, all
the {\it form}s are lambda expressions and the restriction is satisfied automatically.
\vskip 1pc
 
\spread {\tt ({\bf rec} {\it var} {\it expr})}{special form}

\unvpar
Equivalent to {\tt (letrec (({\it var} {\it expr})) {\it var})}.  {\tt rec}
is useful for defining self-recursive procedures.
\vskip 1pc

\spread
{\tt ({\bf named-lambda} ({\it name} {\it var1} $\ldots$) {\it expr}
$\ldots$)}{special form}

\unvpar
Equivalent to 
{\tt ({\bf rec} {\it name} (lambda ({\it var1} $\ldots$) {\it expr} $\ldots$))}

\vskip 1pc
\vpar
{\it Rationale}:  Some implementatations may find it easier to provide good debugging
information when {\tt named-lambda} is used instead of {\tt rec}.
\vskip 1pc

\spread 
{\tt ({\bf define} {\it var} {\it expr})}{essential special form}

\unvpar
When typed at top level, so that it is not nested within any other expression,
this {\it form} has essentially the same effect as the assignment
{\tt (set!} {\it var} {\it expr)} if
{\it var} is bound.  If {\it var} is not bound, however, then the {\tt
define} form will bind
{\it var} before performing the assignment, whereas it would be an error to perform a
{\tt set!} on an unbound identifier.  The value returned by a {\tt define} form is not
specified.
\vskip 1pc
\beginlisp
    (define add3 (lambda (x) (+ x 3)))  -->  {\it unspecified}
    (add3 3)                            -->  6
    (define first car)                  -->  {\it unspecified}
    (first '(1 2))                      -->  1
\endlisp

\vpar
The semantics just described is essential.  Some implementations also
allow {\tt define} expressions to appear at the beginning of the body
of a {\tt lambda}, {\tt named-lambda}, {\tt let}, {\tt let*}, or {\tt
letrec} expression.  Such expressions are known as internal
definitions as opposed to the top level definitions described above.
The variable defined by an internal definition is local to the body of
the {\tt lambda}, {\tt named-lambda}, {\tt let}, {\tt let*}, or {\tt
letrec} expression.  That is, {\it var} is bound rather than assigned,
and the region set up by the binding is the entire body of the {\tt
lambda}, {\tt named-lambda}, {\tt let}, {\tt let*}, or {\tt letrec}
expression.  For example,
\beginlisp
        (let ((x 5))
          (define foo (lambda (y) (bar x y)))
          (define bar (lambda (a b) (+ (* a b) a)))
          (foo (+ x 3)))                -->  45
\endlisp
Internal definitions can always be converted into an equivalent {\tt letrec}
expression. For example, the {\tt let} expression in the above example is equivalent
to
\beginlisp
        (let ((x 5))
          (letrec ((foo (lambda (y) (bar x y)))
                   (bar (lambda (a b) (+ (* a b) a))))
            (foo (+ x 3))))
\endlisp
\vskip 1pc
\spread
{\tt ({\bf define} ({\it var0} {\it var1} $\ldots$) {\it expr1} {\it expr2} $\ldots$)}{special form}
\spread
{\tt ({\bf define} ({\it form} {\it var1} $\ldots$) {\it expr1} {\it expr2} $\ldots$)}{special form}

\unvpar
The first syntax, where {\it var0} is an identifier, is equivalent to

\par
\begintcenter
{\tt (define {\it var0} (rec {\it var0} (lambda ({\it var1} $\ldots$) {\it expr1} {\it expr2} )))}
\endtcenter

\vpar
The second syntax, where {\it form} is a list, is sometimes convenient for defining a
procedure that returns another procedure as its result.  It is equivalent to

\par
\begintcenter
{\tt (define {\it form} (lambda ({\it var1} $\ldots$) {\it expr1} {\it expr2} $\ldots$)).}
\endtcenter

\vskip 1pc
\spread {\tt ({\bf set!} {\it var} {\it expr})}{essential special form}

\unvpar 
Stores the value of {\it expr} in the location to which {\it var} is bound.  {\it expr} is
evaluated but {\it var} is not.  The result of the {\tt set!} expression is unspecified.
\beginlisp
                (set! x 4)              -->  {\it unspecified}
                (1+ x)                  -->  5
\endlisp
\vskip 1pc

\spread
{\tt ({\bf begin} {\it expr1} {\it expr2} $\ldots$)}{essential special form}


\unvpar
Evaluates the {\it expr}s sequentially from left to right and returns the value of the
last {\it expr}.  Used to sequence side effects such as input and output.
\beginlisp
        (begin (set! x 5)
               (1+ x))                  -->  6
\endlisp
\vskip 1pc

\vpar
Also
\beginlisp
        (begin (display "4 plus 1 equals ")
               (display (1+ 4)))
\endlisp

\vpar
prints
\begintcenter
{\tt 4 plus 1 equals 5}
\endtcenter

\vpar
A number of special forms such as {\tt lambda} and {\tt letrec}
implicitly treat their bodies as {\tt begin} expressions.
 
\vskip 1pc
\spread
{\tt {\bf(sequence} {\it expr1} {\it expr2} $\ldots$)}{special form}
 
\unvpar
{\tt sequence} is synonymous with {\tt begin}.

\vskip 1pc
\vpar
{\it Rationale}:  {\tt sequence} was used in the Abelson and Sussman text, but it should not
be used in new code.
\vskip 1pc 

\spread
{\tt ({\bf do} {\it varspecs} {\it exit} {\it stmt1} $\ldots$)}{special form}

\unvpar
The {\tt do} special form is an extremely general albeit complex
iteration macro.  The {\it varspecs} specify variables to be bound, how they are
to be initialized 
at the start, and how they are to be incremented every on every iteration.
the general form looks like:
\beginlisp
(do (({\it var1} {\it init1} {\it step1}) $\ldots$)
     ({\it test} {\it expr1} $\ldots$)
     {\it stmt1} $\ldots$)
\endlisp

\vpar
Each {\it var} must be an identifier and each {\it init} and {\it
step} must be expressions.  The {\it init} expressions are evaluated
(in some unspecified order), the {\it var}s are bound to fresh
locations, the results of the {\it init} expressions are stored in the
bindings of the {\it var}s, and then the iteration phase begins.

\vskip 1pc
\vpar
Each iteration begins by evaluating {\it test}; if the result is false
(see section II.2), then the {\it stmt}s are evaluated in order for
effect, the {\it step}s are evaluated (in some unspecified order), the
results of the {\it step} expressions are stored in the bindings of
the {\it var}s, and the next iteration begins.

\vskip 1pc
\vpar
If {\it test} evaluates true, then the {\it expr}s are evaluated from
left to right and the value of the last {\it expr} is returned as the
value of the {\tt do} expression.  If no {\it expr}s are present, then the
value of the {\tt do} expression is unspecified.

\vskip 1pc
\vpar
The region set up by the binding of a {\it var} consists of the entire
{\tt do} expression except for the {\it init}s.

\vskip 1pc
\vpar
A {\it step} may be omitted, in which case the corresponding {\it var}
is not updated.  When the {\it step} is omitted the {\it init} may be
omitted as well, in which case the initial value is not specified.
\beginlisp
    (do ((vec (make-vector 5))
         (i 0 (1+ i)))
        ((=? i 5) vec)
        (vector-set! vec i i))          -->  \verb"#"(0 1 2 3 4)
;\pbrk 
    (let ((x '(1 3 5 7 9)))
      (do ((x x (cdr x))
           (sum 0 (+ sum (car x))))
          ((null? x) sum)))             -->  25
\endlisp

\vpar
The {\tt do} special form is essentially the same as the {\tt do} macro in Common Lisp.  The
main difference is that in Scheme the identifier {\tt return} is not bound;
programmers that want to bind {\tt return} as in Common Lisp must do so explicitly
(see {\tt call-with-current-continuation}).
\vskip 1pc

\spread {{\tt `}{\tt {\it pattern}}}{special form}

\unvpar 
The backquote special form is useful for constructing a list structure when most
but not all of the desired structure is known in advance.  If no commas appear 
within the {\it pattern}, the result of evaluating {\it `pattern} is equivalent (in the
sense of {\tt equal?}) to the result of evaluating {\it `pattern}.  If a comma appears
within the {\it pattern}, however, the expression following the comma is evaluated and
its result is inserted into the structure instead of the comma and the
expression.  If a comma appears followed immediately by an at-sign \verb_(@)_, then the
following expression must evaluate to a list; the opening and closing
parentheses of the list are then ``stripped away'' and the elements of the list
are inserted in place of the comma/at-sign/expression sequence.
\beginlisp
`(a ,(+ 1 2) ,@(map 1+ '(4 5 6)) b)    -->  (a 3 5 6 7 b)
`(((foo ,(- 10 3)) ,@(cdr '(c)) cons)) -->  (((foo 7) cons))
\endlisp

\vpar
{\it Scheme does not have any standard facility for defining new
special forms.}

\vskip 1pc
\vpar
{\it Rationale}: The ability to define new special forms creates
numerous problems.  All current implementations of Scheme have macro
facilities that solve those problems to one degree or another, but the
solutions are quite different and it isn't clear at this time which
solution is best, or indeed whether any of the solutions are truly
adequate.  Rather than standardize, we are encouraging implementations
to continue to experiment with different solutions.

\vskip 1pc
\vpar
The main problems with traditional macros are: They must be defined to
the system before any code using them is loaded; this is a common
source of obscure bugs.  They are usually global; macros can be made
to follow lexical scope rules as in Common Lisp's {\tt macrolet}, but
many people find the resulting scope rules confusing.  Unless they are
written very carefully, macros are vulnerable to inadvertant capture
of free variables; to get around this, for example, macros may have to
generate code in which procedure values appear as quoted constants.
There is a similar problem with keywords if the keywords of special
forms are not reserved.  If keywords are reserved, then either macros
introduce new reserved words, invalidating old code, or else special
forms defined by the programmer do not have the same status as special
forms defined by the system.
\filpage

\section{II.2. Booleans}

\unvpar
The standard boolean objects for truth and falsity are written as
\verb"#!true" and \verb"#!false".  What really matters, though, are
the objects that the Scheme conditional expressions ({\tt if}, {\tt
cond}, {\tt and}, {\tt or}, {\tt do}) will treat as though they were
true or false.  The phrase ``a true value'' (or sometimes just
``true'') means any object treated as true by the conditional
expressions, and the phrase ``a false value'' (or ``false'') means any
object treated as false by the conditional expressions.  All of the
conditional expressions are equivalent in that an object treated as
false by any one of them is treated as false by all of them, and
likewise for true values.

\vskip 1pc
\vpar
Of all the standard Scheme values, only \verb"#!false" and the empty
list count as false in conditional expressions.  \verb"#!true", pairs
(and therefore lists), symbols, numbers, strings, vectors, and
procedures all count as true.

\vskip 1pc
\vpar
The empty list counts as false for historical reasons only, and programs should
not rely on this because future versions of Scheme will probably do away with
this nonsense.

\vskip 1pc
\vpar
Programmers accustomed to other dialects of Lisp should beware that Scheme has
already done away with the nonsense that identifies the empty list with the
symbol {\tt nil}.
\vskip 1pc 

\spread
{\bf \# !false}{essential constant}

\unvpar
\verb"#!false" is the boolean value for falsity.  The \verb"#!false"
object is self-evaluating.  That is, it does not need to be quoted in
programs.
\beginlisp
                        '\verb"#!false"        -->  \verb"#!false"
                        \verb"#!false"         -->  \verb"#!false"
\endlisp
\vskip 1pc
\spread
{\bf \# !true}{essential constant}

\unvpar
\verb"#!true" is the boolean value for truth.  The \verb"#!true"
object is self-evaluating, and does not need to be quoted in
programs.
 
\vskip 1pc 
\spread
{\tt ({\bf not} {\it obj)}}{essential procedure}

\unvpar
Returns \verb"#!true" if {\it obj} is false and returns \verb"#!false" otherwise.
\vskip 1pc 

\spread
{\tt {\bf nil}}{variable}
\spread
{\tt {\bf t}}{variable}

\unvpar
As a crutch for programmers accustomed to other dialects of Lisp, some
implementations provide variables {\tt nil} and {\tt t} whose initial values are \verb"#!null" and
\verb"#!true" respectively.  These variables should not be relied upon in new code.
\filpage
 
\section{II.3.  Equivalence predicates}

\unvpar
A predicate is a procedure that always returns \verb"#!true" or \verb"#!false".  Of the
equivalence predicates described in this section, {\tt eq?} is the most discriminating
while {\tt equal?} is the most liberal. {\tt eqv?} is very slightly less
discriminating than {\tt eq?}. 
\vskip 1pc

\spread{\tt ({\bf eq?} {\it obj1} {\it obj2})}{essential procedure}

\unvpar 
Returns \verb"#!true" if {\it obj1} is identical in all respects to {\it obj2}, otherwise returns
\verb"#!false".  If there is any way at all that a user can distinguish {\it obj1} and {\it obj2},
then {\tt eq?} will return \verb"#!false".  On the other hand, it is guaranteed that objects
maintain their identity despite being fetched from or stored into variables or
data structures.

\vskip 1pc
\vpar
The notion of identity used by {\tt eq?} is stronger than the notions of equivalence
used by the {\tt eqv?} and {\tt equal?} predicates.  The constants \verb"#!true" and \verb"#!false" are
identical to themselves and are different from everything else, except that in
some implementations the empty list is identical to \verb"#!false" for historical
reasons. Two symbols are identical if they print the same way (except that some
implementations may have ``uninterned symbols'' that violate this rule).  For
structured objects such as pairs and vectors the notion of sameness is defined
in terms of the primitive mutation procedures defined on those objects.  For
example, two pairs are the same if and only if a {\tt set-car!} operation on one
changes the car field of the other.  The rules for identity of numbers are
extremely implementation-dependent and should not be relied on.

\vskip 1pc
\vpar
Generally speaking, the {\tt equal?} procedure should be used to compare lists,
vectors, and arrays.  The \verb_char=?_ procedure should be used to compare characters,
the {\tt string=?} procedure should be used to compare strings, and the \verb"=?"
procedure should be used to compare numbers.  The {\tt eqv?} procedure is just like
{\tt eq?} except that it can be used to compare characters and exact numbers as well. 
(See section II.6 for a discussion of exact numbers.)
\beginlisp
        (eq? 'a 'a)                     -->  \verb"#!true"
        (eq? 'a 'b)                     -->  \verb"#!false"
        (eq? '(a) '(a))                 -->  {\it unspecified}
\endlisp
\beginlisp
        (eq? "a" "a")                   -->  {\it unspecified}
        (eq? 2 2)                       -->  {\it unspecified}
        (eq? (cons 'a 'b) (cons 'a 'b)) -->  \verb"#!false"
        (let ((x (read)))
          (eq? (cdr (cons 'b x)) x))    -->  \verb"#!true"
\endlisp

\spread 
{\tt ({\bf eqv?} {\it obj1} {\it obj2})}{essential procedure}

\unvpar 
{\tt eqv?} is just like {\tt eq?} except that if {\it obj1} and {\it
obj2}  are exact numbers then {\tt eqv}?
is guaranteed to return \verb"#!true" if {\it obj1}  and {\it obj2}  are equal according to the \verb_=?_
procedure.
\beginlisp
                (eq? 100000 100000)     -->  {\it unspecified}
                (eqv? 100000 100000)    -->  \verb"#!true"
\endlisp

\vpar
See section II.6 for a discussion of exact numbers.
\vskip 1pc 

\spread 
{\tt ({\bf equal?} {\it obj1} {\it obj2})}{essential procedure}

\unvpar 
Returns \verb"#!true" if {\it obj1} and {\it obj2} are identical objects or if they are
equivalent numbers, lists, characters, strings, or vectors.  Two objects are
generally considered equivalent if they print the same.  {\tt equal?} may fail to
terminate if its arguments are circular data structures. 
\beginlisp
        (equal? 'a 'a)                  -->  \verb"#!true"
        (equal? '(a) '(a))              -->  \verb"#!true"
        (equal? '(a (b) c) '(a (b) c))  -->  \verb"#!true"
        (equal? "abc" "abc")            -->  \verb"#!true"
        (equal? 2 2)                    -->  \verb"#!true"
        (equal? (make-vector 5 'a)
                (make-vector 5 'a))     -->  \verb"#!true"
\endlisp
\filpage

\section{II.4.  Pairs and lists}

\unvpar 
Lists are Lisp's---and therefore Scheme's---characteristic data structures. 

\vskip 1pc
\vpar
The empty list is a special object that is written as an opening parenthesis
followed by a closing parenthesis:
{\tt ()}
The empty list has no elements, and its length is zero.  The empty list is not a
pair.

\vskip 1pc
\vpar
Larger lists are built out of pairs.  A pair (sometimes called a
``dotted pair'') is a record structure with two fields called the car
and cdr fields (for historical reasons).  Pairs are created by the
procedure named {\tt cons}. The car and cdr fields are accessed by the
procedures {\tt car} and {\tt cdr}.  The car and cdr fields are
assigned by the procedures {\tt set-car!} and {\tt set-cdr!}.

\vskip 1pc
\vpar
The most general notation used for Scheme pairs is the ``dotted''
notation \linebreak {\tt ({\it c1} .  {\it c2})} where {\it c1} is the value of
the car field and {\it c2} is the value of the cdr field.  For example
{\tt (4 . 5)} is a pair whose car is 4 and whose cdr is 5.

\vskip 1pc
\vpar
The dotted notation is not often used, because more streamlined
notations exist for the common case where the cdr is the empty list or
a pair.  Thus {\tt ({\it c1} . ())} is usually written as {\tt ({\it
c1})}, and {\tt ({\it c1} . ({\it c2} . {\it c3} ))} is usually
written as {\tt ({\it c1} {\it c2} .  {\it c3} )}.  Usually these
special notations permit a structure to be written without any dotted
pair notation at all.  For example

\par
\begintcenter
{\tt (a . (b . (c . (d . (e . ())))))}
\endtcenter

\vskip 1pc
\vpar
would normally be written as {\tt (a b c d e)}.

\vpar
When all the dots can be made to disappear as in the example above, the entire
structure is called a proper list.  Proper lists are so common that when people
speak of a list, they usually mean a proper list.  An inductive definition:

\bpar
The empty list is a proper list.

\bpar
If {\it plist}  is a proper list, then any pair whose cdr is {\it plist} is also a proper list.

\bpar
There are no other proper lists.

\vpar 
A proper list is therefore either the empty list or a pair from which the empty
list can be obtained by applying the {\tt cdr} procedure a finite number of times.
Whether a given pair is a proper list depends upon what is stored in the cdr
field.  When the {\tt set-cdr!} procedure is used, an object can be a proper list one
moment and not the next:
\beginlisp
           (define x '(a b c))     -->  {\it unspecified}
           (define y x)            -->  {\it unspecified}
           y                       -->  (a b c)
           (set-cdr! x 4)          -->  {\it unspecified}
           x                       -->  (a . 4)
           (eq? x y)               -->  \verb"#!true"
           y                       -->  (a . 4)
\endlisp

\vpar
A pair object, on the other hand, will always be a pair object.

\vskip 1pc
\vpar
It is often convenient to speak of a homogeneous (proper) list of objects of
some particular data type, as for example {\tt (1 2 3)} is a list of integers.  To be
more precise, suppose {\it D} is some data type.  (Any predicate defines a data type
consisting of those objects of which the predicate is true.)  Then

\bpar
The empty list is a list of {\it D}.

\bpar
If {\it plist} is a list of {\it D}, then any pair whose cdr is {\it
plist} and whose car is an element of the data type {\it D} is also a
list of {\it D}.

\bpar
There are no other lists of {\it D}.
 
\vskip 2pc
\spread
{\tt ({\bf pair?} {\it obj})}{essential procedure}

\unvpar
Returns \verb"#!true" if {\it obj} is a pair, otherwise returns \verb"#!false".
\beginlisp
                (pair? '(a . b))        -->  \verb"#!true"
                (pair? '(a b c))        -->  \verb"#!true"
                (pair? '())             -->  \verb"#!false"
                (pair? '#(a b))         -->  \verb"#!false"
\endlisp

\vskip 1pc
\spread
{\tt ({\bf cons} {\it obj1} {\it obj2})}{essential procedure}

\unvpar 
Returns a newly allocated pair whose car is {\it obj1} and whose cdr is {\it obj2}.  The
pair is guaranteed to be different (in the sense of {\tt eq?}) from every existing
object.
\beginlisp
                (cons 'a '())           -->  (a)
                (cons '(a) '(b c d))    -->  ((a) b c d)
                (cons "a" '(b c))       -->  ("a" b c)
                (cons 'a 3)             -->  (a . 3)
                (cons '(a b) 'c)        -->  ((a b) . c)
\endlisp

\filpage

\spread
{\tt ({\bf car} {\it pair})}{essential procedure}

\unvpar 
Returns the contents of the car field of {\it pair}.  {\it pair} must be a pair.  Note that
it is an error to take the car of the empty list.
\beginlisp
                (car '(a b c))          -->  a
                (car '((a) b c d))      -->  (a)
                (car '(1 . 2))          -->  1
                (car '())               -->  {\it error}
\endlisp
 
\vskip 1pc
\spread
{\tt ({\bf cdr} {\it pair})}{essential procedure}

\unvpar 
Returns the contents of the cdr field of {\it pair}. {\it pair} must be a pair.  Note that
it is an error to take the cdr of the empty list.
\beginlisp
                (cdr '((a) b c d))      -->  (b c d)
                (cdr '(1 . 2))          -->  2
                (cdr '())               -->  {\it error}
\endlisp
 
\vskip 1pc
\spread
{\tt ({\bf set-car!} {\it  pair obj})}{essential procedure}

\unvpar
Stores {\it obj} in the car field of {\it pair}.  {\it pair} must be a pair.  The value returned
by {\tt set-car!} is unspecified.  This procedure can be very confusing if used
indiscriminately.
\vskip 1pc
 
\spread
{\tt ({\bf set-cdr!} {\it pair} {\it obj})}{essential procedure}

\unvpar 
Stores {\it obj} in the cdr field of {\it pair}.  {\it pair} must be a pair.  The value returned
by set-cdr! is unspecified.  This procedure can be very confusing if used
indiscriminately.
\vskip 1pc
\spread
{\tt ({\bf caar} {\it pair})}{essential procedure}
\spread
{\tt ({\bf cadr} {\it pair})}{essential procedure}
\spread
{\tt ({\bf cdar} {\it pair})}{essential procedure}
\spread
{\tt ({\bf cddr} {\it pair})}{essential procedure}
\spread
{\tt ({\bf caaar} {\it pair})}{essential procedure}
\spread
{\tt ({\bf caadr} {\it pair})}{essential procedure}
\spread
{\tt ({\bf cadar} {\it pair})}{essential procedure}
\spread
{\tt ({\bf caddr} {\it pair})}{essential procedure}
\spread
{\tt ({\bf cdaar} {\it pair})}{essential procedure}
\spread
{\tt ({\bf cdadr} {\it pair})}{essential procedure}
\spread
{\tt ({\bf cddar} {\it pair})}{essential procedure}
\spread
{\tt ({\bf cdddr} {\it pair})}{essential procedure}
\spread
{\tt ({\bf caaaar} {\it pair})}{essential procedure}
\spread
{\tt ({\bf caaadr} {\it pair})}{essential procedure}
\spread
{\tt ({\bf caadar} {\it pair})}{essential procedure}
\spread
{\tt ({\bf caaddr} {\it pair})}{essential procedure}
\spread
{\tt ({\bf cadaar} {\it pair})}{essential procedure}
\spread
{\tt ({\bf cadadr} {\it pair})}{essential procedure}
\spread
{\tt ({\bf caddar} {\it pair})}{essential procedure}
\spread
{\tt ({\bf cadddr} {\it pair})}{essential procedure}
\spread
{\tt ({\bf cdaaar} {\it pair})}{essential procedure}
\spread
{\tt ({\bf cdaadr} {\it pair})}{essential procedure}
\spread
{\tt ({\bf cdadar} {\it pair})}{essential procedure}
\spread
{\tt ({\bf cdaddr} {\it pair})}{essential procedure}
\spread
{\tt ({\bf cddaar} {\it pair})}{essential procedure}
\spread
{\tt ({\bf cddadr} {\it pair})}{essential procedure}
\spread
{\tt ({\bf cdddar} {\it pair})}{essential procedure}
\spread
{\tt ({\bf cddddr} {\it pair})}{essential procedure}
\vskip 1pc 

\unvpar
These procedures are compositions of {\tt car} and {\tt cdr}, where
for example {\tt caddr} could be defined by

\vskip 1pc
\begintcenter
{\tt (define caddr (lambda (x) (car (cdr (cdr x)))))}
\endtcenter

\vskip 1pc
\spread
{\tt '()}{essential constant}
\spread
{\bf \#!null}{constant}

\unvpar
{\tt '()} and \verb"#!null" are notations for the empty list.  The \verb"#!null" notation does not
have to be quoted in programs.  The {\tt ()} notation must be quoted in programs,
however, because otherwise it would be a procedure call without a expression in
the procedure position.

\vskip 1pc
\vpar
{\it Rationale}:  Because many current Scheme interpreters deal with expressions as
list structures rather than as character strings, they will treat an
unquoted {\tt ()}
as though it were quoted.  It is entirely possible, however, that some
implementations of Scheme will be able to detect an unquoted {\tt ()} as an error.
\vskip 1pc
 
\spread
{\tt ({\bf null?} {\it  obj})}{essential procedure}

\unvpar
Returns \verb"#!true" if {\it obj} is the empty list, otherwise returns \verb"#!false".
 
\vskip 1pc
\spread
{\tt ({\bf list} {\it obj1} $\ldots$)}{essential procedure}

\unvpar 
Returns a proper list of its arguments.
\beginlisp
        (list 'a (+ 3 4) 'c)            -->  (a 7 c)
\endlisp
\filpage

\spread
{\tt ({\bf length} {\it plist})}{essential procedure}

\unvpar
Returns the length of {\it plist}, which must be a proper list.
\beginlisp
        (length '())                    -->  0
        (length '(a b c))               -->  3
        (length '(a (b) (c d e)))       -->  3
\endlisp
\vskip 1pc
\spread
{\tt ({\bf append} {\it plist1} {\it plist2})}{essential procedure}
\spread
{\tt ({\bf append} {\it plist} $\ldots$)}{ procedure}

\unvpar
All {\it plist}s should be proper lists.  Returns a list consisting of the elements of
the first {\it plist} followed by the elements of the other {\it plist}s. 
\beginlisp
        (append '(x) '(y))              -->  (x y)
        (append '(a) '(b c d))          -->  (a b c d)
        (append '(a (b)) '((c)))        -->  (a (b) (c))
\endlisp
\vskip 1pc
\spread
{\tt ({\bf append!} {\it plist} $\ldots$)}{procedure}

\unvpar 
Like {\tt append} but may side effect all but its last argument.
\vskip 1pc
\spread
{\tt ({\bf reverse} {\it plist})}{procedure}

\unvpar
{\it plist} must be a proper list.  Returns a list consisting of the elements of {\it plist}
in reverse order. 

\beginlisp
   (reverse '(a b c))              -->  (c b a)
   (reverse '(a (b c) d (e (f))))  -->  ((e (f)) d (b c) a)
\endlisp
\vskip 1pc
\spread
{\tt ({\bf list-ref} {\it  x n})}{procedure}

\unvpar
Returns the car of ({\tt list-tail {\it x n})}.
\vskip 1pc
\spread
{\tt ({\bf list-tail} {\it x n})}{procedure}

\unvpar
Returns the sublist of {\it x}  obtained by omitting the first {\it n}  elements.  Could be
defined by
\beginlisp
        (define list-tail
          (lambda (x n)
            (if (zero? n)
                x
                (list-tail (cdr x) (- n 1)))))
\endlisp 
\filpage

\spread
{\tt ({\bf last-pair} {\it x})}{procedure}

\unvpar
Returns the last pair in the nonempty list {\it x}.  Could be defined by
\beginlisp
        (define last-pair
          (lambda (x)
            (if (pair? (cdr x))
                (last-pair (cdr x))
                x)))
\endlisp 
 
\vskip 1pc
\spread
{\tt ({\bf memq} {\it obj} {\it plist})}{essential procedure}
\spread
{\tt ({\bf memv} {\it obj} {\it plist})}{essential procedure}
\spread
{\tt ({\bf member} {\it obj} {\it plist})}{essential procedure}

\unvpar
Finds the first occurrence of {\it obj} in the proper list {\it plist}
and returns the first sublist of {\it plist} beginning with {\it obj}.
If {\it obj} does not occur in {\it plist}, returns \verb"#!false".
{\tt memq} uses \verb"eq?" to compare {\it obj} with the elements of
{\it plist}, while {\tt memv} uses {\tt eqv?} and {\tt member} uses
{\tt equal?}.
\beginlisp
 
        (memq 'a '(a b c))              -->  (a b c)
        (memq 'b '(a b c))              -->  (b c)
        (memq 'a '(b c d))              -->  \verb"#!false"
        (memq (list 'a) '(b (a) c))     -->  \verb"#!false"
        (memq 101 '(100 101 102))       -->  {\it unspecified}
        (memv 101 '(100 101 102))       -->  (101 102)
        (member (list 'a) '(b (a) c))   -->  ((a) c)
\endlisp 
 
\vskip 1pc
\spread
{\tt ({\bf assq} {\it obj} {\it alist})}{essential procedure}
\spread
{\tt ({\bf assv} {\it obj} {\it alist})}{essential procedure}
\spread
{\tt ({\bf assoc} {\it obj} {\it alist})}{essential procedure}

\unvpar
{\it alist} must be a proper list of pairs.  Finds the first pair in alist whose car
field is {\it obj} and returns that pair. If no pair in {\it alist} has {\it obj} as its car,
returns \verb"#!false".  {\tt assq} uses {\tt eq?} to compare {\it obj} with the car fields of the pairs
in {\it alist}, while {\tt assv} uses {\tt eqv?} and {\tt assoc} uses
{\tt equal?}.
\beginlisp
        (assq 'a '((a 1) (b 2) (c 3)))     -->  (a 1)
        (assq 'b '((a 1) (b 2) (c 3)))     -->  (b 2)
        (assq 'd '((a 1) (b 2) (c 3)))     -->  \verb"#!false"
        (assq (list 'a)
              '(((a)) ((b)) ((c))))        -->  \verb"#!false"
        (assq 5 '((2 3) (5 7) (11 13)))    -->  {\it unspecified}
        (assv 5 '((2 3) (5 7) (11 13)))    -->  (5 7)
        (assoc (list 'a)
               '(((a)) ((b)) ((c))))       -->  ((a))
\endlisp
\filpage

\vpar
{\it Rationale}:  {\tt memq, memv, member, assq, assv}, and {\tt assoc} do not have question marks
in their names because they return useful values rather than just \verb"#!true".
\filpage 

\section{II.5.  Symbols}

\unvpar
Symbols are objects whose usefulness rests entirely on the fact that two symbols
are identical (in the sense of {\tt eq?}) if and only if their names are spelled the
same way.  This is exactly the property needed to represent identifiers in
programs, and so most implementations of Scheme use them internally for that
purpose.  Programmers may also use symbols as they use enumerated values in
Pascal.

\vskip 1pc
\vpar
The rules for writing a symbol are the same as the rules for writing an
identifier (see section I.2).  As with identifiers, different implementations
of Scheme use slightly different rules, but it is always the case that a
sequence of characters that contains no special characters and begins with a
character that cannot begin a number is taken to be a symbol; in
addition {\tt +}, {\tt -}, {\tt 1+}, and {\tt -1+} are symbols.

\vskip 1pc
\vpar
The case in which a symbol is written is unimportant.  Some implementations of
Scheme convert any upper case letters to lower case, and others convert lower
case to upper case.

\vskip 1pc
\vpar
It is guaranteed that any symbol that has been read using the {\tt read} procedure and
subsequently written out using the {\tt write} procedure will read back in as the
identical symbol (in the sense of {\tt eq?}).  The {\tt
string->symbol} procedure, however,
can create symbols for which this write/read invariance may not hold because
their names contain special characters or letters in the non-standard case.
 
\vskip 1pc
\vpar
{\it Rationale}:  Some implementations of Lisp have a feature known as
``slashification'' in order to guarantee write/read invariance for all symbols,
but historically the most important use of this feature has been to compensate
for the lack of a string data type.  Some implementations have ``uninterned
symbols'', which defeat write/read invariance even in implementations with
slashification and also generate exceptions to the rule that two symbols are the
same if and only if their names are spelled the same.  It is questionable
whether these features are worth their complexity, so they are not standard in
Scheme.
\vskip 1pc

\spread
{\tt ({\bf symbol?} {\it obj})}{essential procedure}

\unvpar
Returns \verb"#!true" if {\it obj} is a symbol, otherwise returns \verb"#!false".
\beginlisp
                (symbol? 'foo)          -->  \verb"#!true"
                (symbol? (car '(a b)))  -->  \verb"#!true"
                (symbol? "bar")         -->  \verb"#!false"
\endlisp
\vskip 1pc

\spread
{\tt ({\bf symbol-}>{\bf string} {\it symbol})}{essential procedure}

\unvpar 
Returns the name of {\it symbol}  as a string.  {\tt symbol->string} performs no case
conversion.  See {\tt string->symbol}.  The following examples assume the {\tt read}
procedure converts to lower case:
\beginlisp
     (symbol->string 'flying-fish)     -->  "flying-fish"
     (symbol->string 'Martin)          -->  "martin"
     (symbol->string
       (string->symbol "Malvina"))     -->  "Malvina"
\endlisp
\vskip 1pc
\spread
{\tt ({\bf string-}>{\bf symbol} {\it string})}{essential procedure}

\unvpar
Returns the symbol whose name is {\it string}.  {\tt string->symbol} can create symbols with
special characters or letters in the non-standard case, but it is usually a bad
idea to create such symbols because in some implementations of Scheme they
cannot be read as themselves.  See {\tt symbol->string}.
\beginlisp
    'mISSISSIppi                        -->  mississippi
;\pbrk 
    (string->symbol "mISSISSIppi")      -->  mISSISSIppi
;\pbrk
    (eq? 'bitBlt
         (string->symbol "bitBlt"))     -->  {\it unspecified}
;\pbrk
   (eq? 'JollyWog
         (string->symbol
           (symbol->string 'JollyWog))) -->  \verb"#!true"
;\pbrk
    (string=?
      "K. Harper, M.D."
      (symbol->string
        (string->symbol
          "K. Harper, M.D.")))          -->  \verb"#!true"
\endlisp
\filpage

\section{II.6.  Numbers}

\unvpar 
Numerical computation has traditionally been neglected by the Lisp community. 
Until Common Lisp there has been no carefully thought out strategy for
organizing numerical computation, and with the exception of the MacLisp system
there has been little effort to execute numerical code efficiently.  We applaud
the excellent work of the Common Lisp committee and we accept many of their
recommendations.  In some ways we simplify and generalize their proposals in a
manner consistent with the purposes of Scheme.

\vskip 1pc
\vpar
Scheme's numerical operations treat numbers as abstract data, as independent of
their representation as is possible.  Thus, the casual user should be able to
write simple programs without having to know that the implementation may use
fixed-point, floating-point, and perhaps other representations for his data. 
Unfortunately, this illusion of uniformity can be sustained only approximately
-- the implementation of numbers will leak out of its abstraction whenever the
user must be in control of precision, or accuracy, or when he must construct
especially efficient computations.  Thus the language must also provide escape
mechanisms so that a sophisticated programmer can exercise more control over the
execution of his code and the representation of his data when necessary.

\vskip 1pc
\vpar
It is important to distinguish between the abstract numbers, their machine
representations, and their written representations.  We will use mathematical
words such as NUMBER, COMPLEX, REAL, RATIONAL, and INTEGER for properties of the
abstract numbers, names such as FIXNUM, BIGNUM, RATNUM, and FLONUM for machine
representations, and names like INT, FIX, FLO, SCI, RAT, POLAR, and RECT for
input/output formats.
 
 
\heading{Numbers}

\unvpar
A Scheme system provides data of type NUMBER, which is the most
general numerical type supported by that system.  NUMBER is likely to
be a complicated union type implemented in terms of FIXNUMS, BIGNUMS,
FLONUMS, and so forth, but this should not be apparent to a naive
user.  What the user should see is that the usual operations on
numbers produce the mathematically expected results, within the limits
of the implementation.  Thus if the user divides the exact number 3 by
the exact number 2, he should get something like 1.5 (or the exact
fraction 3/2).  If he adds that result to itself, and the
implementation is good enough, he should get an exact 3.

\vskip 1pc
\vpar
Mathematically, numbers may be arranged into a tower of subtypes with 
projections and injections relating adjacent levels of the tower:

\begintext
                                NUMBER
                                COMPLEX
                                REAL
                                RATIONAL
                                INTEGER
\endtext

\vpar
We impose a uniform rule of downward coercion---a number of one type is also of
a lower type if the injection (up) of the projection (down) of a number leaves
the number unchanged.  Since this tower is a genuine mathematical structure,
Scheme provides predicates and procedures to access the tower.

\vskip 1pc
\vpar
Not all implementations of Scheme must provide the whole tower, but they must
implement a coherent subset consistent with both the purposes of the
implementation and the spirit of the Scheme language.
 
 
\heading{Exactness}

\unvpar
Numbers are either EXACT or INEXACT.  A number is exact if it was derived from
EXACT numbers using only EXACT operations.  A number is INEXACT if it models a
quantity known only approximately, if it was derived using INEXACT ingredients,
or if it was derived using INEXACT operations.  Thus INEXACTness is a contagious
property of a number.  Some operations, such as the square root (of non-square
numbers) must be INEXACT because of the finite precision of our representations.
Other operations are inexact because of implementation requirements.  We
emphasize that exactness is independent of the position of the number on the
tower.  It is perfectly possible to have an INEXACT INTEGER or an EXACT REAL;
355/113 may be an EXACT RATIONAL or it may be an INEXACT RATIONAL approximation
to pi, depending on the application.

\vskip 1pc
\vpar
Operationally, it is the system's responsibility to combine EXACT numbers using
exact methods, such as infinite precision integer and rational arithmetic, where
possible.  An implementation may not be able to do this (if it does not use
infinite precision integers and rationals), but if a number becomes inexact for
implementation reasons there is likely to be an important error condition, such
as integer overflow, to be reported.  Arithmetic on INEXACT numbers is not so
constrained.  The system may use
floating point and other ill-behaved representation strategies for INEXACT
numbers.  This is not to say that implementors need not use the best known
algorithms for INEXACT computations---only that approximate methods of high
quality are allowed.  In a system that cannot explicitly distinguish exact from
inexact numbers the system must do its best to maintain precision.  Scheme
systems must not burden users with numerical operations described in terms of
hardware and operating-system dependent representations such as FIXNUM and
FLONUM, however, because these representation issues are hardly ever germane to
the user's problems.

\vskip 1pc
\vpar
We highly recommend that the IEEE 32-bit and 64-bit floating-point standards be
adopted for implementations that use floating-point representations internally. 
To minimize loss of precision we adopt the following rules: If an implementation
uses several different sizes of floating-point formats, the results of any
operation with a floating-point result must be expressed in the largest format
used to express any of the floating-point arguments to that operation.  It is
desirable (but not required) for potentially irrational operations such as {\tt sqrt},
when applied to EXACT arguments, to produce EXACT answers whenever possible (for
example the square root of an exact 4 ought to be an exact 2).  If an EXACT
number (or an INEXACT number represented as a FIXNUM, a BIGNUM, or a RATNUM) is
operated upon so as to produce an INEXACT result (as by {\tt sqrt}), and if the result
is represented as a FLONUM, then the largest available FLONUM format must be
used; but if the result is expressed as a RATNUM then the rational approximation
must have at least as much precision as the largest available FLONUM.


\heading{Numerical operations}

\unvpar
Scheme provides the usual set of operations for manipulating numbers.  In
general, numerical operations require numerical arguments.  For succintness we
let the following meta-symbols range over the indicated types of object in our
descriptions, and we let these meta-symbols specify the types of the arguments
to numeric operations.  It is an error for an operation to be presented with an
argument that it is not specified to handle.
 
\vskip 1pc
\centerline{
\begintable[ll]
{\it obj}&any object\cr
{\it z, z1, $\ldots$ zi, $\ldots$}&complex, real
, rational, integer\cr
{\it x, x1, $\ldots$ xi, $\ldots$}&real, rational, integer\cr
{\it q, q1, $\ldots$ qi, $\ldots$}&rational, integer\cr
{\it n, n1, $\ldots$ ni, $\ldots$}&integer\cr
\endtable
}
\vskip 1pc
\spread
{\tt ({\bf number?} {\it obj})}{essential procedure}
\spread
{\tt ({\bf complex?} {\it obj})}{essential procedure}
\spread
{\tt ({\bf real?} {\it obj})}{essential procedure}
\spread
{\tt ({\bf rational?} {\it obj})}{essential procedure}
\spread
{\tt ({\bf integer?} {\it obj})}{essential procedure}

\unvpar
These numerical type predicates can be applied to any kind of argument. They
return true if the object is of the named type.  In general, if a type predicate
is true of a number then all higher type predicates are also true of that
number.  Not every system supports all of these types; for example, it is
entirely possible to have a Scheme system that has only INTEGERs.  Nonetheless
every implementation of Scheme must have all of these predicates.

\vskip 1pc
\spread
{\tt ({\bf zero?} {\it z})}{essential procedure}
\spread
{\tt ({\bf positive?} {\it x})}{essential procedure}
\spread
{\tt ({\bf negative?} {\it x})}{essential procedure}
\spread
{\tt ({\bf odd?} {\it n})}{essential procedure}
\spread
{\tt ({\bf even?} {\it n})}{essential procedure}
\spread
{\tt ({\bf exact?} {\it z})}{essential procedure}
\spread
{\tt ({\bf inexact?} {\it z})}{essential procedure}

\unvpar
These numerical predicates test a number for a particular property, returning
\verb"#!true" or \verb"#!false".
\vskip 1pc

\spread 
{\tt ({\bf =} {\it z1} {\it z2})}{essential procedure}
\spread
{\tt ({\bf =?} {\it z1} {\it z2})}{essential procedure}
\spread
{\tt ({\tt <} {\it x1} {\it x2})}{essential procedure}
\spread
{\tt ({\tt <}{\bf ?} {\it x1} {\it x2})}{essential procedure}
\spread
{\tt ({\tt >} {\it x1} {\it x2})}{essential procedure}
\spread
{\tt ({\tt >}{\bf ?} {\it x1} {\it x2})}{essential procedure}
\spread
{\tt ({\tt <}{\bf =} {\it x1} {\it x2})}{essential procedure}
\spread
{\tt ({\tt <}{\bf =?} {\it x1} {\it x2})}{essential procedure}
\spread
{\tt ({\tt >}{\bf =} {\it x1} {\it x2})}{essential procedure}
\spread
{\tt ({\tt >}{\bf =?} {\it x1} {\it x2})}{essential procedure}

\unvpar
These numerical comparison predicates have redundant names (with and without the
terminal ``?'') to make all user populations happy.  Some implementations allow
them to take many arguments, as in Common Lisp, to facilitate range checks. 
These procedures return \verb"#!true" if their arguments are (respectively):
numerically equal, monotonically increasing, monotonically decreasing,
monotonically nondecreasing, or monotonically nonincreasing.  Warning:  On
INEXACT numbers the equality tests will give unreliable results, and the other
numerical comparisons will be useful only heuristically; when in doubt, consult
a numerical analyst.
 
\vskip 1pc
\spread
{\tt ({\bf max} {\it x1} {\it x2})}{essential procedure}
\spread
{\tt ({\bf max} {\it x1} {\it x2} $\ldots$)}{procedure}
\spread
{\tt ({\bf min} {\it x1} {\it x2})}{essential procedure}
\spread
{\tt ({\bf min} {\it x1} {\it x2} $\ldots$)}{procedure}

\unvpar
Returns the maximum or minimum of its arguments, respectively.

\spread
{\tt ({\bf +} {\it z1} {\it z2})}{essential procedure}
\spread
{\tt ({\bf +} {\it z1} $\ldots$)}{procedure}
\spread
{\tt ({\bf *} {\it z1} {\it z2})}{essential procedure}
\spread
{\tt ({\bf *} {\it z1} $\ldots$)}{procedure}

\unvpar
These procedures return the sum or product of their arguments.
\beginlisp
                (+ 3 4)                 -->  7
                (+ 3)                   -->  3
                (+)                     -->  0
                (* 4)                   -->  4
                (*)                     -->  1
\endlisp 
 
\vskip 1pc
\spread
{\tt ({\bf -} {\it z1} {\it z2})}{essential procedure}
\spread
{\tt ({\bf -} {\it z1} {\it z2} $\ldots$)}{procedure}
\spread
{\tt ({\bf /} {\it z1} {\it z2})}{essential procedure}
\spread
{\tt ({\bf /} {\it z1} {\it z2} $\ldots$)}{procedure}

\unvpar
With two or more arguments, these procedures return the difference or (complex)
quotient of their arguments, associating to the left.  With one argument,
however, they return the additive or multiplicative inverse of their argument.
\beginlisp
                (- 3 4)                 -->  -1
                (- 3 4 5)               -->  -6
                (- 3)                   -->  -3
                (/ 3 4 5)               -->  3/20
                (/ 3)                   -->  1/3
\endlisp
\vskip 1pc

\spread
{\tt ({\bf 1+} {\it z})}{procedure}
\spread
{\tt ({\bf-1+} {\it z})}{procedure}

\unvpar
These procedures return the result of adding 1 to or subtracting 1 from their argument.

\vskip 1pc
\spread
{\tt ({\bf abs} {\it z})}{essential procedure}

\unvpar
Returns the magnitude of its argument.
\beginlisp
                (abs -7)                -->  7
                (abs -3+4i)             -->  5
\endlisp

\spread
{\tt ({\bf quotient} {\it n1} {\it n2})}{essential procedure}
\spread
{\tt ({\bf remainder} {\it n1} {\it n2})}{essential procedure}
\spread
{\tt ({\bf modulo} {\it n1} {\it n2})}{procedure}

\unvpar
In general, these are intended to implement number-theoretic (integer) division:
For positive integers $n▶01◀1$ and $n▶01◀2$, if $n▶01◀3$ and $n▶01◀4$ are integers such that
$n▶01◀1=n▶01◀2n▶01◀3+n▶01◀4$ and $0\leq n▶01◀4 < n▶01◀2$,
then
\beginlisp
                (quotient {\it n1} {\it n2})        -->  {\it n3}
                (remainder {\it n1} {\it n2})       -->  {\it n4}
                (modulo {\it n1} {\it n2})          -->  {\it n4}
\endlisp

\vpar
The value returned by {\tt quotient} always has the sign of the product of its
arguments.  {\tt Remainder} and {\tt modulo} differ on negative arguments as do the Common
Lisp {\tt rem} and {\tt mod} procedures---the {\tt remainder} always has the sign of the
dividend, the {\tt modulo} always has the sign of the divisor:
\beginlisp
                (modulo 13 4)           -->  1
                (remainder 13 4)        -->  1
 
                (modulo -13 4)          -->  3
                (remainder -13 4)       -->  -1
 
                (modulo 13 -4)          -->  -3
                (remainder 13 -4)       -->  1
 
                (modulo -13 -4)         -->  -1
                (remainder -13 -4)      -->  -1
\endlisp
\vskip 1pc
\spread
{\tt ({\bf gcd} {\it n1} $\ldots$)}{procedure}
\spread
{\tt ({\bf lcm} {\it nl} $\ldots$)}{procedure}

\unvpar
These procedures return the greatest common divisor or least common
multiple of their arguments. The result is always non-negative.
\beginlisp
                (gcd 32 -36)            -->  4
                (gcd)                   -->  0
                (lcm 32 -36)            -->  288
                (lcm)                   -->  1
\endlisp
\vskip 1pc
\spread
{\tt ({\bf floor} {\it x})}{procedure}
\spread
{\tt ({\bf ceiling} {\it x})}{procedure}
\spread
{\tt ({\bf truncate} {\it x})}{procedure}
\spread
{\tt ({\bf round} {\it x})}{procedure}
\spread
{\tt ({\bf rationalize} {\it x} {\it y})}{procedure}
\spread
{\tt ({\bf rationalize} {\it x})}{procedure}

\unvpar 
These procedures create integers and rationals.  Their results are not EXACT---in
fact, their results are clearly INEXACT, though they can be made EXACT with
an explicit exactness coercion.

\vskip 1pc
\vpar
{\tt Floor} returns the largest integer not larger than {\it x}.  {\tt Ceiling} returns
the smallest integer not smaller than {\it x}.  {\tt Truncate} returns the integer
of maximal absolute value not larger than the absolute value of {\it x}.
{\tt Round} returns the closest integer to {\it x}, rounding to even when
{\it x} is
halfway between two integers.  With two arguments, {\tt rationalize}
produces the best rational approximation to {\it x} within the tolerance
specified by {\it y}.  With one argument, {\tt rationalize} produces the best
rational approximation to {\it x}, preserving all of the precision in its
representation.
\vskip 1pc
\spread {\tt ({\bf exp} {\it z})}{procedure}
\spread {\tt ({\bf log} {\it z})}{ procedure}
\spread {\tt ({\bf expt} {\it z1} {\it z2})}{procedure}
\spread {\tt ({\bf sqrt} {\it z})}{procedure}
\spread {\tt ({\bf sin} {\it z})}{procedure}
\spread {\tt ({\bf cos} {\it z})}{procedure}
\spread {\tt ({\bf tan} {\it z})}{procedure}
\spread {\tt ({\bf asin} {\it z})}{procedure}
\spread {\tt ({\bf acos} {\it z})}{procedure}
\spread {\tt ({\bf atan} {\it z1} {\it z2})}{procedure}

\unvpar
These procedures are part of every implementation that supports real numbers. 
Their meanings conform with the Common Lisp standard.  (Implementors should be
careful of the branch cuts if complex numbers are allowed.)

\vskip 1pc
\spread {\tt ({\bf make-rectangular} {\it x1} {\it x2})}{procedure}
\spread {\tt ({\bf make-polar} {\it x3} {\it x4})}{procedure}
\spread {\tt ({\bf real-part} {\it z})}{procedure}
\spread {\tt ({\bf imag-part} {\it z})}{procedure}
\spread {\tt ({\bf magnitude} {\it z})}{procedure}
\spread {\tt ({\bf angle} {\it z})}{procedure}

\unvpar
These procedures are part of every implementation that supports complex numbers.
Suppose $x▶01◀1$, $x▶01◀2$, $x▶01◀3$, and $x▶01◀4$ are real numbers
and $z$ is a complex number such that
$$ z = x▶01◀1 + x▶01◀{2}{\hbox{\bf i}} = x▶01◀3 \cdot e▶8b◀{{\displaystyle{\hbox{\bf i}} x▶01◀4}}$$
Then {\tt make-rectangular} and {\tt make-polar} return $z$, {\tt
real-part} returns $x▶01◀1$, {\tt imag-part}
returns $x▶01◀2$, {\tt magnitude} returns $x▶01◀3$, and {\tt angle}
returns $x▶01◀4$.

\vskip 1pc
\spread {\tt ({\bf exact-}>{\bf inexact} {\it z})}{procedure}
\spread {\tt ({\bf inexact-}>{\bf exact} {\it z})}{procedure}
 
\unvpar
{\tt exact->inexact} returns an INEXACT representation of {\it z}, which is a fairly
harmless thing to do.  {\tt inexact->exact} returns an EXACT representation of {\it z}.
Since the law of "garbage in, garbage out" remains in force, {\tt inexact->exact}
should not be used casually.


\heading{Numerical Input and Output}

\unvpar
Scheme allows all the traditional ways of writing numerical constants, though
any particular implementation may support only some of them.  These syntaxes are
intended to be purely notational; any kind of number may be written in any form
that the user deems convenient.  Of course, writing 1/7 as a limited-precision
decimal fraction will not express the number exactly, but this approximate form
of expression may be just what the user wants to see.

\vskip 1pc
\vpar
Scheme numbers are written according to the grammar described below.  In that
description, {\it x*} means zero or more occurrences of {\it x}.  Spaces never appear inside
a number, so all spaces in the grammar are for legibility.  {\tt <empty>} stands for
the empty string.

\beginlisp
  bit  -->  0  |  1
  oct  -->  0  |  1  |  2  |  3  |  4  |  5  |  6  |  7
  dit  -->  oct  |  8  |  9
  hit  -->  dit  |  a  |  b  |  c  |  d  |  e  |  f
                 |  A  |  B  |  C  |  D  |  E  |  F
\endlisp
\beginlisp
  radix2  -->  \verb"#"b  |  \verb"#"B
  radix8  -->  \verb"#"o  |  \verb"#"O
  radix10  -->  <empty>  |  \verb"#"d  |  \verb"#"D
  radix16  -->  \verb"#"x  |  \verb"#"X
  exactness  -->  <empty>  |  \verb"#"i  |  \verb"#"I  |  \verb"#"e  |  \verb"#"E
  precision  -->  <empty>  |  \verb"#"s  |  \verb"#"S  |  \verb"#"l  |  \verb"#"L
\endlisp
\beginlisp
  prefix2  -->  radix2 exactness precision
             |  radix2 precision exactness
             |  exactness radix2 precision
             |  exactness precision radix2
             |  precision radix2 exactness
             |  precision exactness radix2
\endlisp
\beginlisp
  prefix8  -->  radix8 exactness precision
             |  radix8 precision exactness
             |  exactness radix8 precision
             |  exactness precision radix8
             |  precision radix8 exactness
             |  precision exactness radix8
\endlisp
\beginlisp
  prefix10  -->  radix10 exactness precision
              |  radix10 precision exactness
              |  exactness radix10 precision
              |  exactness precision radix10
              |  precision radix10 exactness
              |  precision exactness radix10
\endlisp
\beginlisp
  prefix16  -->  radix16 exactness precision
              |  radix16 precision exactness
              |  exactness radix16 precision
              |  exactness precision radix16
              |  precision radix16 exactness
              |  precision exactness radix16
\endlisp
\beginlisp
  sign  -->  <empty>  |  +  |  -
  suffix  -->  <empty>  |  e sign dit dit*    |  E sign dit dit*
  ureal  -->  prefix2 bit bit* \verb"#"* suffix
           |  prefix2 bit bit* \verb"#"* / bit bit* \verb"#"* suffix
           |  prefix2 . bit bit* \verb"#"* suffix
           |  prefix2 bit bit* . bit* \verb"#"* suffix
           |  prefix2 bit bit* \verb"#"* . \verb"#"* suffix
\endlisp
\beginlisp
           |  prefix8 oct oct* \verb"#"* suffix
           |  prefix8 oct oct* \verb"#"* / oct oct* \verb"#"* suffix
           |  prefix8 . oct oct* \verb"#"* suffix
           |  prefix8 oct oct* . oct* \verb"#"* suffix
           |  prefix8 oct oct* \verb"#"* . \verb"#"* suffix
\endlisp
\beginlisp
           |  prefix10 dit dit* \verb"#"* suffix
           |  prefix10 dit dit* \verb"#"* / dit dit* \verb"#"* suffix
           |  prefix10 . dit dit* \verb"#"* suffix
           |  prefix10 dit dit* . dit* \verb"#"* suffix
           |  prefix10 dit dit* \verb"#"* . \verb"#"* suffix
\endlisp
\beginlisp
           |  prefix16 hit hit* \verb"#"* suffix
           |  prefix16 hit hit* \verb"#"* / hit hit* \verb"#"* suffix
           |  prefix16 . hit hit* \verb"#"* suffix
           |  prefix16 hit hit* . hit* \verb"#"* suffix
           |  prefix16 hit hit* \verb"#"* . \verb"#"* suffix
  real  -->  sign ureal
  number  -->  real  |  real + ureal i  |  real - ureal i
            |  real @ real
\endlisp

\vpar
The conventions used to print a number can be specified by a format, as described
later in this section.  The system provides a procedure, {\tt number->string}, that
takes a number and a format and returns as a string the printed expression of
the given number in the given format.
\vskip 1pc

             
\spread
{\tt ({\bf number-}>{\bf string}  {\it number format})}{procedure}

\unvpar
This procedure will mostly be used by sophisticated users and in system
programs.  In general, a naive user will need to know nothing about the formats
because the system printer will have reasonable default formats for all types of
NUMBERs.  The system reader will construct reasonable default numerical types
for numbers expressed in each of the formats it recognizes.  If a user needs
control of the coercion from strings to numbers he will use {\tt string->number},
which takes a string, an exactness, and a radix and produces a number of the
maximally precise applicable type expressed by the given string.
\vskip 1pc
 
\spread
{\tt ({\bf string-}>{\bf number} {\it string exactness radix})}{procedure}

\unvpar 
The {\it exactness} is a symbol, either {\tt E} (or {\tt EXACT}) or {\tt
I} (or {\tt INEXACT}).  The {\it radix}
is also a symbol: {\tt B} (or {\tt BINARY}), {\tt O} (or {\tt OCTAL}), {\tt D} (or
{\tt DECIMAL}), and {\tt X} (or
{\tt HEXADECIMAL}).  Returns a number of the maximally precise representation expressed
by the given {\it string}.  It is an error if {\it string} does not express a number
according to the grammar presented above.
 
 
\heading{Formats}

\unvpar
Formats may have parameters.  For example, the {\tt (SCI 5 2)} format specifies that a
number is to be expressed in Fortran scientific format with 5 significant places
and two places after the radix point.

\vskip 1pc
\vpar
In the following examples, the comment shows the format that was used to produce
the output shown:
\beginlisp
    123  +123  -123               ; (int)
    123456789012345678901234567   ; (int) ; a big one!
    355/113  +355/113  -355/113   ; (rat)
    +123.45  -123.45              ; (fix 2)
    3.14159265358979              ; (fix 14)
    3.14159265358979              ; (flo 15)
    123.450                       ; (flo 6)
    -123.45e-1                    ; (sci 5 2)
    123e3  123e-3  -123e-3        ; (sci 3 0)
    -1+2i                         ; (rect (int) (int))
    1.2@1.570796                  ; (polar (fix 1) (flo 7))
\endlisp

\vpar 
A numerical constant may be specified with an explicit radix by a prefix.  The
prefixes are: \verb"#"{\tt B} (binary), \verb"#"{\tt O} (octal),
\verb"#"{\tt D} (decimal), \verb"#"{\tt X} (hex).  A format may
specify that a number should be expressed in a particular radix.  The radix
prefix may also be suppressed.  For example, one may express a complex number in
polar form with the magnitude in octal and the angle in decimal as follows:
\beginlisp
\verb"#"o1.2@\verb"#"d1.570796327 ; (polar (flo 2 (radix o)) (flo (radix d)))
\verb"#"o1.2@1.570796327   ; (polar (flo 2 (radix o)) (flo (radix d s)))
\endlisp

\vpar
A numerical constant may be specified to be either EXACT or INEXACT by a prefix.
The prefixes are: \verb"#"{\tt I} (inexact), \verb"#"{\tt E} (exact).
An exactness prefix may appear before or after any radix prefix that is used.  A format may specify that a
number should be expressed with an explicit exactness prefix, or it may force
the exactness to be suppressed.  For example, the following are ways to output
an inexact value for pi:
\beginlisp
\verb"#"i355/113           ; (rat (exactness))
355/113             ; (rat (exactness s))
\verb"#"i3.1416            ; (fix 4 (exactness))
\endlisp

\vpar
An attempt to produce more digits than are available in the internal machine
representation of a number will be marked with a "\verb"#"" filling the extra digits. 
This is not a statement that the implementation knows or keeps track of the
significance of a number, just that the machine will flag attempts to produce 20
digits of a number that has only 15 digits of machine representation:
\beginlisp
3.14158265358979\verb"#"\verb"#"\verb"#"\verb"#"\verb"#"       ; (flo 20 (exactness s))
\endlisp

\vpar
In systems with both single and double precision FLONUMs we may want to specify
which size we want to use to represent a constant internally.  For example, we
may want a constant that has the value of pi rounded to the single precision
length, or we might want a long number that has the value 6/10.  In either case,
we are specifying an explicit way to represent an INEXACT number.  For this
purpose, we may express a number with a prefix that indicates short or long
FLONUM representation:
\beginlisp
\verb"#"S3.14159265358979   ; Round to short -- 3.141593
\verb"#"L.6                 ; Extend to long -- .600000000000000
\endlisp
 
 
\heading{Details of formats}

\unvpar 
The format of a number is a list beginning with a format descriptor, which is a
symbol such as {\tt SCI}.  Following the descriptor are parameters used by that
descriptor, such as the number of significant digits to be used.  Default values
are supplied for any parameters that are omitted.  Modifiers may appear next,
such as the {\tt RADIX} and {\tt EXACTNESS} descriptors described below, which themselves
take parameters.  The format descriptors are:
\vskip 1pc

\heading{\tt (INT)}

\unvpar
Express as an integer.  The radix point is implicit.  If there are not enough
significant places then insignificant digits will be flagged.  For example,
6.0238E23 (represented internally as a 7 digit FLONUM) would be printed as

{\tt 6023800\verb"#################"}
\vskip 1pc
 
\heading {\tt (RAT {\it n})}

\unvpar
Express as a rational fraction.  {\it n} specifies the largest denominator to be
used in constructing a rational approximation to the number being expressed.  If
{\it n} is omitted it defaults to infinity.
\vskip 1pc

\heading {\tt (FIX {\it n})}

\unvpar
Express with a fixed radix point.  {\it n} specifies the number of places to the
right of the radix point.  {\it n} defaults to the size of a single-precision FLONUM. 
If there are not enough significant places, then insignificant digits will be
flagged.  For example, 6.0238E23 (represented internally as a 7 digit FLONUM)
would be printed with a {\tt (FIX 2)} format as {\tt 6023800\verb"#################.##"}

\vskip 1pc
\heading {\tt (FLO {\it n})}

\unvpar
Express with a floating radix point.  {\it n}  specifies the total number of places to
be displayed.  {\it n} defaults to the size of a single-precision FLONUM.  If the
number is out of range, it is converted to {\tt (SCI)}.  {\tt (FLO H)} allows the system to
express a FLO heuristically for human consumption.
 
\vskip 1pc
\heading {\tt (SCI {\it n m})}

\unvpar
Express in exponential notation.  {\it n} specifies the total number of places to be
displayed.  {\it n} defaults to the size of a single-precision
FLONUM.  {\it m}  specifies
the number of places to the right of the radix point.  {\it m}
defaults to {\it n}-1.  {\tt (SCI H)} does heuristic expression.
 
\vskip 1pc
\heading {\tt (RECT {\it r i})}

\unvpar
Express as a rectangular form complex number.  {\it r} and {\it i} are formats for the real
and imaginary parts respectively.  They default to {\tt (HEUR)}.
 
\vskip 1pc
\heading {\tt (POLAR {\it m a})}

\unvpar
Express as a polar form complex number.  {\it m}  and {\it a}  are formats for the magnitude
and angle respectively.  {\it m} and {\it a}  default to {\tt (HEUR)}.

\vskip 1pc
\heading {\tt (HEUR)}

\unvpar
Express heuristically using the minimum number of digits required to get an
expression that when coerced back to a number produces the original machine
representation.  EXACT numbers are expressed as {\tt (INT)} or {\tt (RAT)}. INEXACT numbers
are expressed as {\tt (FLO H)} or {\tt (SCI H)} depending on their range.  Complex numbers
are expressed in {\tt (RECT)}.  This is the normal default of the system printer.
\vskip 1pc

\vpar
The following modifiers may be added to a numerical format specification:
\vskip 1pc

\heading {\tt (EXACTNESS {\it s})}

\unvpar
This controls the expression of the exactness label of a number.  {\it s} indicates
whether the exactness is to be {\tt E} (expressed) or {\tt S}
(suppressed).  {\it s} defaults to
{\it E}.  If no exactness modifier is specified for a format then the exactness is by
default not expressed.

\vskip 1pc
\heading {\tt (RADIX {\it r} {\it s})}

\unvpar
This forces a number to be expressed in the radix {\it r}.  {\it r}
may be the symbol {\tt B}
(binary), {\tt O} (octal), {\tt D} (decimal), or {\tt X} (hex).  {\it s} indicates whether the radix
label is to be {\tt E} (expressed) or {\tt S} (suppressed).  {\it s}
defaults to {\tt E}.  If no radix
modifier is specified then the default is decimal and the label is suppressed.
\filpage

\section{II.7  Characters}

\unvpar
Characters are written using the {\tt \#$\backslash$} notation of Common
Lisp.  For example:

\centerline{
\begintable[ll]
{\tt \#$\backslash$a}&; lower case letter\cr
{\tt \#$\backslash$A}&; upper case letter\cr
{\tt \#$\backslash$(}&; the left parentheses as a character\cr
{\tt \#$\backslash$}&; the space character\cr
{\tt \#$\backslash$space}&; the preferred way to write a space\cr
{\tt \#$\backslash$newline}&; the newline character\cr
\endtable
}
\vskip 1pc

\vpar
Characters written in the \verb"#"$\backslash$ notation are self-evaluating.  That is, they do not
have to be quoted in programs.
The \verb"#"$\backslash$ notation is not an essential part of Scheme, however.  Even
implementations that support the \verb"#"$\backslash$ notation for input do not have to support it
for output, and there is no requirement that the data type of characters be
disjoint from data types such as integers or strings.

\vskip 1pc
\vpar
Some of the procedures that operate on characters ignore the difference between
upper case and lower case.  The procedures that ignore case have the suffix
``{\tt -ci}'' (for ``case insensitive'').  If the operation is a
predicate, then the ``{\tt -ci}''
suffix precedes the ``{\tt ?}'' at the end of the name.
\vskip 1pc

\spread {\tt ({\bf char?} {\it obj})}{essential procedure}

\unvpar
Returns \verb"#"!true if {\it obj} is a character, otherwise returns \verb"#"!false.


\spread {\tt ({\bf char=?} {\it char1} {\it char2})}{essential procedure}
\spread {\tt ({\bf char}<{\bf ?} {\it char1} {\it char2})}{essential procedure}
\spread {\tt ({\bf char}>{\bf ?} {\it char1} {\it char2})}{essential procedure}
\spread {\tt ({\bf char}<{\bf =?} {\it char1} {\it char2})}{essential procedure}
\spread {\tt ({\bf char}>{\bf =?} {\it char1} {\it char2})}{essential procedure} 

\unvpar
Both {\it char1} and {\it char2} must be characters.  These procedures impose a total
ordering on the set of characters.  It is guaranteed that under this ordering:

\bpar
The upper case characters are in order.  For example, {\tt (char<? \verb"#"$\backslash$A \verb"#"$\backslash$B)} returns
\verb"#"!true.

\bpar
The lower case characters are in order.  For example, {\tt (char<? \verb"#"$\backslash$a \verb"#"$\backslash$b)} returns
\verb"#!true".

\bpar
The digits are in order.  For example, {\tt (char<? \verb"#"$\backslash$0 \verb"#"$\backslash$9)} returns \verb"#!true".

\bpar
Either all the digits precede all the upper case letters, or vice versa.

\bpar
Either all the digits precede all the lower case letters, or vice versa.

\vskip 1pc
\vpar
Some implementations may generalize these procedures to take more than two
arguments, as with the corresponding numeric predicates.

\spread
{\tt ({\bf char-ci=?} {\it char1} {\it char2})}{procedure}
\spread
{\tt ({\bf char-ci}<{\bf ?} {\it char1} {\it char2})}{procedure}
\spread
{\tt ({\bf char-ci}>{\bf ?} {\it char1} {\it char2})}{procedure}
\spread
{\tt ({\bf char-ci}<{\bf =?} {\it char1} {\it char2})}{procedure}
\spread
{\tt ({\bf char-ci}>{\bf =?} {\it char1} {\it char2})}{procedure}

\unvpar
Both {\it char1} and {\it char2}  must be characters.  These procedures are similar to
{\tt char=?} et cetera, but they treat upper case and lower case letters as the same. 
For example, {\tt (char-ci=? \verb"#"$\backslash$A \verb"#"$\backslash$a)} returns \verb"#!true".  Some implementations may
generalize these procedures to take more than two arguments, as with the
corresponding arithmetic predicates.
\vskip 1pc

\spread
{\tt ({\bf char-upper-case?} {\it char})}{procedure}
\spread
{\tt ({\bf char-lower-case?} {\it char})}{procedure}
\spread
{\tt ({\bf char-alphabetic?} {\it char})}{procedure}
\spread
{\tt ({\bf char-numeric?} {\it char})}{procedure}
\spread
{\tt ({\bf char-whitespace?} {\it char})}{procedure}

\unvpar 
{\it Char} must be a character These procedures return \verb"#!true"
if their arguments are upper case, lower case, alphabetic, numeric, or
whitespace characters, respectively, otherwise they return
\verb"#!false".  The following remarks, which are specific to the
ASCII character set, are intended only as a guide.  The alphabetic
characters are the 52 upper and lower case letters.  The numeric
characters are the 10 decimal digits.  The whitespace characters are
tab, line feed, form feed, carriage return, and space.
\vskip 1pc
 
\spread
{\tt ({\bf char-}>{\bf integer} {\it char})}{essential procedure}
\spread
{\tt ({\bf integer-}>{\bf char} {\it n})}{essential procedure}

\unvpar
Given a character, {\tt char->integer} returns an integer representation of the
character.  Given an integer that is the image of a character under
{\tt char->integer}, {\tt integer->char} returns a character.  These procedures implement
order isomorphisms between the set of characters under the {\tt char<=?} ordering and
the set of integers under the {\tt <=?} ordering.  That is, if
\beginlisp
        (char<=? {\it a} {\it b})                   -->  \verb"#!true"
        (<=? {\it x} {\it y})                       -->  \verb"#!true"
\endlisp

\vpar
and {\it x} and {\it y} are in the range of {\tt char->integer}, then
\beginlisp
        (<=? (char->integer {\it a})
             (char->integer {\it b}))         -->  \verb"#!true"
;\pbrk
        (char<=? (integer->char {\it x})
                 (integer->char {\it y}))     -->  \verb"#!true"
\endlisp
\vskip 1pc

\spread
{\tt ({\bf char-upcase} {\it char})}{procedure}
\spread
{\tt ({\bf char-downcase} {\it char})}{procedure}

\unvpar 
{\it char} must be a character.  These procedures return a character {\it char2}  such that
{\tt (char-ci=? {\it char} {\it char2})}.  In addition, if {\it char} is alphabetic, then the result of
{\tt char-upcase} is upper case and the result of {\tt char-downcase} is lower case.
\filpage

\section{II.8.  Strings}

\unvpar 
Strings are sequences of characters.  In some implementations of Scheme they are
immutable; other implementations provide destructive procedures such as
{\tt string-set!} that alter string objects.

\vskip 1pc
\vpar
Strings are written as sequences of characters enclosed within
doublequotes ({\tt "}).
A doublequote can be written inside a string only by escaping it with a
backslash ($\backslash$), as in

\begintcenter
{\tt "The word $\backslash$"Recursion$\backslash$" has many different meanings."}
\endtcenter

\vpar
A backslash can be written inside a string only by escaping it with another
backslash.  
Scheme does not specify the effect of a backslash within a string that is not
followed by a doublequote or backslash.

\vskip 1pc
\vpar
A string may continue from one line to the next, but this is usually a bad idea
because the exact effect varies from one computer system to another.

\vskip 1pc
\vpar
The {\it length} of a string is the number of characters that it contains.  This
number is a non-negative integer that is fixed when the string is created.  The
{\it valid indexes}  of a string are the nonnegative integers less than the length of
the string.  The first character of a string has index 0, the second has index
1, and so on.

\vskip 1pc
\vpar
In phrases such as ``the characters of {\it string} beginning with
index {\it start} and ending with index {\it end},'' it is understood
that the index {\it start} is inclusive, and the index {\it end} is
exclusive.  Thus if {\it start} and {\it end} are the same index, a
null substring is referred to, and if {\it start} is zero and {\it
end} is the length of {\it string}, then the entire string is referred
to.

\vskip 1pc
\vpar
Some of the procedures that operate on strings ignore the difference between
upper and lower case.  The versions that ignore case have the suffix
``{\tt -ci}'' (for
``case insensitive'').  If the operation is a predicate, then the ``{\tt -ci}'' suffix
precedes the ``{\tt ?}'' at the end of the name.
\vskip 1pc

\spread
{\tt ({\bf string?} {\it obj})}{essential procedure}

\unvpar
Returns \verb"#!true" if {\it obj} is a string, otherwise returns \verb"#!false".
\vskip 1pc
\spread
{\tt ({\bf string-null?}{\it string})}{essential procedure}

\unvpar
{\it string} must be a string.  Returns \verb"#!true" if {\it string} has  zero length, otherwise
returns \verb"#!false".
\vskip 1pc

\spread
{\tt ({\bf string=?} {\it string1} {\it string2})}{essential procedure}
\spread
{\tt ({\bf string-ci=?} {\it string1} {\it string2})}{procedure}

\unvpar
Returns \verb"#!true" if the two strings are the same length and contain the same
characters in the same positions, otherwise returns \verb"#!false".
{\tt string-ci=?} treats
upper and lower case letters as though they were the same character, but
{\tt string=?} treats upper and lower case as distinct characters.
\vskip 1pc

  
\spread
{\tt ({\bf string}<{\bf ?} {\it string1} {\it string2})}{essential procedure}
\spread
{\tt ({\bf string}>{\bf ?} {\it string1} {\it string2})}{essential procedure}
\spread
{\tt ({\bf string}<{\bf =?} {\it string1} {\it string2})}{essential procedure}
\spread
{\tt ({\bf string}>{\bf =?} {\it string1} {\it string2})}{essential procedure}
\spread
{\tt ({\bf string-ci}<{\bf ?} {\it string1} {\it string2})}{procedure}
\spread
{\tt ({\bf string-ci}>{\bf ?} {\it string1} {\it string2})}{procedure}
\spread
{\tt ({\bf string-ci}<{\bf =?} {\it string1} {\it string2})}{procedure}
\spread
{\tt ({\bf string-ci}>{\bf =?} {\it string1} {\it string2})}{procedure}

\unvpar
These procedures are the lexicographic extensions to strings of the
corresponding orderings on characters.  For example, {\tt string<?} is the
lexicographic ordering on strings induced by the ordering {\tt char<?} on characters. 
Some implementations may generalize these and the {\tt string=?} and
{\tt string-ci=?}
procedures to take more than two arguments.
\vskip 1pc
  
\spread
{\tt ({\bf make-string} {\it n})}{procedure}
\spread
{\tt ({\bf make-string} {\it n char})}{procedure}

\unvpar
{\it n} must be a non-negative integer, and {\it char} must be a character.  Returns a newly
allocated string of length {\it n}.  If {\it char} is given, then all elements of the string
are initialized to {\it char}, otherwise the contents of the {\it string} are unspecified.
\vskip 1pc 
\spread 
{\tt ({\bf string-length} {\it string})}{essential procedure}

\unvpar
Returns the number of characters in the given {\it string}.
\vskip 1pc
\spread
{\tt ({\bf string-ref} {\it string} {\it n})}{essential procedure}

\unvpar
{\it n} must be a nonnegative integer less than the {\tt
string-length} of {\it string}. Returns
character {\it n} using zero-origin indexing.
\vskip 1pc
\spread
{\tt ({\bf substring} {\it string} {\it start} {\it end})}{essential procedure}

\unvpar
{\it string} must be a string, and {\it start} and {\it end} must be
valid indexes of {\it string} with
{\it start} {\tt<=} {\it end}.  Returns a newly allocated string formed from the characters of
{\it string} beginning with index {\it start} and ending with index
{\it end}.
\filpage

\spread
{\tt ({\bf string-append} {\it string1} {\it string2})}{essential procedure}
\spread
{\tt ({\bf string-append} {\it string1} $\ldots$)}{procedure}

\unvpar 
Returns a new string whose characters form the catenation of the given strings.

\vskip 1pc
\spread
{\tt ({\bf string-}>{\bf list} {\it string})}{essential procedure}
\spread
{\tt ({\bf list-}>{\bf string} {\it chars})}{essential procedure}

\unvpar 
{\tt string->list} returns a list of the characters that make up the
given string.  {\tt list->string} returns a string formed from the
proper list of characters {\it chars}.  {\tt string->list} and {\tt
list->string} are inverses so far as {\tt equal?} is concerned.
Implementations that provide destructive operations on strings should
ensure that the results of these procedures are newly allocated
objects.
\vskip 1pc
\spread
{\tt ({\bf string-set!} {\it string} {\it n} {\it char})}{procedure}

\unvpar 
{\it string} must be a string, {\it n} must be a valid index of {\it
string}, and {\it char} must be a
character.  Stores {\it char} in element {\it n} of {\it string} and returns an unspecified
value.
\vskip 1pc
\spread
{\tt ({\bf string-fill!} {\it string} {\it char})}{procedure}

\unvpar 
Stores {\it char} in every element of the given {\it string} and returns an unspecified
value.
\vskip 1pc
\spread
{\tt ({\bf string-copy} {\it string})}{procedure}

\unvpar
Returns a newly allocated copy of the given {\it string}.
\vskip 1pc 
\spread
{\tt ({\bf substring-fill!} {\it string} {\it start} {\it end} {\it char})}{procedure}

\unvpar
Stores {\it char} in elements {\it start} through {\it end} of the
given {\it string} and returns an
unspecified value.
\vskip 1pc 
\spread
{\tt ({\bf substring-move-right!} {\it s1} {\it m1} {\it n1} {\it s2}
{\it m2})}{procedure}
\spread
{\tt ({\bf substring-move-left!} {\it s1} {\it m1} {\it n1} s{\it 2}
{\it m2})}{procedure}

\unvpar
{\it s1} and {\it s2} must be strings, {\it m1} and {\it n1} must be
valid indexes of {\it s1} with {\it m1} {\tt <=} {\it n1} and {\it m2}
must be a valid index of {\it s2}.  These procedures store the
elements {\it m1} through {\it n1} of {\it s1} into the string {\it
s2} starting at element {\it m2} and return an unspecified value.
\vskip 1pc
\vpar
The procedures differ only when {\it s1} and {\it s2} are {\tt eq?} and the substring being moved
overlaps the substring being replaced.  In this case, {\tt substring-move-right!}
copies serially, starting with the rightmost element and proceeding to the left,
while {\tt substring-move-left!} begins with the leftmost element and proceeds to the
right.
\filpage

\section {II.9.  Vectors}

\unvpar  
Vectors are heterogenous mutable structures whose elements are indexed by
integers. The first element in a vector is indexed by  zero, and the last element
is indexed by one less than the length of the vector.  A vector of length 3
containing the number  zero in element 0, the list ({\tt 2 2 2 2}) in element 1, and
the string ``{\tt Anna}'' in element 2 can be written as
\begintcenter
{\tt \verb"#"(0 (2 2 2 2) "Anna")}
\endtcenter

\vskip 1pc
\vpar
Implementations are not required to support this notation.

\vskip 1pc
\vpar
Vectors are created by the constructor procedure {\tt make-vector}.  The elements are
accessed and assigned by the procedures {\tt vector-ref} and {\tt vector-set!}.
\vskip 1pc 
\spread
{\tt ({\bf vector?} {\it obj})}{essential procedure}

\unvpar 
Returns \verb"#!true" if {\it obj} is a vector, otherwise returns \verb"#!false".
\vskip 1pc
\spread
{\tt ({\bf make-vector} {\it size})}{essential procedure}
\spread
{\tt ({\bf make-vector} {\it size} {\it fill})}{procedure}

\unvpar
Returns a newly allocated vector of {\it size} elements.  If a second argument is
given, then each element is initialized to {\it fill}.  Otherwise the initial contents
of each element is unspecified.
\vskip 1pc 
\spread
{\tt ({\bf vector} {\it obj} $\ldots$)}{essential procedure}

\unvpar
Returns a newly allocated vector whose elements contain the given arguments. 
Analogous to {\tt list}.
\beginlisp
        (vector 'a 'b 'c)               -->  \verb"#"(a b c)
\endlisp
\vskip 1pc 
\spread
{\tt ({\bf vector-length} {\it vec})}{essential procedure}

\unvpar
Returns the number of elements in the vector {\it vec}.
\vskip 1pc
\spread
{\tt ({\bf vector-ref} {\it vec} {\it k})}{essential procedure}

\unvpar
Returns the contents of element {\it k} of the vector {\it vec}.  {\it k} must be a nonnegative
integer less than ({\tt vector-length} {\it vec}).
\beginlisp
  (vector-ref '\verb"#"(1 1 2 3 5 8 13 21) 5)  -->  8
\endlisp
\vskip 1pc
\spread
{\tt ({\bf vector-set!} {\it vec} {\it k} {\it obj})}{essential procedure}

\unvpar
Stores {\it obj} in element {\it k}  of the vector {\it vec}.  {\it k} must be a nonnegative integer
less than ({\tt vector-length} {\it vec}).  The value returned by {\tt vector-set!} is not
specified.
\beginlisp
    (let ((vec '\verb"#"(0 (2 2 2 2) "Anna")))
      (vector-set! vec 1 '("Sue" "Sue"))
      vec)                              -->  \verb"#"(0
                                               ("Sue" "Sue")
                                               "Anna")
\endlisp
\vskip 1pc
\spread
{\tt ({\bf vector-}>{\bf list} {\it vec})}{essential procedure}

\unvpar
Returns a list of the objects contained in the elements of {\it vec}.  See \linebreak
{\tt list->vector}.
\beginlisp
    (vector->list '\verb"#"(dah dah didah))    -->  (dah dah didah)
\endlisp
\vskip 1pc
\spread
{\tt ({\bf list-}>{\bf vector} {\it elts})}{essential procedure}

\unvpar
Returns a newly created vector whose elements are initialized to the elements of
the proper list {\it elts}.
\beginlisp
        (list->vector '(dididit dah))   -->  \verb"#"(dididit dah)
\endlisp
\vskip 1pc
\spread
{\tt ({\bf vector-fill!} {\it vec} {\it fill})}{procedure}

\unvpar
Stores {\it fill} in every element of the vector {\it vec.}  The value returned by
{\tt vector-fill!} is not specified.
\filpage

\section{II.10.  The object table}
\vskip 1pc 

\spread
{\tt ({\bf object-hash} {\it obj})}{procedure}
\spread
{\tt ({\bf object-unhash} {\it n})}{procedure}

\unvpar
{\tt object-hash} associates an integer with {\it obj} in a global     
table and returns {\it obj}. 
{\tt object-hash} guarantees that distinct objects (in the sense of
{\tt eq?}) are
associated with distinct integers.  {\tt object-unhash} takes an integer and returns
the object associated with that integer if there is one, returning \verb"#!false"
otherwise.

\vskip 1pc
\vpar 
{\it Rationale}:  {\tt object-hash} and {\tt object-unhash} can be implemented using association
lists and the {\tt assq} procedure, but the intent is that they be efficient hash
functions for general objects.  Furthermore it is intended that the Scheme
system is free to destroy and reclaim the storage of objects that are accessible
only through the object table.  It follows that {\tt object-unhash} is of questionable
utility, as illustrated by the following scenario.
\beginlisp
        >>> (define x (cons 0 0))
        x
        >>> (object-hash x)
        77
        >>> (set! x 0)
        $\ldots$
        >>> (gc)        ; garbage collection occurs for some reason
        $\ldots$
        >>> (object-unhash 77)
        {\it ???}            ; ill-defined: \verb"#!false" or (0 . 0)
\endlisp
\filpage

\section{II.11.  Procedures}

\unvpar
Procedures are created when lambda expressions are evaluated.  Procedures do not
have a standard printed representation.

\vskip 1pc
\vpar
The most common thing to do with a procedure is to call it with  zero or more
arguments.  A Scheme procedure may also be stored in data structures or passed
as an argument to procedures such as those described below.
 
\vskip 1pc
\spread
{\tt ({\bf apply} {\it proc} {\it args})}{essential procedure}
\spread
{\tt ({\bf apply} {\it proc} {\it arg1} $\ldots$ {\it args})}{procedure}

\unvpar
{\it proc} must be a procedure and {\it args} must be a proper list of arguments.  The
first (essential) form calls {\it proc} with the elements of {\it args} as the actual
arguments.  The second form is a generalization of the first that
calls {\it proc}
with the elements of {(\tt append ({\it list} {\it arg1} $\ldots$)
{\it args})} as the actual arguments.
\beginlisp
    (apply + (list 3 4))                -->  7
;\pbrk
    (define compose
      (lambda (f g)
        (lambda args
          (f (apply g args)))))         -->  {\it unspecified}
;\pbrk
    ((compose 1+ *) 3 4)                -->  13
\endlisp
\vskip 1pc
\spread
{\tt ({\bf map} {\it f} {\it plist})}{essential procedure}
\spread
{\tt ({\bf map} {\it f} {\it plist1} {\it plist2}
$\ldots$)}{procedure}

\unvpar 
{\it f} must be a procedure of one argument and the {\it plist}s must be proper lists.  If
more than one {\it plist} is given, then they should all be the same length.  Applies
f  element-wise to the elements of the {\it plist}s and returns a list of the results.
The order in which {\it f} is applied to the elements of the {\it plist}s is not
specified.
\beginlisp
    (map cadr '((a b) (d e) (g h)))     -->  (b e h)
;\pbrk 
    (map (lambda (n) (expt n n))
         '(1 2 3 4 5))                  -->  (1 4 27 256 3125)
;\pbrk
    (map + '(1 2 3) '(4 5 6))           -->  (5 7 9)
;\pbrk
    (let ((count 0))
      (map (lambda (ignored)
             (set! count (1+ count))
             count)
           '(a b c)))                   -->  {\it unspecified}
\endlisp
\filpage
 
\spread
{\tt ({\bf for-each} {\it f} {\it plist})}{essential procedure}
\spread
{\tt ({\bf for-each} {\it f} {\it plist1} {\it plist2} $\ldots$)}{procedure}

\unvpar 
The arguments to {\tt for-each} are like the arguments to {\tt map},
but {\tt for-each} calls {\it f} 
for its side effects rather than for its values.  Unlike {\tt map},
{\tt for-each} is
guaranteed to call {\it f} on the elements of the {\it plist}s in order from the first
element to the last, and the value returned by {\tt for-each} is not specified.
\beginlisp
    (let ((v (make-vector 5)))
      (for-each (lambda (i)
                  (vector-set! v i (* i i)))
                '(0 1 2 3 4))
      v)                                -->  \verb"#"(0 1 4 9 16)
\endlisp
\vskip 1pc
 
\spread
{\tt ({\bf call-with-current-continuation} {\it f})}{essential procedure}

\unvpar 
{\it f} must be a procedure of one argument.  {\tt call-with-current-continuation} packages
up the current continuation (see the Rationale below) as an ``escape procedure''
and passes it as an argument to {\it f}.  The escape procedure is an ordinary Scheme
procedure of one argument that, if it is later passed a value, will ignore
whatever continuation is in effect at that later time and will give the value
instead to the continuation that was in effect when the escape procedure was
created.

\vskip 1pc
\vpar
The escape procedure created by {\tt call-with-current-continuation} has unlimited
extent just like any other procedure in Scheme.  It may be stored in variables
or data structures and may be called as many times as desired.

\vskip 1pc
\vpar
The following examples show only the most common uses of
{\tt call-with-current-continuation}.  If all real programs were as simple as these
examples, there would be no need for a procedure with the power of
{\tt call-with-current-continuation}.
\beginlisp
    (call-with-current-continuation
      (lambda (exit)
        (for-each (lambda (x)
                    (if (negative? x)
                        (exit x)))
                  '(54 0 37 -3 245 19))
        \verb"#!true"))                        -->  -3
\endlisp
\beginlisp
    (define list-length
      (lambda (obj)
        (call-with-current-continuation
          (lambda (return)
            ((rec loop (lambda (obj)
                         (cond ((null? obj) 0)
                               ((pair? obj)
                                (1+ (loop (cdr obj))))
                               (else (return \verb"#!false")))))
             obj)))))
                                        -->  list-length
\endlisp
\beginlisp
    (list-length '(1 2 3 4))            -->  4
;\pbrk
    (list-length '(a b . c))            -->  \verb"#!false"
\endlisp

\vskip 1pc
\vpar
{\it Rationale}:  The classic use of {\tt call-with-current-continuation} is for structured,
non-local exits from loops or procedure bodies, but in fact
{\tt call-with-current-continuation} is extremely useful for
implementing a wide variety of advanced control structures.

\vskip 1pc
\vpar
Whenever a Scheme expression is evaluated there is a {\it continuation} wanting the
result of the expression.  The continuation represents an entire (default)
future for the computation.  If the expression is evaluated at top level, for
example, then the continuation will take the result, print it on the screen,
prompt for the next input, evaluate it, and so on forever.  Most of the time the
continuation includes actions specified by user code, as in a continuation that
will take the result, multiply it by the value stored in a local variable, add
seven, and give the answer to the top level continuation to be printed. 
Normally these ubiquitous continuations are hidden behind the scenes and
programmers don't think much about them.  On rare occasions, however, when
programmers need to do something fancy, then they may need to deal with
continuations explicitly.  {\tt call-with-current-continuation} allows Scheme
programmers to do that by creating a procedure that acts just like the current
continuation.

\vskip 1pc
\vpar
Most serious programming languages incorporate one or more special purpose
escape constructs with names like {\tt exit}, {\tt return}, or even
{\tt goto}.  In 1965, however,
Peter Landin invented a general purpose escape operator called the J-operator. 
John Reynolds described a simpler but equally powerful construct in 1972.  The
{\tt catch} special form described by Sussman and Steele in the 1975 report on Scheme
is exactly the same as Reynolds's construct, though its name came from a less
general construct in MacLisp.  The fact that the full power of
Scheme's {\tt catch}
could be obtained using a procedure rather than a special form was noticed in
1982 by the implementors of Scheme 311, and the name {\tt call-with-current-continuation} was coined later that year.  Although the name is descriptive, some
people feel it is too long and have taken to calling the procedure
{\tt call/cc}.
\filpage

\section{II.12.  Ports}

\unvpar  
Ports represent input and output devices.  To Scheme, an input device is a
Scheme object that can deliver characters upon command, while an output device
is a Scheme object that can accept characters.
 
\vskip 1pc 
\spread
{\tt ({\bf call-with-input-file} {\it string} {\it proc})}{essential procedure}
\spread
{\tt ({\bf call-with-output-file} {\it string} {\it proc})}{essential procedure}

\unvpar
{\it Proc} is a procedure of one argument, and {\it string} is a string naming a file.  For
{\tt call-with-input-file}, the file must already exist; for {\tt call-with-output-file},
the effect is unspecified if the file already exists.  Calls {\it proc} with one
argument: the port obtained by opening the named file for input or output.  If
the file cannot be opened, an error is signalled.  If the procedure returns,
then the port is closed automatically and the value yielded by the procedure is
returned.  If the procedure does not return, then Scheme will not close the port
unless it can prove that the port will never again be used for a read or write
operation.

\vskip 1pc
\vpar
{\it Rationale}:  Because Scheme's escape procedures have unlimited extent, it  is
possible to escape from the current continuation but later to escape back in. 
If implementations were permitted to close the port on any escape from the
current continuation, then it would be impossible to write portable code using
both {\tt call-with-current-continuation} and {\tt call-with-input-port} or
{\tt call-with-output-port}.
 
\vskip 1pc 
\spread
{\tt ({\bf input-port?} {\it obj})}{essential procedure}
\spread
{\tt ({\bf output-port?} {\it obj})}{essential procedure}

\unvpar 
Returns \verb"#!true" if {\it obj} is an input port or output port (respectively), otherwise
returns \verb"#!false".
\vskip 1pc
\spread
{\tt ({\bf current-input-port})}{essential procedure}
\spread
{\tt ({\bf current-output-port})}{essential procedure}

\unvpar 
Returns the current default input or output port.
\vskip 1pc
 
\spread
{\tt ({\bf with-input-from-file} {\it string} {\it thunk})}{procedure}
\spread
{\tt ({\bf with-output-to-file} {\it string} {\it thunk})}{procedure}

\unvpar 
{\it thunk} is a procedure of no arguments, and {\it string}  is a string naming a file. 
For {\tt with-input-from-file}, the file must already exist; for {\tt with-output-to-file},
the effect is unspecified if the file already exists.  The file is opened for
input or output, an input or output port connected to it is made the default
value returned by {\tt current-input-port} or {\tt
current-output-port}, and the {\it thunk} is
called with no arguments.  When the {\it thunk} returns, the port is closed and the
previous default is restored.  {\tt with-input-from-file} and {\tt with-output-to-file}
return the value yielded by {\it thunk}.  Furthermore, in contrast to
{\tt call-with-input-file} and {\tt call-with-output-file}, these procedures will attempt to
close the default port and restore the previous default whenever the current
continuation changes in such a way as to make it doubtful that the
{\it thunk} will
ever return.
\vskip 1pc
\spread
{\tt ({\bf open-input-file} {\it filename})}{procedure}

\unvpar 
Takes a string naming an existing file and returns an input port capable of
delivering characters from the file.  If the file cannot be opened, an error is
signalled.
\vskip 1pc
\spread
{\tt ({\bf open-output-file} {\it filename})}{procedure}

\unvpar
Takes a string naming an output file to be created and returns an output port
capable of writing characters to a new file by that name.  If the file cannot be
opened, an error is signalled.  If a file with the given name already exists,
the effect is unspecified.
\vskip 1pc
\spread
{\tt ({\bf close-input-port} {\it port})}{procedure}
\spread
{\tt ({\bf close-output-port} {\it port})}{procedure}

\unvpar 
Closes the file associated with {\it port}, rendering the {\it port} incapable of delivering
or accepting characters.  The value returned is not specified.
\filpage

\section{II.13.  Input}

\unvpar
The {\tt read} procedure converts written representations of Scheme objects into the
objects themselves.  The written representations for Scheme objects are
described in the sections devoted to the operations on those objects.
\vskip 1pc
 
\spread
{\tt ({\bf eof-object?} {\it obj})}{essential procedure}

\unvpar
Returns \verb"#!true" if {\it obj} is an end of file object, otherwise returns \verb"#!false".  The
precise set of end of file objects will vary among implementations, but in any
case no end of file object will ever be a character or an object that can be
read in using {\tt read}.
\vskip 1pc
\spread
{\tt ({\bf read})}{essential procedure}
\spread
{\tt ({\bf read} {\it port})}{essential procedure}

\unvpar 
Returns the next object parsable from the given input {\it port},
updating {\it port} to
point to the first character past the end of the written representation of the
object.  If an end of file is encountered in the input before any characters are
found that can begin an object, then an end of file object is returned.  If an
end of file is encountered after the beginning of an object's written
representation, but the written representation is incomplete and therefore not
parsable, an error is signalled.  The {\it port} argument may be omitted, in which
case it defaults to the value returned by {\tt current-input-port}.     

\vskip 1pc
\vpar
{\it Rationale}:  This corresponds to Common Lisp's {\tt read-preserving-whitespace}, but
for simplicity it is never an error to encounter end of file except in the
middle of an object.
\vskip 1pc
\spread
{\tt ({\bf read-char})}{essential procedure}
\spread
{\tt ({\bf read-char} {\it port})}{essential procedure}

\unvpar
Returns the next character available from the input {\it port},
updating the {\it port} to
point to the following character.  If no more characters are available, an end
of file object is returned.  {\it port} may be omitted, in which case it defaults to
the value returned by {\tt current-input-port}.  

\vskip 1pc
\spread
{\tt ({\bf char-ready?})}{procedure}
\spread
{\tt ({\bf char-ready?} {\it port})}{procedure}

\unvpar 
Returns \verb"#!true" if a character is ready on the input {\it port} and returns \verb"#!false"
otherwise.  If {\tt char-ready} returns \verb"#!true" then the next
{\tt read-char} operation on
the given {\it port} is guaranteed not to hang.  If the {\it port} is at end of file then
{\tt char-ready?} returns \verb"#!true".  {\it port} may be omitted, in which case it defaults to
the value returned by {\tt current-input-port}.

\vskip 1pc
\vpar
{\it Rationale}:  {\tt char-ready?} exists to make it possible for a program to accept
characters from interactive ports without getting stuck waiting for input.  Any
rubout handlers associated with such ports must ensure that characters whose
existence has been asserted by {\tt char-ready?} cannot be rubbed out.  If
{\tt char-ready?} were to return \verb"#!false" at end of file, a port at end of file would
be indistinguishable from an interactive port that has no ready
characters.
\vskip 1pc
\spread
{\tt ({\bf load} {\it filename})}{essential procedure}

\unvpar
{\it filename} should be a string naming an existing file containing Scheme source
code.  The {\tt load} procedure reads expressions from the file and evaluates them
sequentially as though they had been typed interactively.  It is not specified
whether the results of the expressions are printed, however.  The {\tt load} procedure
does not affect the values returned by {\tt current-input-port} and
{\tt current-output-port}.  {\tt load} returns an unspecified value.

\vskip 1pc
\vpar
{\it Rationale}:  For portability {\tt load} must operate on source files.  Its operation on
other kinds of files necessarily varies among implementations.
\filpage

\section{II.14.  Output}
\vskip 1pc 
\spread
{\tt ({\bf write} {\it obj})}{essential procedure}
\spread
{\tt ({\bf write} {\it obj} {\it port})}{essential procedure}

\unvpar 
Writes a representation of {\it obj} to the given {\it port}.  Strings that appear in the
written representation are enclosed in doublequotes, and within those strings
backslash and doublequote characters are escaped by backslashes. 
{\it write} returns an unspecified value.  The {\it port} argument may be omitted, in which
case it defaults to the value returned by {\tt current-output-port}.  See
{\tt display}.
\vskip 1pc
\spread
{\tt ({\bf display} {\it obj})}{essential procedure}
\spread
{\tt ({\bf display} {\it obj} {\it port})}{essential procedure}

\unvpar
Writes a representation of {\it obj} to the given {\it port}.  Strings that appear in the
written representation are not enclosed in doublequotes, and no characters are
escaped within those strings. {\it display} returns an unspecified
value.  The {\it port}
argument may be omitted, in which case it defaults to the value returned by
{\tt current-output-port}.  See {\tt write}.

\vskip 1pc
\vpar
{\it Rationale}:  Like Common Lisp's {\tt prin1} and {\tt princ}, {\tt write} is for producing
machine-readable output and {\tt display} is for producing human-readable output. 
Implementations that allow ``slashification'' within symbols will probably want
{\tt write} but not {\tt display} to slashify funny characters in symbols.
\vskip 1pc
\spread
{\tt ({\bf newline})}{essential procedure}
\spread
{\tt ({\bf newline} {\it port})}{essential procedure}

\unvpar
Writes an end of line to {\it port}.  Exactly how this is done differs from one
operating system to another.  Returns an unspecified value.  The {\it port} argument
may be omitted, in which case it defaults to the value returned by
{\tt current-output-port}.
\vskip 1pc
\spread
{\tt ({\bf write-char} {\it char})}{essential procedure}
\spread
{\tt ({\bf write-char} {\it char} {\it port})}{essential procedure}

\unvpar 
Writes the character {\it char} (not a written representation of the character) to the
given {\it port} and returns an unspecified value.  The {\it port} argument may be omitted,
in which case it defaults to the value returned by {\tt
current-output-port}.
\filpage

\spread
{\tt ({\bf transcript-on} {\it filename})}{procedure}
\spread
{\tt ({\bf transcript-off})}{procedure}

\unvpar
{\it Filename} must be a string naming an output file to be created.  The effect of
{\tt transcript-on} is to open the named file for output, and to cause a transcript of
subsequent interaction between the user and the Scheme system to be written to
the file.  The transcript is ended by a call to {\tt transcript-off}, which closes the
transcript file.  Only one transcript may be in progress at any time, though
some implementations may relax this restriction.  The values returned by these
procedures are unspecified.

\vskip 1pc
\vpar
{\it Rationale}:  These procedures are redundant in some systems, but systems that
need them should provide them.
\filpage 

\section{Bibliography and References}

\atpar{1.}
Harold Abelson and Gerald Jay Sussman with Julie Sussman,
{\it Structure and Interpretation of Computer Programs}.  MIT Press,
Cambridge MA, 1985.

\atpar{2.}
John Batali, Chris Hanson, Neil Mayle, Howard Shrobe, Richard M.
Stallman, and Gerald Jay Sussman, The Scheme-81 Architecture---System
and Chip. In {\it Proceedings of the MIT Conference on Advanced
Research in VLSI}, Paul Penfield Jr [ed], Artech House, Dedham MA,
1982.

\atpar{3.}
William Clinger, The Scheme 311 Compiler: an Exercise in
Denotational Semantics.  In {\it Conference Record of the 1984 ACM
Symposium on Lisp and Functional Programming}, August 1984, pages
356-364.

\atpar{4.}
Carol Fessenden, William Clinger, Daniel P Friedman, and
Christopher Haynes, Scheme 311 Version 4 Reference Manual.
Indiana University Computer Science Technical Report 137,
February 1983.

\atpar{5.}
D Friedman, C Haynes, E Kohlbecker, and M Wand, Scheme 84
Interim Reference Manual. Indiana University Computer Science
Technical Report 153, January 1985.

\atpar{6.}
Daniel P Friedman and Christopher T Haynes, Constraining
Control.  In {\it Proceedings of the Twelfth Annual ACM Symposium on
Principles of Programming Languages}, January 1985, pages 245-254.

\atpar{7.}
Christopher T Haynes, Daniel P Friedman, and Mitchell
Wand, Continuations and coroutines.  In {\it Conference Record of the
1984 ACM Symposium on Lisp and Functional Programming}, August
1984, pages 293-298.

\atpar{8.}
Peter Landin, A Correspondence Between Algol 60 and
Church's Lambda Notation: Part I.  In {\it Communications of the ACM},
8(2), February 1965, pages 89-101.

\atpar{9.}
Drew McDermott, An Efficient Environment Allocation
Scheme in an Interpreter for a Lexically-scoped Lisp.  In
{\it Conference Record of the 1980 Lisp Conference}, August 1980, pages
154-162.

\atpar{10.}
Steven S Muchnick and Uwe F Pleban, A Semantic Comparison
of Lisp and Scheme.  In {\it Conference Record of the 1980 Lisp
Conference}, August 1980, pages 56-64.

\atpar{11.}
MIT Scheme Manual, Seventh Edition, September 1984.

\atpar{12.}
Peter Naur et al, Revised Report on the Algorithmic
Language Algol 60.  In {\it Communications of the ACM}, 6(1), January
1963, pages 1-17.

\atpar{13.}
Kent M Pitman, The Revised MacLisp Manual.  MIT
Artificial Intelligence Laboratory Technical Report 295, 21 May
1983 (Saturday Evening Edition).

\atpar{14.}
Jonathan A Rees and Norman I Adams IV, T: A Dialect of
Lisp or, LAMBDA: The Ultimate Software Tool.  In {\it Proceedings of
the 1982 ACM Symposium on Lisp and Functional Programming}, August
1982, pages 114-122.

\atpar{15.}
Jonathan A Rees, Norman I Adams IV, and James R Meehan,
The T Manual. Fourth Edition, 10 January 1984.

\atpar{16.}
John Reynolds, Definitional Interpreters for Higher Order
Programming Languages.  In {\it ACM Conference Proceedings}, 1972,
pages 717-740.

\atpar{17.}
Richard M Stallman, Phantom Stacks---If You Look Too
Hard, They Aren't There.  MIT Artificial Intelligence Memo 556,
July 1980.

\atpar{18.}
Guy Lewis Steele Jr, and Gerald Jay Sussman, Lambda, the Ultimate Imperative.
MIT Artificial Intelligence Memo 353, March 1976.

\atpar{19.}
Guy Lewis Steele Jr, Lambda, The Ultimate Declarative.
MIT Artificial Intelligence Memo 379, November 1976.

\atpar{20.}
Guy Lewis Steele Jr, Debunking the ``Expensive Procedure
Call'' Myth, or Procedure Call Implementations Considered Harmful,
or Lambda, The Ultimate GOTO. In {\it ACM Conference Proceedings},
1977, pages 153-162.

\atpar{21.}
Guy Lewis Steele Jr, Rabbit: a Compiler for Scheme.  MIT
Artificial Intelligence Laboratory Technical Report 474, May
1978.

\atpar{22.}
Guy Lewis Steele Jr, An overview of Common Lisp.  In Conference
Record of the 1982 {\it ACM Symposium on Lisp and Functional
Programming}, August 1982, pages 98-107.

\atpar{23.}
Guy Lewis Steele Jr, Common Lisp: the Language.  Digital
Press, 1984.

\atpar{24.}Guy Lewis Steele Jr and Gerald Jay Sussman, The revised
report on Scheme, a dialect of Lisp.  MIT Artificial Intelligence
Memo 452, January 1978.

\atpar{25.}
Guy Lewis Steele Jr and Gerald Jay Sussman, The Art of
the Interpreter, or The Modularity Complex (Parts  Zero, One, and
Two).  MIT Artificial Intelligence Memo 453, May 1978.

\atpar{26.}
Guy Lewis Steele Jr and Gerald Jay Sussman, Design of a
Lisp-Based Processor.  In {\it Communications of the ACM}, 23(11),
November 1980, pages 628-645.

\atpar{27.}
Guy Lewis Steele Jr and Gerald Jay Sussman, The Dream of a
Lifetime: A Lazy Variable Extent Mechanism.  In {\it Conference Record
of the 1980 Lisp Conference, August 1980}, pages 163-172.

\atpar{28.}
Gerald Jay Sussman and Guy Lewis Steele Jr, Scheme: an
Interpreter for Extended Lambda Calculus.  MIT Artificial
Intelligence Memo 349, December 1975.

\atpar{29.}
Gerald Jay Sussman, Jack Holloway, Guy Lewis Steele Jr, and Alan
Bell, Scheme-79---Lisp on a chip.  In {\it IEEE Computer},  14(7),
July 1981, pages 10-21.

\atpar{30.}
Mitchell Wand, Continuation-based Program Transformation
Strategies.  In {\it Journal of the ACM}, 27(1), 1978, pages 174-180.

\atpar{31.}
Mitchell Wand, Continuation-based Multiprocessing.  In
{\it Conference Record of the 1980 Lisp Conference}, August 1978, pages
19-28.

\filpage

\tcenter{\bf Index}

\vskip 1pc

\centerline{

\begindisplaytable [lR]

\verb"#!false"&22\cr
\verb"#!null"&29\cr
\verb"#!true"&22\cr
'&12\cr
i*&39\cr      
+&39\cr      
-&39\cr       
-1+&39\cr    
/&39\cr
1+&39\cr     
{\tt <}&38\cr      
{\tt <}=&38\cr     
{\tt <}=?&38\cr
{\tt <}?&38\cr      
=&38\cr       
=?&38\cr     
{\tt >}&38\cr       
{\tt >}=&38\cr     
{\tt >}=?&38\cr     
{\tt >}?&38\cr      
`&20\cr       
abs&39\cr    
acos&41\cr    
and&15\cr
angle&41\cr   
append&30\cr
append!&30\cr
apply&57\cr   
asin&41\cr    
assoc&31\cr
assq&31\cr
assv&31\cr
atan&41\cr
backquote&20\cr 
begin&19\cr
binding construct&11\cr
bound&11\cr
caaaar&28\cr
caaadr&28\cr  
caaar&28\cr
caadar&28\cr
caaddr&29\cr
caadr&28\cr
caar&28\cr
cadaar&29\cr
cadadr&29\cr
cadar&28\cr
caddar&29\cr
cadddr&29\cr
caddr&28\cr
cadr&28\cr
call-with-current-continuation&58\cr
call-with-input-file&61\cr
call-with-output-file&61\cr
car&28\cr
case&14\cr
cdaaar&29\cr
cdaadr&29\cr
cdaar&28\cr
cdadar&29\cr
cdaddr&29\cr
cdadr&28\cr
cdar&28\cr
cddaar&29\cr
cddadr&29\cr
cddar&28\cr
cdddar&29\cr
cddddr&29\cr
cdddr&28\cr
cddr&28\cr
cdr&28\cr
ceiling&40\cr
char-{\tt >}integer&49\cr
char-alphabetic?&49\cr
char-ci{\tt <}=?&49\cr
char-ci{\tt <}?&49\cr       
char-ci=?&49\cr      
char-ci{\tt >}=?&49\cr     
char-ci{\tt >}?&49\cr       
char-downcase&50\cr  
char-lower-case?&49\cr   
char-numeric?&49\cr
char-ready?&63\cr
char-upcase&50\cr     
char-upper-case?&49\cr 
char-whitespace?&49\cr      
char{\tt <}=?&48\cr
char{\tt <}?&48\cr
char=?&48\cr
char{\tt >}=?&48\cr
char{\tt >}?&48\cr
char?&48\cr
close-input-port&62\cr
close-output-port&62\cr     
comment&6\cr 
complex?&37\cr    
cond&14\cr
cons&27\cr 
constant&9\cr  
cos&41\cr
current-input-port&61\cr
current-output-port&61\cr     
define&17,18\cr
display&65\cr
do&19\cr
else&14,15\cr
empty list&26\cr   
environment&11\cr
eof-object?&63\cr
eq?&24\cr
equal?&25\cr
eqv?&25\cr
essential&9\cr 
even?&38\cr
exact-{\tt >}inexact&41\cr
exact?&38\cr
exact numbers&36\cr
exactness&47\cr
exp&41\cr
expt&41\cr
false&22\cr
fix&46\cr
flo&46\cr
floor&40\cr
for-each&58\cr
formats&44\cr
gcd&40\cr
heur&47\cr
identifier&5\cr
if&13\cr
imag-part&41\cr
inexact numbers&36\cr
inexact-{\tt >}exact&41\cr
inexact?&38\cr
input-port?&61\cr
int&46\cr
integer-{\tt >}char&49\cr
integer?&37\cr
keyword&11\cr
lambda& 12,13\cr
last-pair&31\cr
lcm&40\cr
length&30\cr
let&15\cr
let*&16\cr
letrec&16\cr
list&29\cr
list&27\cr
list-{\tt >}string&53\cr
list-{\tt >}vector&55\cr
list-ref&30\cr
list-tail&30\cr     
load&64\cr
log&41\cr    
macros&20\cr
magnitude&41\cr
make-polar&41\cr     
make-rectangular&41\cr
make-string&52\cr
make-vector&54\cr
map&57\cr
max&38\cr
member&31\cr
memq&31\cr
memv&31\cr
min&38\cr
modulo&39\cr
named-lambda&17\cr
negative?&38\cr
newline&64\cr
nil&22\cr
not&22\cr
null?&29\cr
number-{\tt >}string&44\cr
number?&37\cr
object-hash&56\cr
object-unhash&56\cr
odd?&38\cr
open-input-file&62\cr
open-output-file&62\cr
or&15\cr
output-port?&61\cr
pair&26\cr
pair?&27\cr
polar&47\cr
positive?&38\cr
precision&45\cr
procedure&9\cr      
procedure call&12\cr
proper list&26\cr
quote&12\cr
quotient&39\cr
radix&47\cr
rat&46\cr
rational?&37\cr
rationalize&40\cr
read&64\cr
read-char&63\cr
real-part&41\cr      
real?&37\cr
rec&17\cr
rect&46\cr
region&11\cr
remainder&39\cr
reverse&30\cr
round&40\cr
sci&46\cr
sequence&19\cr
set!&18\cr
set-car!&28\cr  
set-cdr!&28\cr      
signal an error&10\cr
sin&41\cr
special form&9,11\cr
sqrt&41\cr
string-{\tt >}list&53\cr
string-{\tt >}number&44\cr
string-{\tt >}symbol&34\cr
string-append&53\cr
string-ci{\tt <}=?&52\cr
string-ci{\tt <}?&52\cr
string-ci=?&52\cr    
string-ci{\tt >}=?&52\cr   
string-ci{\tt >}?&52\cr
string-copy&53\cr    
string-fill!&53\cr
string-length&52\cr
string-null?&51\cr
string-ref&52\cr
string-set!&53\cr
string{\tt <}=?&52\cr     
string{\tt <}?&52\cr       
string=?&52\cr      
string{\tt >}=?&52\cr     
string{\tt >}?&52\cr       
string?&51\cr
substring&52\cr    
substring-fill!&53\cr
substring-move-left!&53\cr
substring-move-right!&53\cr
symbol-{\tt >}string&34\cr
symbol?&33\cr
t&22\cr       
tan&41\cr    
transcript-off&66\cr
transcript-on&66\cr
true&22\cr 
truncate&40\cr  
unbound variable&11\cr
variable&9,11\cr
vector&54\cr 
vector-{\tt >}list&55\cr
vector-fill!&55\cr
vector-length&54\cr
vector-ref&54\cr
vector-set!&54\cr     
vector?&54\cr
with-input-from-file&61\cr
with-output-to-file&61\cr
write&65\cr
write-char&65\cr 
zero?&38\cr

\enddisplaytable
}


\vfill\eject
\end