Read without ads and support Scribd by becoming a Scribd Premium Reader.
 
Revised5
.
91Report on the Algorithmic LanguageScheme
M
ICHAEL
S
PERBER
W
ILLIAM
C
LINGER
, R. K
ENT
D
YBVIG
, M
ATTHEW
F
LATT
, A
NTON VAN
S
TRAATEN
R
ICHARD
K
ELSEY
, J
ONATHAN
R
EES
(
Editors
)H. A
BELSON
R. B. F
INDLER
C. T. H
AYNES
K. M. P
ITMAN
N. I. A
DAMS IV
D. P. F
RIEDMAN
E. K
OHLBECKER
G. J. R
OZAS
D. H. B
ARTLEY
R. H
ALSTEAD
J. M
ATTHEWS
G. L. S
TEELE
J
R
.G. B
ROOKS
C. H
ANSON
D. O
XLEY
G. J. S
USSMAN
M. W
AND
5 September 2006
SUMMARY
The report gives a defining description of the programming language Scheme. Scheme is a statically scoped and properlytail-recursive dialect of the Lisp programming language invented by Guy Lewis Steele Jr. and Gerald Jay Sussman. It wasdesigned to have an exceptionally clear and simple semantics and few different ways to form expressions. A wide varietyof programming paradigms, including imperative, functional, and message passing styles, find convenient expression inScheme.The introduction offers a brief history of the language and of the report. It also gives a short introduction to the basicconcepts of the language.Chapter 2 explains Scheme’s number types. Chapter 3 defines the read syntax of Scheme programs. Chapter 4 presentsthe fundamental semantic ideas of the language. Chapter 5 defines notational conventions used in the rest of the report.Chapters 6 and 7 describe libraries and scripts, the basic organizational units of Scheme programs. Chapter 8 explainsthe expansion process for Scheme code.Chapter 9 explains the Scheme base library which contains the fundamental forms useful to programmers.The next set of chapters describe libraries that provide specific functionality: Unicode semantics for characters andstrings, binary data, list utility procedures, a record system, exceptions and conditions, I/O, specialized libraries fordealing with numbers and arithmetic, the
syntax-case
facility for writing arbitrary macros, hash tables, enumerations,and various miscellaneous libraries.Chapter 21 describes the composite library containing most of the forms described in this report. Chapter 22 describes the
eval
facility for evaluating Scheme expressions represented as data. Chapter 23 describes the operations for mutatingpairs. Chapter 24 describes a library with some procedures from the previous version of this report for backwardscompatibility.Appendix A provides a formal semantics for a core of Scheme. Appendix B contains definitions for some of the derivedforms described in the report.The report concludes with a list of references and an alphabetic index.
*** DRAFT***
This is a preliminary draft. It is intended to reflect the decisions taken by the editors’ comittee, but contains manymistakes, ambiguities and inconsistencies.
 
