R5RS
R5RS
Scheme
RICHARD KELSEY, WILLIAM CLINGER, AND JONATHAN REES (Editors)
H. ABELSON R. K. DYBVIG C. T. HAYNES G. J. ROZAS
N. I. ADAMS IV D. P. FRIEDMAN E. KOHLBECKER G. L. STEELE JR.
D. H. BARTLEY R. HALSTEAD D. OXLEY G. J. SUSSMAN
G. BROOKS C. HANSON K. M. PITMAN M. WAND
INTRODUCTION
Programming languages should be designed not by piling munity, and so we grant permission to copy it in whole or in
feature on top of feature, but by removing the weaknesses part without fee. In particular, we encourage implementors
and restrictions that make additional features appear nec- of Scheme to use this report as a starting point for manuals
essary. Scheme demonstrates that a very small number of and other documentation, modifying it as necessary.
rules for forming expressions, with no restrictions on how
they are composed, suffice to form a practical and efficient
Acknowledgements
programming language that is flexible enough to support
most of the major programming paradigms in use today. We would like to thank the following people for their
Scheme was one of the first programming languages to in- help: Alan Bawden, Michael Blair, George Carrette, Andy
corporate first class procedures as in the lambda calculus, Cromarty, Pavel Curtis, Jeff Dalton, Olivier Danvy, Ken
thereby proving the usefulness of static scope rules and Dickey, Bruce Duba, Marc Feeley, Andy Freeman, Richard
block structure in a dynamically typed language. Scheme Gabriel, Yekta Gürsel, Ken Haase, Robert Hieb, Paul
was the first major dialect of Lisp to distinguish procedures Hudak, Morry Katz, Chris Lindblad, Mark Meyer, Jim
from lambda expressions and symbols, to use a single lex- Miller, Jim Philbin, John Ramsdell, Mike Shaff, Jonathan
ical environment for all variables, and to evaluate the op- Shapiro, Julie Sussman, Perry Wagle, Daniel Weise, Henry
erator position of a procedure call in the same way as an Wu, and Ozan Yigit. We thank Carol Fessenden, Daniel
operand position. By relying entirely on procedure calls Friedman, and Christopher Haynes for permission to use
to express iteration, Scheme emphasized the fact that tail- text from the Scheme 311 version 4 reference manual.
recursive procedure calls are essentially goto’s that pass We thank Texas Instruments, Inc. for permission to use
arguments. Scheme was the first widely used program- text from the TI Scheme Language Reference Manual [30].
ming language to embrace first class escape procedures, We gladly acknowledge the influence of manuals for MIT
from which all previously known sequential control struc- Scheme [17], T [22], Scheme 84 [11], Common Lisp [27],
tures can be synthesized. A subsequent version of Scheme and Algol 60 [18].
introduced the concept of exact and inexact numbers, an
We also thank Betty Dexter for the extreme effort she put
extension of Common Lisp’s generic arithmetic. More re-
into setting this report in TEX, and Donald Knuth for de-
cently, Scheme became the first programming language to
signing the program that caused her troubles.
support hygienic macros, which permit the syntax of a
block-structured language to be extended in a consistent The Artificial Intelligence Laboratory of the Massachusetts
and reliable manner. Institute of Technology, the Computer Science Department
of Indiana University, the Computer and Information Sci-
ences Department of the University of Oregon, and the
Background NEC Research Institute supported the preparation of this
The first description of Scheme was written in 1975 [28]. A report. Support for the MIT work was provided in part by
revised report [25] appeared in 1978, which described the the Advanced Research Projects Agency of the Department
evolution of the language as its MIT implementation was of Defense under Office of Naval Research contract N00014-
upgraded to support an innovative compiler [26]. Three 80-C-0505. Support for the Indiana University work was
distinct projects began in 1981 and 1982 to use variants provided by NSF grants NCS 83-04567 and NCS 83-03325.
of Scheme for courses at MIT, Yale, and Indiana Univer-
sity [21, 17, 10]. An introductory computer science text-
book using Scheme was published in 1984 [1].
As Scheme became more widespread, local dialects be-
gan to diverge until students and researchers occasion-
ally 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.
Their report [4] was published at MIT and Indiana Uni-
versity in the summer of 1985. Further revision took place
in the spring of 1986 [23], and in the spring of 1988 [6].
The present report reflects further revisions agreed upon
in a meeting at Xerox PARC in June 1992.
When speaking of an error situation, this report uses the indicates zero or more occurrences of a hthingi, and
phrase “an error is signalled” to indicate that implemen- hthing1 i hthing2 i . . .
tations must detect and report the error. If such wording indicates one or more occurrences of a hthingi.
does not appear in the discussion of an error, then imple-
mentations are not required to detect or report the error, If category is “procedure”, then the entry describes a pro-
though they are encouraged to do so. An error situation cedure, and the header line gives a template for a call to the
that implementations are not required to detect is usually procedure. Argument names in the template are italicized .
referred to simply as “an error.” Thus the header line
For example, it is an error for a procedure to be passed an (vector-ref vector k ) procedure
argument that the procedure is not explicitly specified to indicates that the built-in procedure vector-ref takes two
handle, even though such domain errors are seldom men- arguments, a vector vector and an exact non-negative in-
tioned in this report. Implementations may extend a pro- teger k (see below). The header lines
cedure’s domain of definition to include such arguments.
(make-vector k ) procedure
This report uses the phrase “may report a violation of an (make-vector k fill ) procedure
implementation restriction” to indicate circumstances un-
indicate that the make-vector procedure must be defined
der which an implementation is permitted to report that
to take either one or two arguments.
it is unable to continue execution of a correct program be-
cause of some restriction imposed by the implementation. It is an error for an operation to be presented with an ar-
Implementation restrictions are of course discouraged, but gument that it is not specified to handle. For succinctness,
implementations are encouraged to report violations of im- we follow the convention that if an argument name is also
plementation restrictions. the name of a type listed in section 3.2, then that argu-
ment must be of the named type. For example, the header
For example, an implementation may report a violation of
line for vector-ref given above dictates that the first ar-
an implementation restriction if it does not have enough
gument to vector-ref must be a vector. The following
storage to run a program.
naming conventions also imply type restrictions:
If the value of an expression is said to be “unspecified,”
then the expression must evaluate to some object without obj any object
signalling an error, but the value depends on the imple- list, list1 , . . . listj , . . . list (see section 6.3.2)
mentation; this report explicitly does not say what value z, z1 , . . . zj , . . . complex number
should be returned. x, x1 , . . . xj , . . . real number
y, y1 , . . . yj , . . . real number
q, q1 , . . . qj , . . . rational number
1.3.3. Entry format n, n1 , . . . nj , . . . integer
k, k1 , . . . kj , . . . exact non-negative integer
Chapters 4 and 6 are organized into entries. Each entry de-
scribes one language feature or a group of related features,
where a feature is either a syntactic construct or a built-in 1.3.4. Evaluation examples
procedure. An entry begins with one or more header lines
of the form The symbol “=⇒” used in program examples should be
read “evaluates to.” For example,
template category
(* 5 8) =⇒ 40
for required, primitive features, or
means that the expression (* 5 8) evaluates to the ob-
template qualifier category
ject 40. Or, more precisely: the expression given by the
where qualifier is either “library” or “optional” as defined sequence of characters “(* 5 8)” evaluates, in the initial
in section 1.3.1. environment, to an object that may be represented exter-
If category is “syntax”, the entry describes an expression nally by the sequence of characters “40”. See section 3.3
type, and the template gives the syntax of the expression for a discussion of external representations of objects.
type. Components of expressions are designated by syn-
tactic variables, which are written using angle brackets, 1.3.5. Naming conventions
for example, hexpressioni, hvariablei. Syntactic variables
should be understood to denote segments of program text; By convention, the names of procedures that always return
for example, hexpressioni stands for any string of charac- a boolean value usually end in “?”. Such procedures are
ters which is a syntactically valid expression. The notation called predicates.
2. Lexical conventions 5
By convention, the names of procedures that store values 2.2. Whitespace and comments
into previously allocated locations (see section 3.4) usually
end in “!”. Such procedures are called mutation proce- Whitespace characters are spaces and newlines. (Imple-
dures. By convention, the value returned by a mutation mentations typically provide additional whitespace char-
procedure is unspecified. acters such as tab or page break.) Whitespace is used for
By convention, “->” appears within the names of proce- improved readability and as necessary to separate tokens
dures that take an object of one type and return an anal- from each other, a token being an indivisible lexical unit
ogous object of another type. For example, list->vector such as an identifier or number, but is otherwise insignifi-
takes a list and returns a vector whose elements are the cant. Whitespace may occur between any two tokens, but
same as those of the list. not within a token. Whitespace may also occur inside a
string, where it is significant.
A semicolon (;) indicates the start of a comment. The
2. Lexical conventions comment continues to the end of the line on which the
This section gives an informal account of some of the lexical semicolon appears. Comments are invisible to Scheme, but
conventions used in writing Scheme programs. For a formal the end of the line is visible as whitespace. This prevents a
syntax of Scheme, see section 7.1. comment from appearing in the middle of an identifier or
number.
Upper and lower case forms of a letter are never distin-
guished except within character and string constants. For ;;; The FACT procedure computes the factorial
example, Foo is the same identifier as FOO, and #x1AB is ;;; of a non-negative integer.
the same number as #X1ab. (define fact
(lambda (n)
(if (= n 0)
1 ;Base case: return 1
2.1. Identifiers (* n (fact (- n 1))))))
\ Backslash is used in the syntax for character constants The region is determined by the particular binding con-
(section 6.3.4) and as an escape character within struct that establishes the binding; if the binding is estab-
string constants (section 6.3.5). lished by a lambda expression, for example, then its region
is the entire lambda expression. Every mention of an iden-
[ ] { } | Left and right square brackets and curly braces tifier refers to the binding of the identifier that established
and vertical bar are reserved for possible future exten- the innermost of the regions containing the use. If there is
sions to the language. no binding of the identifier whose region contains the use,
# Sharp sign is used for a variety of purposes depending then the use refers to the binding for the variable in the
on the character that immediately follows it: top level environment, if any (chapters 4 and 6); if there
is no binding for the identifier, it is said to be unbound.
#t #f These are the boolean constants (section 6.3.1).
3.1. Variables, syntactic keywords, and re- These predicates define the types boolean, pair, symbol,
gions number, char (or character), string, vector, port, and pro-
cedure. The empty list is a special object of its own type;
An identifier may name a type of syntax, or it may name it satisfies none of the above predicates.
a location where a value can be stored. An identifier that Although there is a separate boolean type, any Scheme
names a type of syntax is called a syntactic keyword and is value can be used as a boolean value for the purpose of a
said to be bound to that syntax. An identifier that names conditional test. As explained in section 6.3.1, all values
a location is called a variable and is said to be bound to count as true in such a test except for #f. This report uses
that location. The set of all visible bindings in effect at the word “true” to refer to any Scheme value except #f,
some point in a program is known as the environment in and the word “false” to refer to #f.
effect at that point. The value stored in the location to
which a variable is bound is called the variable’s value.
By abuse of terminology, the variable is sometimes said 3.3. External representations
to name the value or to be bound to the value. This is
not quite accurate, but confusion rarely results from this
An important concept in Scheme (and Lisp) is that of the
practice.
external representation of an object as a sequence of char-
Certain expression types are used to create new kinds of acters. For example, an external representation of the inte-
syntax and bind syntactic keywords to those new syntaxes, ger 28 is the sequence of characters “28”, and an external
while other expression types create new locations and bind representation of a list consisting of the integers 8 and 13
variables to those locations. These expression types are is the sequence of characters “(8 13)”.
called binding constructs. Those that bind syntactic key-
The external representation of an object is not neces-
words are listed in section 4.3. The most fundamental of
sarily unique. The integer 28 also has representations
the variable binding constructs is the lambda expression,
“#e28.000” and “#x1c”, and the list in the previous para-
because all other variable binding constructs can be ex-
graph also has the representations “( 08 13 )” and “(8
plained in terms of lambda expressions. The other variable
. (13 . ()))” (see section 6.3.2).
binding constructs are let, let*, letrec, and do expres-
sions (see sections 4.1.4, 4.2.2, and 4.2.4). Many objects have standard external representations, but
some, such as procedures, do not have standard represen-
Like Algol and Pascal, and unlike most other dialects of
tations (although particular implementations may define
Lisp except for Common Lisp, Scheme is a statically scoped
representations for them).
language with block structure. To each place where an
identifier is bound in a program there corresponds a region An external representation may be written in a program to
of the program text within which the binding is visible. obtain the corresponding object (see quote, section 4.1.2).
3. Basic concepts 7
External representations can also be used for input and created by the other procedures listed in this report are
output. The procedure read (section 6.6.2) parses ex- mutable. It is an error to attempt to store a new value
ternal representations, and the procedure write (sec- into a location that is denoted by an immutable object.
tion 6.6.3) generates them. Together, they provide an
elegant and powerful input/output facility.
3.5. Proper tail recursion
Note that the sequence of characters “(+ 2 6)” is not an
external representation of the integer 8, even though it is an
Implementations of Scheme are required to be properly tail-
expression evaluating to the integer 8; rather, it is an exter-
recursive. Procedure calls that occur in certain syntactic
nal representation of a three-element list, the elements of
contexts defined below are ‘tail calls’. A Scheme imple-
which are the symbol + and the integers 2 and 6. Scheme’s
mentation is properly tail-recursive if it supports an un-
syntax has the property that any sequence of characters
bounded number of active tail calls. A call is active if
that is an expression is also the external representation of
the called procedure may still return. Note that this in-
some object. This can lead to confusion, since it may not
cludes calls that may be returned from either by the cur-
be obvious out of context whether a given sequence of char-
rent continuation or by continuations captured earlier by
acters is intended to denote data or program, but it is also
call-with-current-continuation that are later invoked.
a source of power, since it facilitates writing programs such
In the absence of captured continuations, calls could return
as interpreters and compilers that treat programs as data
at most once and the active calls would be those that had
(or vice versa).
not yet returned. A formal definition of proper tail recur-
The syntax of external representations of various kinds of sion can be found in [8].
objects accompanies the description of the primitives for Rationale:
manipulating the objects in the appropriate sections of
chapter 6. Intuitively, no space is needed for an active tail call because the
continuation that is used in the tail call has the same semantics
as the continuation passed to the procedure containing the call.
Although an improper implementation might use a new con-
3.4. Storage model tinuation in the call, a return to this new continuation would
be followed immediately by a return to the continuation passed
Variables and objects such as pairs, vectors, and strings to the procedure. A properly tail-recursive implementation re-
implicitly denote locations or sequences of locations. A turns to that continuation directly.
string, for example, denotes as many locations as there Proper tail recursion was one of the central ideas in Steele and
are characters in the string. (These locations need not Sussman’s original version of Scheme. Their first Scheme in-
correspond to a full machine word.) A new value may be terpreter implemented both functions and actors. Control flow
stored into one of these locations using the string-set! was expressed using actors, which differed from functions in
procedure, but the string continues to denote the same that they passed their results on to another actor instead of
locations as before. returning to a caller. In the terminology of this section, each
actor finished with a tail call to another actor.
An object fetched from a location, by a variable reference or
Steele and Sussman later observed that in their interpreter the
by a procedure such as car, vector-ref, or string-ref,
code for dealing with actors was identical to that for functions
is equivalent in the sense of eqv? (section 6.1) to the object
and thus there was no need to include both in the language.
last stored in the location before the fetch.
A tail call is a procedure call that occurs in a tail con-
Every location is marked to show whether it is in use. No text. Tail contexts are defined inductively. Note that a tail
variable or object ever refers to a location that is not in use. context is always determined with respect to a particular
Whenever this report speaks of storage being allocated for lambda expression.
a variable or object, what is meant is that an appropriate
number of locations are chosen from the set of locations
• The last expression within the body of a lambda ex-
that are not in use, and the chosen locations are marked
pression, shown as htail expressioni below, occurs in a
to indicate that they are now in use before the variable or
tail context.
object is made to denote them.
In many systems it is desirable for constants (i.e. the val- (lambda hformalsi
ues of literal expressions) to reside in read-only-memory. hdefinitioni* hexpressioni* htail expressioni)
To express this, it is convenient to imagine that every
object that denotes locations is associated with a flag
telling whether that object is mutable or immutable. In • If one of the following expressions is in a tail context,
such systems literal constants and the strings returned by then the subexpressions shown as htail expressioni are
symbol->string are immutable objects, while all objects in a tail context. These were derived from rules in
8 Revised5 Scheme
the grammar given in chapter 7 by replacing some oc- In the following example the only tail call is the call to f.
currences of hexpressioni with htail expressioni. Only None of the calls to g or h are tail calls. The reference to
those rules that contain tail contexts are shown here. x is in a tail context, but it is not a call and thus is not a
tail call.
(lambda ()
(if hexpressioni htail expressioni htail expressioni)
(if (g)
(if hexpressioni htail expressioni)
(let ((x (h)))
x)
(cond hcond clausei+ ) (and (g) (f))))
(cond hcond clausei* (else htail sequencei))
Note: Implementations are allowed, but not required, to recog-
(case hexpressioni
nize that some non-tail calls, such as the call to h above, can be
hcase clausei+ )
evaluated as though they were tail calls. In the example above,
(case hexpressioni
the let expression could be compiled as a tail call to h. (The
hcase clausei*
possibility of h returning an unexpected number of values can
(else htail sequencei))
be ignored, because in that case the effect of the let is explicitly
unspecified and implementation-dependent.)
(and hexpressioni* htail expressioni)
(or hexpressioni* htail expressioni)
4. Expressions
(let (hbinding speci*) htail bodyi)
(let hvariablei (hbinding speci*) htail bodyi) Expression types are categorized as primitive or derived.
(let* (hbinding speci*) htail bodyi) Primitive expression types include variables and procedure
(letrec (hbinding speci*) htail bodyi) calls. Derived expression types are not semantically prim-
itive, but can instead be defined as macros. With the ex-
(let-syntax (hsyntax speci*) htail bodyi) ception of quasiquote, whose macro definition is complex,
(letrec-syntax (hsyntax speci*) htail bodyi) the derived expressions are classified as library features.
Suitable definitions are given in section 7.3.
(begin htail sequencei)
4.1. Primitive expression types
(do (hiteration speci*)
(htesti htail sequencei)
4.1.1. Variable references
hexpressioni*)
(quote hdatumi) may be abbreviated as ’hdatumi. The Note: In many dialects of Lisp, the empty combination, (),
two notations are equivalent in all respects. is a legitimate expression. In Scheme, combinations must have
at least one subexpression, so () is not a syntactically valid
’a =⇒ a
expression.
’#(a b c) =⇒ #(a b c)
’() =⇒ ()
’(+ 1 2) =⇒ (+ 1 2) 4.1.4. Procedures
’(quote a) =⇒ (quote a)
’’a =⇒ (quote a) (lambda hformalsi hbodyi) syntax
Numerical constants, string constants, character constants, Syntax: hFormalsi should be a formal arguments list as
and boolean constants evaluate “to themselves”; they need described below, and hbodyi should be a sequence of one
not be quoted. or more expressions.
Semantics: A lambda expression evaluates to a procedure.
’"abc" =⇒ "abc"
The environment in effect when the lambda expression was
"abc" =⇒ "abc"
’145932 =⇒ 145932 evaluated is remembered as part of the procedure. When
145932 =⇒ 145932 the procedure is later called with some actual arguments,
’#t =⇒ #t the environment in which the lambda expression was evalu-
#t =⇒ #t ated will be extended by binding the variables in the formal
argument list to fresh locations, the corresponding actual
As noted in section 3.4, it is an error to alter a constant argument values will be stored in those locations, and the
(i.e. the value of a literal expression) using a mutation pro- expressions in the body of the lambda expression will be
cedure like set-car! or string-set!. evaluated sequentially in the extended environment. The
result(s) of the last expression in the body will be returned
4.1.3. Procedure calls as the result(s) of the procedure call.
(lambda (x) (+ x x)) =⇒ a procedure
(hoperatori hoperand1 i . . . ) syntax ((lambda (x) (+ x x)) 4) =⇒ 8
the hclausei is(are) returned as the result(s) of the case ex- initial values are being computed, thus allowing mutually
pression. If the result of evaluating hkeyi is different from recursive definitions.
every hdatumi, then if there is an else clause its expres-
sions are evaluated and the result(s) of the last is(are) the
(let hbindingsi hbodyi) library syntax
result(s) of the case expression; otherwise the result of the
case expression is unspecified. Syntax: hBindingsi should have the form
((hvariable1 i hinit1 i) . . . ),
(case (* 2 3)
((2 3 5 7) ’prime) where each hiniti is an expression, and hbodyi should be a
((1 4 6 8 9) ’composite)) =⇒ composite sequence of one or more expressions. It is an error for a
(case (car ’(c d)) hvariablei to appear more than once in the list of variables
((a) ’a) being bound.
((b) ’b)) =⇒ unspecified
(case (car ’(c d)) Semantics: The hinitis are evaluated in the current envi-
((a e i o u) ’vowel) ronment (in some unspecified order), the hvariableis are
((w y) ’semivowel) bound to fresh locations holding the results, the hbodyi is
(else ’consonant)) =⇒ consonant evaluated in the extended environment, and the value(s) of
the last expression of hbodyi is(are) returned. Each bind-
ing of a hvariablei has hbodyi as its region.
(and htest1 i . . . ) library syntax
(let ((x 2) (y 3))
The htesti expressions are evaluated from left to right, and (* x y)) =⇒ 6
the value of the first expression that evaluates to a false
value (see section 6.3.1) is returned. Any remaining ex- (let ((x 2) (y 3))
pressions are not evaluated. If all the expressions evaluate (let ((x 7)
to true values, the value of the last expression is returned. (z (+ x y)))
If there are no expressions then #t is returned. (* z x))) =⇒ 35
resulting environment (in some unspecified order), each termination condition is met, the loop exits after evaluating
hvariablei is assigned to the result of the corresponding the hexpressionis.
hiniti, the hbodyi is evaluated in the resulting environment, Do expressions are evaluated as follows: The hiniti ex-
and the value(s) of the last expression in hbodyi is(are) re- pressions are evaluated (in some unspecified order), the
turned. Each binding of a hvariablei has the entire letrec hvariableis are bound to fresh locations, the results of
expression as its region, making it possible to define mutu- the hiniti expressions are stored in the bindings of the
ally recursive procedures. hvariableis, and then the iteration phase begins.
(letrec ((even? Each iteration begins by evaluating htesti; if the result is
(lambda (n) false (see section 6.3.1), then the hcommandi expressions
(if (zero? n)
are evaluated in order for effect, the hstepi expressions
#t
are evaluated in some unspecified order, the hvariableis
(odd? (- n 1)))))
(odd? are bound to fresh locations, the results of the hstepis are
(lambda (n) stored in the bindings of the hvariableis, and the next iter-
(if (zero? n) ation begins.
#f If htesti evaluates to a true value, then the hexpressionis
(even? (- n 1)))))) are evaluated from left to right and the value(s) of the
(even? 88))
last hexpressioni is(are) returned. If no hexpressionis are
=⇒ #t
present, then the value of the do expression is unspecified.
One restriction on letrec is very important: it must be The region of the binding of a hvariablei consists of the
possible to evaluate each hiniti without assigning or refer- entire do expression except for the hinitis. It is an error
ring to the value of any hvariablei. If this restriction is for a hvariablei to appear more than once in the list of do
violated, then it is an error. The restriction is necessary variables.
because Scheme passes arguments by value rather than by
name. In the most common uses of letrec, all the hinitis A hstepi may be omitted, in which case the effect is the
are lambda expressions and the restriction is satisfied au- same as if (hvariablei hiniti hvariablei) had been written
tomatically. instead of (hvariablei hiniti).
(do ((vec (make-vector 5))
(i 0 (+ i 1)))
4.2.3. Sequencing ((= i 5) vec)
(vector-set! vec i i)) =⇒ #(0 1 2 3 4)
(begin hexpression1 i hexpression2 i . . . ) library syntax
(let ((x ’(1 3 5 7 9)))
The hexpressionis are evaluated sequentially from left to (do ((x x (cdr x))
right, and the value(s) of the last hexpressioni is(are) re- (sum 0 (+ sum (car x))))
turned. This expression type is used to sequence side ef- ((null? x) sum))) =⇒ 25
fects such as input and output.
(define x 0) (let hvariablei hbindingsi hbodyi) library syntax
(begin (set! x 5) “Named let” is a variant on the syntax of let which pro-
(+ x 1)) =⇒ 6 vides a more general looping construct than do and may
also be used to express recursions. It has the same syn-
(begin (display "4 plus 1 equals ") tax and semantics as ordinary let except that hvariablei
(display (+ 4 1))) =⇒ unspecified is bound within hbodyi to a procedure whose formal argu-
and prints 4 plus 1 equals 5 ments are the bound variables and whose body is hbodyi.
Thus the execution of hbodyi may be repeated by invoking
the procedure named by hvariablei.
4.2.4. Iteration
(let loop ((numbers ’(3 -2 1 6 -5))
(do ((hvariable1 i hinit1 i hstep1 i) library syntax (nonneg ’())
...) (neg ’()))
(htesti hexpressioni . . . ) (cond ((null? numbers) (list nonneg neg))
hcommandi . . . ) ((>= (car numbers) 0)
(loop (cdr numbers)
Do is an iteration construct. It specifies a set of variables (cons (car numbers) nonneg)
to be bound, how they are to be initialized at the start, neg))
and how they are to be updated on each iteration. When a ((< (car numbers) 0)
4. Expressions 13
Quasiquote forms may be nested. Substitutions are made The syntactic keyword of a macro may shadow variable
only for unquoted components appearing at the same nest- bindings, and local variable bindings may shadow keyword
ing level as the outermost backquote. The nesting level in- bindings. All macros defined using the pattern language
creases by one inside each successive quasiquotation, and are “hygienic” and “referentially transparent” and thus
decreases by one inside each unquotation. preserve Scheme’s lexical scoping [14, 15, 2, 7, 9]:
14 Revised5 Scheme
• If a macro transformer inserts a binding for an identi- of the letrec-syntax expression with macros whose key-
fier (variable or keyword), the identifier will in effect be words are the hkeywordis, bound to the specified trans-
renamed throughout its scope to avoid conflicts with formers. Each binding of a hkeywordi has the hbindingsi
other identifiers. Note that a define at top level may as well as the hbodyi within its region, so the transformers
or may not introduce a binding; see section 5.2. can transcribe expressions into uses of the macros intro-
duced by the letrec-syntax expression.
• If a macro transformer inserts a free reference to an
identifier, the reference refers to the binding that was (letrec-syntax
((my-or (syntax-rules ()
visible where the transformer was specified, regardless
((my-or) #f)
of any local bindings that may surround the use of the
((my-or e) e)
macro. ((my-or e1 e2 ...)
(let ((temp e1))
(if temp
4.3.1. Binding constructs for syntactic keywords temp
(my-or e2 ...)))))))
Let-syntax and letrec-syntax are analogous to let and (let ((x #f)
letrec, but they bind syntactic keywords to macro trans- (y 7)
formers instead of binding variables to locations that con- (temp 8)
tain values. Syntactic keywords may also be bound at top (let odd?)
level; see section 5.3. (if even?))
(my-or x
(let temp)
(let-syntax hbindingsi hbodyi) syntax (if y)
Syntax: hBindingsi should have the form y))) =⇒ 7
rewrite rules. A use of a macro whose keyword is associated • P is a vector of the form #(P1 . . . Pn ) and F is a
with a transformer specified by syntax-rules is matched vector of n forms that match P1 through Pn ; or
against the patterns contained in the hsyntax ruleis, be-
ginning with the leftmost hsyntax rulei. When a match is • P is of the form #(P1 . . . Pn Pn+1 hellipsisi) where
found, the macro use is transcribed hygienically according hellipsisi is the identifier ... and F is a vector of n or
to the template. more forms the first n of which match P1 through Pn ,
respectively, and each remaining element of F matches
An identifier that appears in the pattern of a hsyntax rulei Pn+1 ; or
is a pattern variable, unless it is the keyword that begins
the pattern, is listed in hliteralsi, or is the identifier “...”. • P is a datum and F is equal to P in the sense of the
Pattern variables match arbitrary input elements and are equal? procedure.
used to refer to elements of the input in the template. It
is an error for the same pattern variable to appear more It is an error to use a macro keyword, within the scope of
than once in a hpatterni. its binding, in an expression that does not match any of
The keyword at the beginning of the pattern in a the patterns.
hsyntax rulei is not involved in the matching and is not When a macro use is transcribed according to the template
considered a pattern variable or literal identifier. of the matching hsyntax rulei, pattern variables that occur
Rationale: The scope of the keyword is determined by the in the template are replaced by the subforms they match
expression or syntax definition that binds it to the associated in the input. Pattern variables that occur in subpatterns
macro transformer. If the keyword were a pattern variable or followed by one or more instances of the identifier ... are
literal identifier, then the template that follows the pattern allowed only in subtemplates that are followed by as many
would be within its scope regardless of whether the keyword instances of .... They are replaced in the output by all
were bound by let-syntax or by letrec-syntax. of the subforms they match in the input, distributed as
indicated. It is an error if the output cannot be built up
Identifiers that appear in hliteralsi are interpreted as literal as specified.
identifiers to be matched against corresponding subforms
of the input. A subform in the input matches a literal Identifiers that appear in the template but are not pattern
identifier if and only if it is an identifier and either both its variables or the identifier ... are inserted into the output
occurrence in the macro expression and its occurrence in as literal identifiers. If a literal identifier is inserted as a
the macro definition have the same lexical binding, or the free identifier then it refers to the binding of that identifier
two identifiers are equal and both have no lexical binding. within whose scope the instance of syntax-rules appears.
If a literal identifier is inserted as a bound identifier then
A subpattern followed by ... can match zero or more el- it is in effect renamed to prevent inadvertent captures of
ements of the input. It is an error for ... to appear in free identifiers.
hliteralsi. Within a pattern the identifier ... must follow
the last element of a nonempty sequence of subpatterns. As an example, if let and cond are defined as in section 7.3
then they are hygienic (as required) and the following is not
More formally, an input form F matches a pattern P if and an error.
only if:
(let ((=> #f))
(cond (#t => ’ok))) =⇒ ok
• P is a non-literal identifier; or
The macro transformer for cond recognizes => as a local
• P is a literal identifier and F is an identifier with the
variable, and hence an expression, and not as the top-level
same binding; or
identifier =>, which the macro transformer treats as a syn-
• P is a list (P1 . . . Pn ) and F is a list of n forms that tactic keyword. Thus the example expands into
match P1 through Pn , respectively; or (let ((=> #f))
(if #t (begin => ’ok)))
• P is an improper list (P1 P2 . . . Pn . Pn+1 ) and
F is a list or improper list of n or more forms that instead of
match P1 through Pn , respectively, and whose nth
(let ((=> #f))
“cdr” matches Pn+1 ; or
(let ((temp #t))
• P is of the form (P1 . . . Pn Pn+1 hellipsisi) where (if temp (’ok temp))))
hellipsisi is the identifier ... and F is a proper list which would result in an invalid procedure call.
of at least n forms, the first n of which match P1
through Pn , respectively, and each remaining element
of F matches Pn+1 ; or
16 Revised5 Scheme
5.3. Syntax definitions top-level binding that has not been introduced by a defini-
tion has an unspecified effect on the behavior of the built-in
Syntax definitions are valid only at the top level of a procedures.
hprogrami. They have the following form:
(define-syntax hkeywordi htransformer speci) 6.1. Equivalence predicates
hKeywordi is an identifier, and the htransformer speci
should be an instance of syntax-rules. The top-level syn- A predicate is a procedure that always returns a boolean
tactic environment is extended by binding the hkeywordi value (#t or #f). An equivalence predicate is the compu-
to the specified transformer. tational analogue of a mathematical equivalence relation
(it is symmetric, reflexive, and transitive). Of the equiva-
There is no define-syntax analogue of internal defini- lence predicates described in this section, eq? is the finest
tions. or most discriminating, and equal? is the coarsest. Eqv?
Although macros may expand into definitions and syntax is slightly less discriminating than eq?.
definitions in any context that permits them, it is an error
for a definition or syntax definition to shadow a syntactic (eqv? obj1 obj2 ) procedure
keyword whose meaning is needed to determine whether
some form in the group of forms that contains the shad- The eqv? procedure defines a useful equivalence relation
owing definition is in fact a definition, or, for internal def- on objects. Briefly, it returns #t if obj1 and obj2 should
initions, is needed to determine the boundary between the normally be regarded as the same object. This relation is
group and the expressions that follow the group. For ex- left slightly open to interpretation, but the following par-
ample, the following are errors: tial specification of eqv? holds for all implementations of
Scheme.
(define define 3)
The eqv? procedure returns #t if:
(begin (define begin list))
• obj1 and obj2 are both #t or both #f.
(let-syntax
((foo (syntax-rules () • obj1 and obj2 are both symbols and
((foo (proc args ...) body ...)
(define proc (string=? (symbol->string obj1)
(lambda (args ...) (symbol->string obj2))
body ...)))))) =⇒ #t
(let ((x 3))
(foo (plus x y) (+ x y)) Note: This assumes that neither obj1 nor obj2 is an “un-
(define foo x) interned symbol” as alluded to in section 6.3.3. This re-
(plus foo x))) port does not presume to specify the behavior of eqv? on
implementation-dependent extensions.
• one of obj1 and obj2 is #t but the other is #f. (define gen-counter
(lambda ()
• obj1 and obj2 are symbols but (let ((n 0))
(lambda () (set! n (+ n 1)) n))))
(let ((g (gen-counter)))
(string=? (symbol->string obj1 ) (eqv? g g)) =⇒ #t
(symbol->string obj2 )) (eqv? (gen-counter) (gen-counter))
=⇒ #f =⇒ #f
(define gen-loser
• one of obj1 and obj2 is an exact number but the other (lambda ()
(let ((n 0))
is an inexact number.
(lambda () (set! n (+ n 1)) 27))))
(let ((g (gen-loser)))
• obj1 and obj2 are numbers for which the = procedure (eqv? g g)) =⇒ #t
returns #f. (eqv? (gen-loser) (gen-loser))
=⇒ unspecified
• obj1 and obj2 are characters for which the char=? pro-
cedure returns #f. (letrec ((f (lambda () (if (eqv? f g) ’both ’f)))
(g (lambda () (if (eqv? f g) ’both ’g))))
• one of obj1 and obj2 is the empty list but the other is (eqv? f g))
not. =⇒ unspecified
• obj1 and obj2 are pairs, vectors, or strings that denote (letrec ((f (lambda () (if (eqv? f g) ’f ’both)))
distinct locations. (g (lambda () (if (eqv? f g) ’g ’both))))
(eqv? f g))
• obj1 and obj2 are procedures that would behave differ- =⇒ #f
ently (return different value(s) or have different side Since it is an error to modify constant objects (those re-
effects) for some arguments. turned by literal expressions), implementations are per-
mitted, though not required, to share structure between
(eqv? ’a ’a) =⇒ #t
constants where appropriate. Thus the value of eqv? on
(eqv? ’a ’b) =⇒ #f
constants is sometimes implementation-dependent.
(eqv? 2 2) =⇒ #t
(eqv? ’() ’()) =⇒ #t (eqv? ’(a) ’(a)) =⇒ unspecified
(eqv? 100000000 100000000) =⇒ #t (eqv? "a" "a") =⇒ unspecified
(eqv? (cons 1 2) (cons 1 2))=⇒ #f (eqv? ’(b) (cdr ’(a b))) =⇒ unspecified
(eqv? (lambda () 1) (let ((x ’(a)))
(lambda () 2)) =⇒ #f (eqv? x x)) =⇒ #t
(eqv? #f ’nil) =⇒ #f
(let ((p (lambda (x) x))) Rationale: The above definition of eqv? allows implementa-
(eqv? p p)) =⇒ #t tions latitude in their treatment of procedures and literals: im-
plementations are free either to detect or to fail to detect that
The following examples illustrate cases in which the above two procedures or two literals are equivalent to each other, and
rules do not fully specify the behavior of eqv?. All that can decide whether or not to merge representations of equivalent
can be said about such cases is that the value returned by objects by using the same pointer or bit pattern to represent
eqv? must be a boolean. both.
is inexact if it was written as an inexact constant, if it must return an exact integer, and it is an error to use
was derived using inexact ingredients, or if it was derived anything but an exact integer as an index. Furthermore
using inexact operations. Thus inexactness is a contagious any integer constant within the index range, if expressed
property of a number. by an exact integer syntax, will indeed be read as an exact
If two implementations produce exact results for a com- integer, regardless of any implementation restrictions that
putation that did not involve inexact intermediate results, may apply outside this range. Finally, the procedures listed
the two ultimate results will be mathematically equivalent. below will always return an exact integer result provided all
This is generally not true of computations involving inex- their arguments are exact integers and the mathematically
act numbers since approximate methods such as floating expected result is representable as an exact integer within
point arithmetic may be used, but it is the duty of each the implementation:
implementation to make the result as close as practical to + - *
the mathematically ideal result. quotient remainder modulo
Rational operations such as + should always produce ex- max min abs
numerator denominator gcd
act results when given exact arguments. If the operation
lcm floor ceiling
is unable to produce an exact result, then it may either
truncate round rationalize
report the violation of an implementation restriction or it expt
may silently coerce its result to an inexact value. See sec-
tion 6.2.3. Implementations are encouraged, but not required, to sup-
With the exception of inexact->exact, the operations de- port exact integers and exact rationals of practically unlim-
scribed in this section must generally return inexact results ited size and precision, and to implement the above proce-
when given any inexact arguments. An operation may, dures and the / procedure in such a way that they always
however, return an exact result if it can prove that the return exact results when given exact arguments. If one of
value of the result is unaffected by the inexactness of its these procedures is unable to deliver an exact result when
arguments. For example, multiplication of any number by given exact arguments, then it may either report a vio-
an exact zero may produce an exact zero result, even if the lation of an implementation restriction or it may silently
other argument is inexact. coerce its result to an inexact number. Such a coercion
may cause an error later.
6.2.3. Implementation restrictions An implementation may use floating point and other ap-
proximate representation strategies for inexact numbers.
Implementations of Scheme are not required to implement This report recommends, but does not require, that the
the whole tower of subtypes given in section 6.2.1, but IEEE 32-bit and 64-bit floating point standards be followed
they must implement a coherent subset consistent with by implementations that use flonum representations, and
both the purposes of the implementation and the spirit that implementations using other representations should
of the Scheme language. For example, an implementation match or exceed the precision achievable using these float-
in which all numbers are real may still be quite useful. ing point standards [12].
Implementations may also support only a limited range of In particular, implementations that use flonum represen-
numbers of any type, subject to the requirements of this tations must follow these rules: A flonum result must be
section. The supported range for exact numbers of any represented with at least as much precision as is used to
type may be different from the supported range for inex- express any of the inexact arguments to that operation. It
act numbers of that type. For example, an implementation is desirable (but not required) for potentially inexact oper-
that uses flonums to represent all its inexact real numbers ations such as sqrt, when applied to exact arguments, to
may support a practically unbounded range of exact inte- produce exact answers whenever possible (for example the
gers and rationals while limiting the range of inexact reals square root of an exact 4 ought to be an exact 2). If, how-
(and therefore the range of inexact integers and rationals) ever, an exact number is operated upon so as to produce an
to the dynamic range of the flonum format. Furthermore inexact result (as by sqrt), and if the result is represented
the gaps between the representable inexact integers and ra- as a flonum, then the most precise flonum format available
tionals are likely to be very large in such an implementation must be used; but if the result is represented in some other
as the limits of this range are approached. way then the representation must have at least as much
precision as the most precise flonum format available.
An implementation of Scheme must support exact integers
throughout the range of numbers that may be used for Although Scheme allows a variety of written notations for
indexes of lists, vectors, and strings or that may result numbers, any particular implementation may support only
from computing the length of a list, vector, or string. The some of them. For example, an implementation in which
length, vector-length, and string-length procedures all numbers are real need not support the rectangular and
6. Standard procedures 21
polar notations for complex numbers. If an implementa- be represented without loss of accuracy; the inexact con-
tion encounters an exact numerical constant that it cannot stants were chosen so that this is likely to be true in imple-
represent as an exact number, then it may either report a mentations that use flonums to represent inexact numbers.
violation of an implementation restriction or it may silently
represent the constant by an inexact number. (number? obj ) procedure
(complex? obj ) procedure
6.2.4. Syntax of numerical constants (real? obj ) procedure
(rational? obj ) procedure
The syntax of the written representations for numbers is (integer? obj ) procedure
described formally in section 7.1.1. Note that case is not These numerical type predicates can be applied to any kind
significant in numerical constants. of argument, including non-numbers. They return #t if the
A number may be written in binary, octal, decimal, or hex- object is of the named type, and otherwise they return #f.
adecimal by the use of a radix prefix. The radix prefixes In general, if a type predicate is true of a number then
are #b (binary), #o (octal), #d (decimal), and #x (hexadec- all higher type predicates are also true of that number.
imal). With no radix prefix, a number is assumed to be Consequently, if a type predicate is false of a number, then
expressed in decimal. all lower type predicates are also false of that number.
A numerical constant may be specified to be either exact or If z is an inexact complex number, then (real? z) is true
inexact by a prefix. The prefixes are #e for exact, and #i if and only if (zero? (imag-part z)) is true. If x is an
for inexact. An exactness prefix may appear before or after inexact real number, then (integer? x) is true if and only
any radix prefix that is used. If the written representation if (= x (round x)).
of a number has no exactness prefix, the constant may be (complex? 3+4i) =⇒ #t
either inexact or exact. It is inexact if it contains a decimal (complex? 3) =⇒ #t
point, an exponent, or a “#” character in the place of a (real? 3) =⇒ #t
digit, otherwise it is exact. (real? -2.5+0.0i) =⇒ #t
(real? #e1e10) =⇒ #t
In systems with inexact numbers of varying precisions it (rational? 6/10) =⇒ #t
may be useful to specify the precision of a constant. For (rational? 6/3) =⇒ #t
this purpose, numerical constants may be written with an (integer? 3+0i) =⇒ #t
exponent marker that indicates the desired precision of the (integer? 3.0) =⇒ #t
inexact representation. The letters s, f, d, and l specify (integer? 8/4) =⇒ #t
the use of short, single, double, and long precision, respec- Note: The behavior of these type predicates on inexact num-
tively. (When fewer than four internal inexact represen- bers is unreliable, since any inaccuracy may affect the result.
tations exist, the four size specifications are mapped onto
those available. For example, an implementation with two Note: In many implementations the rational? procedure will
internal representations may map short and single together be the same as real?, and the complex? procedure will be the
and long and double together.) In addition, the exponent same as number?, but unusual implementations may be able
marker e specifies the default precision for the implemen- to represent some irrational numbers exactly or may extend the
tation. The default precision has at least as much precision number system to support some kind of non-complex numbers.
as double, but implementations may wish to allow this de-
fault to be set by the user. (exact? z) procedure
(inexact? z) procedure
3.14159265358979F0
Round to single — 3.141593 These numerical predicates provide tests for the exactness
0.6L0 of a quantity. For any Scheme number, precisely one of
Extend to long — .600000000000000 these predicates is true.
(= z1 z2 z3 . . . ) procedure
6.2.5. Numerical operations
(< x1 x2 x3 . . . ) procedure
The reader is referred to section 1.3.3 for a summary of (> x1 x2 x3 . . . ) procedure
the naming conventions used to specify restrictions on the (<= x1 x2 x3 . . . ) procedure
types of arguments to numerical routines. The examples (>= x1 x2 x3 . . . ) procedure
used in this section assume that any numerical constant These procedures return #t if their arguments are (respec-
written using an exact notation is indeed represented as tively): equal, monotonically increasing, monotonically de-
an exact number. Some examples also assume that certain creasing, monotonically nondecreasing, or monotonically
numerical constants written using an inexact notation can nonincreasing.
22 Revised5 Scheme
With two or more arguments, these procedures return the (modulo -13 -4) =⇒ -1
difference or quotient of their arguments, associating to the (remainder -13 -4) =⇒ -1
left. With one argument, however, they return the additive
or multiplicative inverse of their argument. (remainder -13 -4.0) =⇒ -1.0 ; inexact
6. Standard procedures 23
then string->number is permitted to return #f whenever string (boolean? obj ) library procedure
uses the polar or rectangular notations for complex numbers. If
Boolean? returns #t if obj is either #t or #f and returns
all numbers are integers, then string->number may return #f
#f otherwise.
whenever the fractional notation is used. If all numbers are
exact, then string->number may return #f whenever an ex- (boolean? #f) =⇒ #t
ponent marker or explicit exactness prefix is used, or if a # (boolean? 0) =⇒ #f
appears in place of a digit. If all inexact numbers are integers, (boolean? ’()) =⇒ #f
then string->number may return #f whenever a decimal point
is used.
6.3.2. Pairs and lists
Note: Programmers accustomed to other dialects of Lisp The empty list is a special object of its own type (it is not
should be aware that Scheme distinguishes both #f and the a pair); it has no elements and its length is zero.
empty list from the symbol nil. Note: The above definitions imply that all lists have finite
length and are terminated by the empty list.
Boolean constants evaluate to themselves, so they do not
need to be quoted in programs. The most general notation (external representation) for
Scheme pairs is the “dotted” notation (c1 . c2 ) where c1
#t =⇒ #t is the value of the car field and c2 is the value of the cdr
#f =⇒ #f
field. For example (4 . 5) is a pair whose car is 4 and
’#f =⇒ #f
whose cdr is 5. Note that (4 . 5) is the external repre-
sentation of a pair, not an expression that evaluates to a
pair.
(not obj ) library procedure
A more streamlined notation can be used for lists: the
Not returns #t if obj is false, and returns #f otherwise. elements of the list are simply enclosed in parentheses and
(not #t) =⇒ #f
separated by spaces. The empty list is written () . For
(not 3) =⇒ #f example,
(not (list 3)) =⇒ #f (a b c d e)
(not #f) =⇒ #t
(not ’()) =⇒ #f and
(not (list)) =⇒ #f
(not ’nil) =⇒ #f (a . (b . (c . (d . (e . ())))))
26 Revised5 Scheme
Pair? returns #t if obj is a pair, and otherwise returns #f. These procedures are compositions of car and cdr, where
for example caddr could be defined by
(pair? ’(a . b)) =⇒ #t
(pair? ’(a b c)) =⇒ #t (define caddr (lambda (x) (car (cdr (cdr x))))).
(pair? ’()) =⇒ #f
(pair? ’#(a b)) =⇒ #f Arbitrary compositions, up to four deep, are provided.
There are twenty-eight of these procedures in all.
characters “#\space” could be taken to be either a repre- (char-alphabetic? char ) library procedure
sentation of the space character or a representation of the (char-numeric? char ) library procedure
character “#\s” followed by a representation of the symbol (char-whitespace? char ) library procedure
“pace.” (char-upper-case? letter ) library procedure
(char-lower-case? letter ) library procedure
Characters written in the #\ notation are self-evaluating.
That is, they do not have to be quoted in programs. These procedures return #t if their arguments are alpha-
betic, numeric, whitespace, upper case, or lower case char-
Some of the procedures that operate on characters ignore
acters, respectively, otherwise they return #f. The follow-
the difference between upper case and lower case. The pro-
ing remarks, which are specific to the ASCII character set,
cedures that ignore case have “-ci” (for “case insensitive”)
are intended only as a guide: The alphabetic characters are
embedded in their names.
the 52 upper and lower case letters. The numeric charac-
ters are the ten decimal digits. The whitespace characters
(char? obj ) procedure are space, tab, line feed, form feed, and carriage return.
Returns #t if obj is a character, otherwise returns #f.
(char->integer char ) procedure
(char=? char1 char2 ) procedure (integer->char n) procedure
(char<? char1 char2 ) procedure Given a character, char->integer returns an exact inte-
(char>? char1 char2 ) procedure ger representation of the character. Given an exact inte-
(char<=? char1 char2 ) procedure ger that is the image of a character under char->integer,
(char>=? char1 char2 ) procedure integer->char returns that character. These procedures
These procedures impose a total ordering on the set of implement order-preserving isomorphisms between the set
characters. It is guaranteed that under this ordering: of characters under the char<=? ordering and some subset
of the integers under the <= ordering. That is, if
• The upper case characters are in order. For example, (char<=? a b) =⇒ #t and (<= x y) =⇒ #t
(char<? #\A #\B) returns #t.
and x and y are in the domain of integer->char, then
• The lower case characters are in order. For example,
(<= (char->integer a)
(char<? #\a #\b) returns #t.
(char->integer b)) =⇒ #t
• The digits are in order. For example, (char<? #\0
(char<=? (integer->char x)
#\9) returns #t.
(integer->char y)) =⇒ #t
• Either all the digits precede all the upper case letters,
or vice versa.
(char-upcase char ) library procedure
• Either all the digits precede all the lower case letters, (char-downcase char ) library procedure
or vice versa.
These procedures return a character char2 such that
(char-ci=? char char2 ). In addition, if char is alpha-
Some implementations may generalize these procedures to betic, then the result of char-upcase is upper case and
take more than two arguments, as with the corresponding the result of char-downcase is lower case.
numerical predicates.
6.3.5. Strings
(char-ci=? char1 char2 ) library procedure
(char-ci<? char1 char2 ) library procedure Strings are sequences of characters. Strings are written
(char-ci>? char1 char2 ) library procedure as sequences of characters enclosed within doublequotes
(char-ci<=? char1 char2 ) library procedure ("). A doublequote can be written inside a string only by
(char-ci>=? char1 char2 ) library procedure escaping it with a backslash (\), as in
These procedures are similar to char=? et cetera, but they "The word \"recursion\" has many meanings."
treat upper case and lower case letters as the same. For
example, (char-ci=? #\A #\a) returns #t. Some imple- A backslash can be written inside a string only by escaping
mentations may generalize these procedures to take more it with another backslash. Scheme does not specify the
than two arguments, as with the corresponding numerical effect of a backslash within a string that is not followed by
predicates. a doublequote or backslash.
30 Revised5 Scheme
A string constant may continue from one line to the next, (string=? string1 string2 ) library procedure
but the exact contents of such a string are unspecified. (string-ci=? string1 string2 ) library procedure
The length of a string is the number of characters that it Returns #t if the two strings are the same length and con-
contains. This number is an exact, non-negative integer tain the same characters in the same positions, otherwise
that is fixed when the string is created. The valid indexes returns #f. String-ci=? treats upper and lower case let-
of a string are the exact non-negative integers less than ters as though they were the same character, but string=?
the length of the string. The first character of a string has treats upper and lower case as distinct characters.
index 0, the second has index 1, and so on.
In phrases such as “the characters of string beginning with (string<? string1 string2 ) library procedure
index start and ending with index end ,” it is understood (string>? string1 string2 ) library procedure
that the index start is inclusive and the index end is ex- (string<=? string1 string2 ) library procedure
clusive. Thus if start and end are the same index, a null (string>=? string1 string2 ) library procedure
substring is referred to, and if start is zero and end is the (string-ci<? string1 string2 ) library procedure
length of string, then the entire string is referred to. (string-ci>? string1 string2 ) library procedure
(string-ci<=? string1 string2 ) library procedure
Some of the procedures that operate on strings ignore the
(string-ci>=? string1 string2 ) library procedure
difference between upper and lower case. The versions that
ignore case have “-ci” (for “case insensitive”) embedded These procedures are the lexicographic extensions to
in their names. strings of the corresponding orderings on characters. For
example, string<? is the lexicographic ordering on strings
induced by the ordering char<? on characters. If two
(string? obj ) procedure
strings differ in length but are the same up to the length
Returns #t if obj is a string, otherwise returns #f. of the shorter string, the shorter string is considered to be
lexicographically less than the longer string.
(make-string k) procedure Implementations may generalize these and the string=?
(make-string k char ) procedure and string-ci=? procedures to take more than two argu-
Make-string returns a newly allocated string of length k. ments, as with the corresponding numerical predicates.
If char is given, then all elements of the string are ini-
tialized to char , otherwise the contents of the string are (substring string start end ) library procedure
unspecified. String must be a string, and start and end must be exact
integers satisfying
(string char . . . ) library procedure
0 ≤ start ≤ end ≤ (string-length string).
Returns a newly allocated string composed of the argu-
ments. Substring returns a newly allocated string formed from
the characters of string beginning with index start (inclu-
(string-length string) procedure sive) and ending with index end (exclusive).
Returns the number of characters in the given string.
(string-append string . . . ) library procedure
(string-ref string k) procedure Returns a newly allocated string whose characters form the
concatenation of the given strings.
k must be a valid index of string. String-ref returns
character k of string using zero-origin indexing.
(string->list string) library procedure
(list->string list) library procedure
(string-set! string k char ) procedure
String->list returns a newly allocated list of the charac-
k must be a valid index of string. String-set! stores char ters that make up the given string. List->string returns
in element k of string and returns an unspecified value. a newly allocated string formed from the characters in the
(define (f) (make-string 3 #\*)) list list, which must be a list of characters. String->list
(define (g) "***") and list->string are inverses so far as equal? is con-
(string-set! (f) 0 #\?) =⇒ unspecified cerned.
(string-set! (g) 0 #\?) =⇒ error
(string-set! (symbol->string ’immutable)
(string-copy string) library procedure
0
#\?) =⇒ error Returns a newly allocated copy of the given string.
6. Standard procedures 31
Vectors are written using the notation #(obj . . . ). For (vector-set! ’#(0 1 2) 1 "doe")
example, a vector of length 3 containing the number zero =⇒ error ; constant vector
in element 0, the list (2 2 2 2) in element 1, and the
string "Anna" in element 2 can be written as following:
(vector->list vector ) library procedure
#(0 (2 2 2 2) "Anna") (list->vector list) library procedure
Note that this is the external representation of a vector, not Vector->list returns a newly allocated list of the objects
an expression evaluating to a vector. Like list constants, contained in the elements of vector . List->vector returns
vector constants must be quoted: a newly created vector initialized to the elements of the list
’#(0 (2 2 2 2) "Anna") list.
=⇒ #(0 (2 2 2 2) "Anna") (vector->list ’#(dah dah didah))
=⇒ (dah dah didah)
(list->vector ’(dididit dah))
(vector? obj ) procedure
=⇒ #(dididit dah)
Returns #t if obj is a vector, otherwise returns #f.
(vector-fill! vector fill ) library procedure
(make-vector k ) procedure
(make-vector k fill ) procedure Stores fill in every element of vector . The value returned
by vector-fill! is unspecified.
Returns a newly allocated vector of k elements. If a second
argument is given, then each element is initialized to fill .
Otherwise the initial contents of each element is unspeci- 6.4. Control features
fied.
This chapter describes various primitive procedures which
(vector obj . . . ) library procedure control the flow of program execution in special ways. The
Returns a newly allocated vector whose elements contain procedure? predicate is also described here.
the given arguments. Analogous to list.
(vector ’a ’b ’c) =⇒ #(a b c) (procedure? obj ) procedure
Returns #t if obj is a procedure, otherwise returns #f.
(vector-length vector ) procedure (procedure? car) =⇒ #t
Returns the number of elements in vector as an exact in- (procedure? ’car) =⇒ #f
teger. (procedure? (lambda (x) (* x x)))
=⇒ #t
(procedure? ’(lambda (x) (* x x)))
(vector-ref vector k ) procedure
=⇒ #f
k must be a valid index of vector . Vector-ref returns the (call-with-current-continuation procedure?)
contents of element k of vector . =⇒ #t
32 Revised5 Scheme
(apply proc arg1 . . . args) procedure computed and returned. The value of the promise is cached
Proc must be a procedure and args must be a list. Calls (or “memoized”) so that if it is forced a second time, the
proc with the elements of the list (append (list arg1 previously computed value is returned.
. . . ) args) as the actual arguments. (force (delay (+ 1 2))) =⇒ 3
(let ((p (delay (+ 1 2))))
(apply + (list 3 4)) =⇒ 7
(list (force p) (force p)))
=⇒ (3 3)
(define compose
(lambda (f g)
(define a-stream
(lambda args
(letrec ((next
(f (apply g args)))))
(lambda (n)
(cons n (delay (next (+ n 1)))))))
((compose sqrt *) 12 75) =⇒ 30
(next 0)))
(define head car)
(map proc list1 list2 . . . ) library procedure (define tail
(lambda (stream) (force (cdr stream))))
The lists must be lists, and proc must be a procedure taking
as many arguments as there are lists and returning a single (head (tail (tail a-stream)))
value. If more than one list is given, then they must all =⇒ 2
be the same length. Map applies proc element-wise to the
elements of the lists and returns a list of the results, in Force and delay are mainly intended for programs written
order. The dynamic order in which proc is applied to the in functional style. The following examples should not be
elements of the lists is unspecified. considered to illustrate good programming style, but they
illustrate the property that only one value is computed for
(map cadr ’((a b) (d e) (g h))) a promise, no matter how many times it is forced.
=⇒ (b e h)
(define count 0)
(map (lambda (n) (expt n n)) (define p
’(1 2 3 4 5)) (delay (begin (set! count (+ count 1))
=⇒ (1 4 27 256 3125) (if (> count x)
count
(map + ’(1 2 3) ’(4 5 6)) =⇒ (5 7 9) (force p)))))
(define x 5)
(let ((count 0)) p =⇒ a promise
(map (lambda (ignored) (force p) =⇒ 6
(set! count (+ count 1)) p =⇒ a promise, still
count) (begin (set! x 10)
’(a b))) =⇒ (1 2) or (2 1) (force p)) =⇒ 6
grammers to do that by creating a procedure that acts just like Scheme, because of call-with-current-continuation,
the current continuation. the dynamic extent of a call may not be a single, connected
Most programming languages incorporate one or more special- time period. It is defined as follows:
purpose escape constructs with names like exit, return, or
even goto. In 1965, however, Peter Landin [16] invented a • The dynamic extent is entered when execution of the
general purpose escape operator called the J-operator. John body of the called procedure begins.
Reynolds [24] described a simpler but equally powerful con-
• The dynamic extent is also entered when exe-
struct in 1972. The catch special form described by Sussman
cution is not within the dynamic extent and a
and Steele in the 1975 report on Scheme is exactly the same as
continuation is invoked that was captured (using
Reynolds’s construct, though its name came from a less general
call-with-current-continuation) during the dy-
construct in MacLisp. Several Scheme implementors noticed
namic extent.
that the full power of the catch construct could be provided by
a procedure instead of by a special syntactic construct, and the • It is exited when the called procedure returns.
name call-with-current-continuation was coined in 1982.
This name is descriptive, but opinions differ on the merits of • It is also exited when execution is within the dynamic
such a long name, and some people use the name call/cc in- extent and a continuation is invoked that was captured
stead. while not within the dynamic extent.
6.6.1. Ports
(eval expression environment-specifier ) procedure
Ports represent input and output devices. To Scheme, an
Evaluates expression in the specified environment and re- input port is a Scheme object that can deliver characters
turns its value. Expression must be a valid Scheme expres- upon command, while an output port is a Scheme object
sion represented as data, and environment-specifier must that can accept characters.
be a value returned by one of the three procedures de-
scribed below. Implementations may extend eval to allow
non-expression programs (definitions) as the first argument (call-with-input-file string proc) library procedure
and to allow other values as environments, with the re- (call-with-output-file string proc) library procedure
striction that eval is not allowed to create new bindings String should be a string naming a file, and proc
in the environments associated with null-environment or should be a procedure that accepts one argument. For
scheme-report-environment. call-with-input-file, the file should already exist; for
(eval ’(* 7 3) (scheme-report-environment 5)) call-with-output-file, the effect is unspecified if the
=⇒ 21 file already exists. These procedures call proc with one ar-
gument: the port obtained by opening the named file for
(let ((f (eval ’(lambda (f x) (f x x)) input or output. If the file cannot be opened, an error is
(null-environment 5)))) signalled. If proc returns, then the port is closed automati-
(f + 10)) cally and the value(s) yielded by the proc is(are) returned.
=⇒ 20 If proc does not return, then the port will not be closed
automatically unless it is possible to prove that the port
will never again be used for a read or write operation.
(scheme-report-environment version) procedure Rationale: Because Scheme’s escape procedures have un-
(null-environment version) procedure limited extent, it is possible to escape from the current con-
Version must be the exact integer 5, corresponding to this tinuation but later to escape back in. If implementations
revision of the Scheme report (the Revised5 Report on were permitted to close the port on any escape from the
Scheme). Scheme-report-environment returns a specifier current continuation, then it would be impossible to write
for an environment that is empty except for all bindings de- portable code using both call-with-current-continuation
fined in this report that are either required or both optional and call-with-input-file or call-with-output-file.
and supported by the implementation. Null-environment
returns a specifier for an environment that is empty except (input-port? obj ) procedure
for the (syntactic) bindings for all syntactic keywords de- (output-port? obj ) procedure
fined in this report that are either required or both optional
and supported by the implementation. Returns #t if obj is an input port or output port respec-
tively, otherwise returns #f.
Other values of version can be used to specify environments
matching past revisions of this report, but their support is
not required. An implementation will signal an error if (current-input-port) procedure
version is neither 5 nor another value supported by the (current-output-port) procedure
implementation. Returns the current default input or output port.
The effect of assigning (through the use of eval) a vari-
able bound in a scheme-report-environment (for exam-
ple car) is unspecified. Thus the environments specified (with-input-from-file string thunk )
by scheme-report-environment may be immutable. optional procedure
(with-output-to-file string thunk )
optional procedure
(interaction-environment) optional procedure
String should be a string naming a file, and proc should be
This procedure returns a specifier for the environment that a procedure of no arguments. For with-input-from-file,
contains implementation-defined bindings, typically a su- the file should already exist; for with-output-to-file,
perset of those listed in the report. The intent is that this the effect is unspecified if the file already exists. The
procedure will return the environment in which the imple- file is opened for input or output, an input or output
mentation would evaluate expressions dynamically typed port connected to it is made the default value returned
by the user. by current-input-port or current-output-port (and is
36 Revised5 Scheme
used by (read), (write obj ), and so forth), and the thunk (read-char) procedure
is called with no arguments. When the thunk returns, (read-char port) procedure
the port is closed and the previous default is restored.
Returns the next character available from the input port,
With-input-from-file and with-output-to-file re-
updating the port to point to the following character. If
turn(s) the value(s) yielded by thunk . If an escape pro-
no more characters are available, an end of file object is
cedure is used to escape from the continuation of these
returned. Port may be omitted, in which case it defaults
procedures, their behavior is implementation dependent.
to the value returned by current-input-port.
(write obj ) library procedure sequentially. It is unspecified whether the results of the
(write obj port) library procedure expressions are printed. The load procedure does not
Writes a written representation of obj to the given port. affect the values returned by current-input-port and
Strings that appear in the written representation are en- current-output-port. Load returns an unspecified value.
closed in doublequotes, and within those strings backslash Rationale: For portability, load must operate on source files.
and doublequote characters are escaped by backslashes. Its operation on other kinds of files necessarily varies among
Character objects are written using the #\ notation. Write implementations.
returns an unspecified value. The port argument may be
omitted, in which case it defaults to the value returned by
current-output-port. (transcript-on filename) optional procedure
(transcript-off) optional procedure
(display obj ) library procedure Filename must be a string naming an output file to be cre-
(display obj port) library procedure ated. The effect of transcript-on is to open the named
Writes a representation of obj to the given port. Strings file for output, and to cause a transcript of subsequent
that appear in the written representation are not enclosed interaction between the user and the Scheme system to
in doublequotes, and no characters are escaped within be written to the file. The transcript is ended by a call
those strings. Character objects appear in the represen- to transcript-off, which closes the transcript file. Only
tation as if written by write-char instead of by write. one transcript may be in progress at any time, though some
Display returns an unspecified value. The port argument implementations may relax this restriction. The values re-
may be omitted, in which case it defaults to the value re- turned by these procedures are unspecified.
turned by current-output-port.
Rationale: Write is intended for producing machine-readable
output and display is for producing human-readable output.
Implementations that allow “slashification” within symbols will
probably want write but not display to slashify funny charac-
ters in symbols.
where I* is the sequence of variables defined in P, P0 is the E[[I]] = λρκ . hold (lookup ρ I)
sequence of expressions obtained by replacing every defini- (single(λ . = undefined →
tion in P by an assignment, hundefinedi is an expression wrong “undefined variable”,
that evaluates to undefined, and E is the semantic function send κ))
that assigns meaning to expressions. E[[(E0 E*)]] =
λρκ . E*(permute(hE0 i § E*))
ρ
7.2.1. Abstract syntax (λ* . ((λ* . applicate (* ↓ 1) (* † 1) κ)
(unpermute *)))
K ∈ Con constants, including quotations
I ∈ Ide identifiers (variables) E[[(lambda (I*) Γ* E0 )]] =
E ∈ Exp expressions λρκ . λσ .
new σ ∈ L →
Γ ∈ Com = Exp commands
send (hnew σ | L,
λ*κ0 . #* = #I* →
tievals(λα* . (λρ0 . C[[Γ*]]ρ0 (E[[E0 ]]ρ0 κ0 ))
Exp −→ K | I | (E0 E*)
(extends ρ I* α*))
| (lambda (I*) Γ* E0 )
*,
| (lambda (I* . I) Γ* E0 ) wrong “wrong number of arguments”i
| (lambda I Γ* E0 ) in E)
| (if E0 E1 E2 ) | (if E0 E1 ) κ
| (set! I E) (update (new σ | L) unspecified σ),
wrong “out of memory” σ
E[[(lambda (I* . I) Γ* E0 )]] =
7.2.2. Domain equations λρκ . λσ .
new σ ∈ L →
α ∈ L locations send (hnew σ | L,
λ*κ0 . #* ≥ #I* →
ν ∈ N natural numbers
tievalsrest
T = {false, true} booleans
(λα* . (λρ0 . C[[Γ*]]ρ0 (E[[E0 ]]ρ0 κ0 ))
Q symbols (extends ρ (I* § hIi) α*))
H characters *
R numbers (#I*),
Ep = L×L×T pairs wrong “too few arguments”i in E)
Ev = L* × T vectors κ
Es = L* × T strings (update (new σ | L) unspecified σ),
M = {false, true, null, undefined, unspecified} wrong “out of memory” σ
miscellaneous E[[(lambda I Γ* E0 )]] = E[[(lambda (. I) Γ* E0 )]]
φ ∈ F = L × (E* → K → C) procedure values
∈ E = Q + H + R + Ep + E v + Es + M + F E[[(if E0 E1 E2 )]] =
λρκ . E[[E0 ]] ρ (single (λ . truish → E[[E1 ]]ρκ,
expressed values
E[[E2 ]]ρκ))
σ ∈ S = L → (E × T) stores
ρ ∈ U = Ide → L environments E[[(if E0 E1 )]] =
θ ∈ C = S→A command continuations λρκ . E[[E0 ]] ρ (single (λ . truish → E[[E1 ]]ρκ,
κ ∈ K = E* → C expression continuations send unspecified κ))
A answers Here and elsewhere, any expressed value other than undefined
X errors may be used in place of unspecified.
E[[(set! I E)]] =
λρκ . E[[E]] ρ (single(λ . assign (lookup ρ I)
7.2.3. Semantic functions
K: Con → E (send unspecified κ)))
E: Exp → U → K → C E*[[ ]] = λρκ . κh i
E* : Exp* → U → K → C
E*[[E0 E*]] =
C: Com* → U → C → C
λρκ . E[[E0 ]] ρ (single(λ0 . E*[[E*]] ρ (λ* . κ (h0 i § *))))
Definition of K deliberately omitted. C[[ ]] = λρθ . θ
E[[K]] = λρκ . send (K[[K]]) κ C[[Γ0 Γ*]] = λρθ . E[[Γ0 ]] ρ (λ* . C[[Γ*]]ρθ)
42 Revised5 Scheme
val ...)))) in the body of a lambda expression. In any case, note that
these rules apply only if the body of the begin contains no
definitions.
(define-syntax let*
(syntax-rules () (define-syntax begin
((let* () body1 body2 ...) (syntax-rules ()
(let () body1 body2 ...)) ((begin exp)
((let* ((name1 val1) (name2 val2) ...) exp)
body1 body2 ...) ((begin exp1 exp2 ...)
(let ((name1 val1)) (let ((x exp1))
(let* ((name2 val2) ...) (begin exp2 ...)))))
body1 body2 ...)))))
(define-syntax begin
(syntax-rules ()
((begin exp ...)
((lambda () exp ...)))))
NOTES EXAMPLE
Integrate-system integrates the system
Language changes
yk0 = fk (y1 , y2 , . . . , yn ), k = 1, . . . , n
This section enumerates the changes that have been made
of differential equations with the method of Runge-Kutta.
to Scheme since the “Revised4 report” [6] was published.
The parameter system-derivative is a function that
• The report is now a superset of the IEEE standard takes a system state (a vector of values for the state vari-
for Scheme [13]: implementations that conform to the ables y1 , . . . , yn ) and produces a system derivative (the val-
report will also conform to the standard. This required ues y10 , . . . , yn0 ). The parameter initial-state provides
the following changes: an initial system state, and h is an initial guess for the
length of the integration step.
– The empty list is now required to count as true. The value returned by integrate-system is an infinite
– The classification of features as essential or stream of system states.
inessential has been removed. There are now
(define integrate-system
three classes of built-in procedures: primitive, li- (lambda (system-derivative initial-state h)
brary, and optional. The optional procedures are (let ((next (runge-kutta-4 system-derivative h)))
load, with-input-from-file, with-output- (letrec ((states
to-file, transcript-on, transcript-off, and (cons initial-state
interaction-environment, and - and / with (delay (map-streams next
more than two arguments. None of these are in states)))))
the IEEE standard. states))))
– Programs are allowed to redefine built-in proce- Runge-Kutta-4 takes a function, f, that produces a system
dures. Doing so will not change the behavior of derivative from a system state. Runge-Kutta-4 produces
other built-in procedures. a function that takes a system state and produces a new
system state.
• Port has been added to the list of disjoint types.
(define runge-kutta-4
• The macro appendix has been removed. High-level (lambda (f h)
macros are now part of the main body of the report. (let ((*h (scale-vector h))
The rewrite rules for derived expressions have been (*2 (scale-vector 2))
replaced with macro definitions. There are no reserved (*1/2 (scale-vector (/ 1 2)))
identifiers. (*1/6 (scale-vector (/ 1 6))))
(lambda (y)
• Syntax-rules now allows vector patterns. ;; y is a system state
(let* ((k0 (*h (f y)))
• Multiple-value returns, eval, and dynamic-wind have (k1 (*h (f (add-vectors y (*1/2 k0)))))
been added. (k2 (*h (f (add-vectors y (*1/2 k1)))))
(k3 (*h (f (add-vectors y k2)))))
• The calls that are required to be implemented in a (add-vectors y
properly tail-recursive fashion are defined explicitly. (*1/6 (add-vectors k0
(*2 k1)
• ‘@’ can be used within identifiers. ‘|’ is reserved for (*2 k2)
possible future extensions. k3))))))))
(define elementwise
ADDITIONAL MATERIAL (lambda (f)
(lambda vectors
The Internet Scheme Repository at (generate-vector
(vector-length (car vectors))
http://www.cs.indiana.edu/scheme-repository/ (lambda (i)
contains an extensive Scheme bibliography, as well as pa- (apply f
(map (lambda (v) (vector-ref v i))
pers, programs, implementations, and other material re-
vectors)))))))
lated to Scheme.
(define generate-vector
(lambda (size proc)
46 Revised5 Scheme
[12] IEEE Standard 754-1985. IEEE Standard for Binary [25] Guy Lewis Steele Jr. and Gerald Jay Sussman. The
Floating-Point Arithmetic. IEEE, New York, 1985. revised report on Scheme, a dialect of Lisp. MIT Ar-
tificial Intelligence Memo 452, January 1978.
[13] IEEE Standard 1178-1990. IEEE Standard for the
Scheme Programming Language. IEEE, New York, [26] Guy Lewis Steele Jr. Rabbit: a compiler for Scheme.
1991. MIT Artificial Intelligence Laboratory Technical Re-
port 474, May 1978.
[14] Eugene E. Kohlbecker Jr. Syntactic Extensions in
the Programming Language Lisp. PhD thesis, Indi- [27] Guy Lewis Steele Jr. Common Lisp: The Language,
ana University, August 1986. second edition. Digital Press, Burlington MA, 1990.
[15] Eugene E. Kohlbecker Jr., Daniel P. Friedman, [28] Gerald Jay Sussman and Guy Lewis Steele Jr.
Matthias Felleisen, and Bruce Duba. Hygienic macro Scheme: an interpreter for extended lambda calcu-
expansion. In Proceedings of the 1986 ACM Con- lus. MIT Artificial Intelligence Memo 349, December
ference on Lisp and Functional Programming, pages 1975.
151–161. [29] Joseph E. Stoy. Denotational Semantics: The Scott-
Strachey Approach to Programming Language The-
[16] Peter Landin. A correspondence between Algol 60
ory. MIT Press, Cambridge, 1977.
and Church’s lambda notation: Part I. Communica-
tions of the ACM 8(2):89–101, February 1965. [30] Texas Instruments, Inc. TI Scheme Language Ref-
erence Manual. Preliminary version 1.0, November
[17] MIT Department of Electrical Engineering and Com- 1985.
puter Science. Scheme manual, seventh edition.
September 1984.
The principal entry for each term, procedure, or keyword is case 10; 43
listed first, separated from the other entries by a semicolon. catch 34
cdddar 26
! 5 cddddr 26
’ 8; 26 cdr 26
* 22 ceiling 23
+ 22; 5, 42 char->integer 29
, 13; 26 char-alphabetic? 29
,@ 13 char-ci<=? 29
- 22; 5 char-ci<? 29
-> 5 char-ci=? 29
... 5; 14 char-ci>=? 29
/ 22 char-ci>? 29
; 5 char-downcase 29
< 21; 42 char-lower-case? 29
<= 21 char-numeric? 29
= 21; 22 char-ready? 36
=> 10 char-upcase 29
> 21 char-upper-case? 29
>= 21 char-whitespace? 29
? 4 char<=? 29
‘ 13 char<? 29
char=? 29
abs 22; 24
char>=? 29
acos 23
char>? 29
and 11; 43
char? 29; 6
angle 24
close-input-port 36
append 27
close-output-port 36
apply 32; 8, 43
combination 9
asin 23
comma 13
assoc 27
comment 5; 38
assq 27
complex? 21; 19
assv 27
cond 10; 15, 43
atan 23
cons 26
#b 21; 38 constant 7
backquote 13 continuation 33
begin 12; 16, 44 cos 23
binding 6 current-input-port 35
binding construct 6 current-output-port 35
boolean? 25; 6
bound 6 #d 21
define 16; 14
caar 26 define-syntax 17
cadr 26 definition 16
call 9 delay 13; 32
call by need 13 denominator 23
call-with-current-continuation 33; 8, 34, 43 display 37
call-with-input-file 35 do 12; 44
call-with-output-file 35 dotted pair 25
call-with-values 34; 8, 43 dynamic-wind 34; 33
call/cc 34
car 26; 42 #e 21; 38
Index 49
else 10 library 3
empty list 25; 6, 26 library procedure 17
eof-object? 36 list 27
eq? 18; 10 list->string 30
equal? 19 list->vector 31
equivalence predicate 17 list-ref 27
eqv? 17; 7, 10, 42 list-tail 27
error 4 list? 26
escape procedure 33 load 37
eval 35; 8 location 7
even? 22 log 23
exact 17
exact->inexact 24 macro 13
exact? 21 macro keyword 13
exactness 19 macro transformer 13
exp 23 macro use 13
expt 24 magnitude 24
make-polar 24
#f 25 make-rectangular 24
false 6; 25 make-string 30
floor 23 make-vector 31
for-each 32 map 32
force 32; 13 max 22
member 27
gcd 23 memq 27
memv 27
hygienic 13 min 22
modulo 22
#i 21; 38 mutable 7
identifier 5; 6, 28, 38
if 10; 41 negative? 22
imag-part 24 newline 37
immutable 7 nil 25
implementation restriction 4; 20 not 25
improper list 26 null-environment 35
inexact 17 null? 26
inexact->exact 24; 20 number 19
inexact? 21 number->string 24
initial environment 17 number? 21; 6, 19
input-port? 35 numerator 23
integer->char 29 numerical types 19
integer? 21; 19
interaction-environment 35 #o 21; 38
internal definition 16 object 3
odd? 22
keyword 13; 38 open-input-file 36
open-output-file 36
lambda 9; 16, 41 optional 3
lazy evaluation 13 or 11; 43
lcm 23 output-port? 35
length 27; 20
let 11; 12, 15, 16, 43 pair 25
let* 11; 16, 44 pair? 26; 6
let-syntax 14; 16 peek-char 36
letrec 11; 16, 44 port 35
letrec-syntax 14; 16 port? 6
50 Revised5 Scheme