2 Revised
5
.
91
Scheme
CONTENTS
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
Description of the language
1 Overview of Scheme . . . . . . . . . . . . . . . . . . . . . . . 51.1 Basic types . . . . . . . . . . . . . . . . . . . . . . . . 51.2 Expressions . . . . . . . . . . . . . . . . . . . . . . . . 61.3 Variables and binding . . . . . . . . . . . . . . . . . . 61.4 Denitions . . . . . . . . . . . . . . . . . . . . . . . . . 61.5 Procedures . . . . . . . . . . . . . . . . . . . . . . . . 71.6 Procedure calls and syntactic keywords . . . . . . . . . 71.7 Assignment . . . . . . . . . . . . . . . . . . . . . . . . 71.8 Derived forms and macros . . . . . . . . . . . . . . . . 81.9 Syntactic datums and datum values . . . . . . . . . . 81.10 Libraries . . . . . . . . . . . . . . . . . . . . . . . . . . 81.11 Scripts . . . . . . . . . . . . . . . . . . . . . . . . . . . 82 Numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92.1 Numerical types . . . . . . . . . . . . . . . . . . . . . 92.2 Exactness . . . . . . . . . . . . . . . . . . . . . . . . . 92.3 Implementation restrictions . . . . . . . . . . . . . . . 92.4 Innities and NaNs . . . . . . . . . . . . . . . . . . . . 103 Lexical syntax and read syntax . . . . . . . . . . . . . . . . 103.1 Notation . . . . . . . . . . . . . . . . . . . . . . . . . . 103.2 Lexical syntax . . . . . . . . . . . . . . . . . . . . . . . 113.3 Read syntax . . . . . . . . . . . . . . . . . . . . . . . . 154 Semantic concepts . . . . . . . . . . . . . . . . . . . . . . . . 164.1 Programs and libraries . . . . . . . . . . . . . . . . . . 164.2 Variables, syntactic keywords, and regions . . . . . . . 164.3 Exceptional situations . . . . . . . . . . . . . . . . . . 174.4 Safety . . . . . . . . . . . . . . . . . . . . . . . . . . . 174.5 Multiple return values . . . . . . . . . . . . . . . . . . 174.6 Storage model . . . . . . . . . . . . . . . . . . . . . . . 174.7 Proper tail recursion . . . . . . . . . . . . . . . . . . . 185 Notation and terminology . . . . . . . . . . . . . . . . . . . 185.1 Entry format . . . . . . . . . . . . . . . . . . . . . . . 185.2 List arguments . . . . . . . . . . . . . . . . . . . . . . 195.3 Evaluation examples . . . . . . . . . . . . . . . . . . . 195.4 Unspecied behavior . . . . . . . . . . . . . . . . . . . 205.5 Exceptional situations . . . . . . . . . . . . . . . . . . 205.6 Naming conventions . . . . . . . . . . . . . . . . . . . 205.7 Syntax violations . . . . . . . . . . . . . . . . . . . . . 206 Libraries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 206.1 Library form . . . . . . . . . . . . . . . . . . . . . . . 216.2 Import and export phases . . . . . . . . . . . . . . . . 236.3 Primitive syntax . . . . . . . . . . . . . . . . . . . . . 246.4 Examples . . . . . . . . . . . . . . . . . . . . . . . . . 257 Scripts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 267.1 Script syntax . . . . . . . . . . . . . . . . . . . . . . . 267.2 Script semantics . . . . . . . . . . . . . . . . . . . . . 278 Expansion process . . . . . . . . . . . . . . . . . . . . . . . . 279 Base library . . . . . . . . . . . . . . . . . . . . . . . . . . . 289.1 Base types . . . . . . . . . . . . . . . . . . . . . . . . . 289.2 Denitions . . . . . . . . . . . . . . . . . . . . . . . . . 299.3 Syntax denitions . . . . . . . . . . . . . . . . . . . . 299.4 Bodies and sequences . . . . . . . . . . . . . . . . . . . 299.5 Expressions . . . . . . . . . . . . . . . . . . . . . . . . 309.6 Equivalence predicates . . . . . . . . . . . . . . . . . . 359.7 Procedure predicate . . . . . . . . . . . . . . . . . . . 379.8 Unspecied value . . . . . . . . . . . . . . . . . . . . . 379.9 End of le object . . . . . . . . . . . . . . . . . . . . . 379.10 Generic arithmetic . . . . . . . . . . . . . . . . . . . . 379.11 Booleans . . . . . . . . . . . . . . . . . . . . . . . . . . 439.12 Pairs and lists . . . . . . . . . . . . . . . . . . . . . . . 449.13 Symbols . . . . . . . . . . . . . . . . . . . . . . . . . . 459.14 Characters . . . . . . . . . . . . . . . . . . . . . . . . . 469.15 Strings . . . . . . . . . . . . . . . . . . . . . . . . . . . 469.16 Vectors . . . . . . . . . . . . . . . . . . . . . . . . . . 489.17 Errors and violations . . . . . . . . . . . . . . . . . . . 489.18 Control features . . . . . . . . . . . . . . . . . . . . . . 499.19 Iteration . . . . . . . . . . . . . . . . . . . . . . . . . . 519.20 Binding constructs for syntactic keywords . . . . . . . 539.21
syntax-rules
. . . . . . . . . . . . . . . . . . . . . . . 549.22 Declarations . . . . . . . . . . . . . . . . . . . . . . . . 569.23 Tail calls and tail contexts . . . . . . . . . . . . . . . . 56
Description of the standard libraries
10Unicode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5810.1 Characters . . . . . . . . . . . . . . . . . . . . . . . . . 5810.2 Strings . . . . . . . . . . . . . . . . . . . . . . . . . . . 5911Bytes objects . . . . . . . . . . . . . . . . . . . . . . . . . . 6012List utilities . . . . . . . . . . . . . . . . . . . . . . . . . . . 6313Records . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6513.1 Procedural layer . . . . . . . . . . . . . . . . . . . . . 6613.2 Explicit-naming syntactic layer . . . . . . . . . . . . . 6913.3 Implicit-naming syntactic layer . . . . . . . . . . . . . 7113.4 Inspection . . . . . . . . . . . . . . . . . . . . . . . . . 7214Exceptions and conditions . . . . . . . . . . . . . . . . . . . 7214.1 Exceptions . . . . . . . . . . . . . . . . . . . . . . . . 7314.2 Conditions . . . . . . . . . . . . . . . . . . . . . . . . . 7414.3 Standard condition types . . . . . . . . . . . . . . . . 7615I/O . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7815.1 Condition types . . . . . . . . . . . . . . . . . . . . . . 7815.2 Primitive I/O . . . . . . . . . . . . . . . . . . . . . . . 7915.3 Port I/O . . . . . . . . . . . . . . . . . . . . . . . . . . 8515.4 Simple I/O . . . . . . . . . . . . . . . . . . . . . . . . 9316Arithmetic . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9416.1 Representability of infinities and NaNs . . . . . . . . . 9416.2 Semantics of common operations . . . . . . . . . . . . 9416.3 Fixnums . . . . . . . . . . . . . . . . . . . . . . . . . . 9516.4 Flonums . . . . . . . . . . . . . . . . . . . . . . . . . . 10016.5 Exact arithmetic . . . . . . . . . . . . . . . . . . . . . 10216.6 Inexact arithmetic . . . . . . . . . . . . . . . . . . . . 10517
syntax-case
. . . . . . . . . . . . . . . . . . . . . . . . . . . 10717.1 Hygiene . . . . . . . . . . . . . . . . . . . . . . . . . . 10717.2 Syntax objects . . . . . . . . . . . . . . . . . . . . . . 10817.3 Transformers . . . . . . . . . . . . . . . . . . . . . . . 10917.4 Parsing input and producing output . . . . . . . . . . 10917.5 Identifier predicates . . . . . . . . . . . . . . . . . . . 11117.6 Syntax-object and datum conversions . . . . . . . . . 11217.7 Generating lists of temporaries . . . . . . . . . . . . . 11317.8 Derived forms and procedures . . . . . . . . . . . . . . 11417.9 Syntax violations . . . . . . . . . . . . . . . . . . . . . 11618Hash tables . . . . . . . . . . . . . . . . . . . . . . . . . . . 11618.1 Constructors . . . . . . . . . . . . . . . . . . . . . . . 11618.2 Procedures . . . . . . . . . . . . . . . . . . . . . . . . 11718.3 Inspection . . . . . . . . . . . . . . . . . . . . . . . . . 11818.4 Hash functions . . . . . . . . . . . . . . . . . . . . . . 11819Enumerations . . . . . . . . . . . . . . . . . . . . . . . . . . 11820Miscellaneous libraries . . . . . . . . . . . . . . . . . . . . . 12020.1
when
and
unless
. . . . . . . . . . . . . . . . . . . . . 12020.2
case-lambda
. . . . . . . . . . . . . . . . . . . . . . . . 12020.3 Delayed evaluation . . . . . . . . . . . . . . . . . . . . 12120.4 Command-line access . . . . . . . . . . . . . . . . . . . 12221Composite library . . . . . . . . . . . . . . . . . . . . . . . . 12222
eval
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12223Mutable pairs . . . . . . . . . . . . . . . . . . . . . . . . . . 12323.1 Procedures . . . . . . . . . . . . . . . . . . . . . . . . 12323.2 Mutable list arguments . . . . . . . . . . . . . . . . . . 12323.3 Procedures with list arguments . . . . . . . . . . . . . 12424R
5
RS compatibility . . . . . . . . . . . . . . . . . . . . . . . 125
Appendices
A Formal semantics . . . . . . . . . . . . . . . . . . . . . . . . 127B Sample definitions for derived forms . . . . . . . . . . . . . . 127C Additional material . . . . . . . . . . . . . . . . . . . . . . . 129D Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130Alphabetic index of definitions of concepts,keywords, and procedures . . . . . . . . . . . . . . . . 133
 
Introduction 3
INTRODUCTION
Programming languages should be designed not by pilingfeature on top of feature, but by removing the weaknessesand restrictions that make additional features appear nec-essary. Scheme demonstrates that a very small number of rules for forming expressions, with no restrictions on howthey are composed, suffice to form a practical and efficientprogramming language that is flexible enough to supportmost of the major programming paradigms in use today.Scheme was one of the first programming languages to in-corporate first class procedures as in the lambda calculus,thereby proving the usefulness of static scope rules andblock structure in a dynamically typed language. Schemewas the first major dialect of Lisp to distinguish proceduresfrom lambda expressions and symbols, to use a single lex-ical environment for all variables, and to evaluate the op-erator position of a procedure call in the same way as anoperand position. By relying entirely on procedure callsto express iteration, Scheme emphasized the fact that tail-recursive procedure calls are essentially goto’s that passarguments. Scheme was the first widely used program-ming language to embrace first class escape procedures,from which all previously known sequential control struc-tures can be synthesized. A subsequent version of Schemeintroduced the concept of exact and inexact numbers, anextension of Common Lisp’s generic arithmetic. More re-cently, Scheme became the first programming language tosupport hygienic macros, which permit the syntax of ablock-structured language to be extended in a consistentand reliable manner.Numerical computation was long neglected by the Lispcommunity. Until Common Lisp there was no carefullythought out strategy for organizing numerical computa-tion, and with the exception of the MacLisp system [39]little effort was made to execute numerical code efficiently.The Scheme reports recognized the excellent work of theCommon Lisp committee and accepted many of their rec-ommendations, while simplifying and generalizing in someways consistent with the purposes of Scheme.
Background
The first description of Scheme was written by Gerald JaySussman and Guy Lewis Steele Jr. in 1975 [47]. A revisedreport by Steele and Sussman [44] appeared in 1978 anddescribed the evolution of the language as its MIT imple-mentation was upgraded to support an innovative com-piler [45]. Three distinct projects began in 1981 and 1982to use variants of Scheme for courses at MIT, Yale, andIndiana University [40, 36, 19]. An introductory computerscience textbook using Scheme was published in 1984 [1].A number of textbooks describing und using Scheme havebeen published since [15].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 othersites. Fifteen representatives of the major implementationsof Scheme therefore met in October 1984 to work towarda better and more widely accepted standard for Scheme.Their report [7], edited by Will Clinger, was published atMIT and Indiana University in the summer of 1985. Fur-ther revision took place in the spring of 1986 [42] (editedby Jonathan Rees and Will Clinger), and in the spring of 1988 [9] (also edited by Will Clinger and Jonathan Rees).Another revision published in 1998, edited by RichardKelsey, Will Clinger and Jonathan Rees, reflected furtherrevisions agreed upon in a meeting at Xerox PARC in June1992 [28].Attendees of the Scheme Workshop in Pittsburgh in Octo-ber 2002 formed a Strategy Committee to discuss a processfor producing new revisions of the report. The strategycommittee drafted a charter for Scheme standardization.This charter, together with a process for selecting editors’committees for producing new revisions for the report, wasconfirmed by the attendees of the Scheme Workshop inBoston in November 2003. Subsequently, a Steering Com-mittee according to the charter was selected, consisting of Alan Bawden, Guy L. Steele Jr., and Mitch Wand. Aneditors’ committee charged with producing this report wasalso formed at the end of 2003, consisting of Will Clinger,R. Kent Dybvig, Marc Feeley, Matthew Flatt, RichardKelsey, Manuel Serrano, and Mike Sperber, with Marc Fee-ley acting as Editor-in-Chief. Richard Kelsey resigned fromthe committee in April 2005, and was replaced by Antonvan Straaten. Marc Feeley and Manuel Serrano resignedfrom the committee in January 2006. Subsequently, thecharter was revised to reduce the size of the editors’ com-mittee to five and to replace the office of Editor-in-Chief bya Chair and a Project Editor [48]. R. Kent Dybvig servedas Chair, and Mike Sperber served as Project Editor. Partsof the report were posted as Scheme Requests for Imple-mentation (SRFIs) and discussed by the community beforebeing revised and finalized for the report [22, 12, 13, 21, 17].Jacob Matthews and Robby Findler wrote the operationalsemantics for the language core.We intend this report to belong to the entire Scheme com-munity, and so we grant permission to copy it in whole or inpart without fee. In particular, we encourage implementorsof Scheme to use this report as a starting point for manualsand other documentation, modifying it as necessary.
Acknowledgements
We would like to thank the following people for theirhelp: Alan Bawden, Michael Blair, Per Bothner, Thomas
Search History:
Searching...
Result 00 of 00
00 results for result for
  • p.
  • Notes
    Load more