Debian Codegraph @

contrib/GambitREPL/r5rs.html

raw
1 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html401/loose.dtd">
2 <html>
3 <!-- Created on September 13, 2011 by texi2html 1.82
4 texi2html was written by:
5 Lionel Cons <[email protected]> (original author)
6 Karl Berry <[email protected]>
7 Olaf Bachmann <[email protected]>
8 and many others.
9 Maintained by: Many creative people.
10 Send bugs and suggestions to <[email protected]>
11 -->
12 <head>
13 <meta name="description" content="Revised(5) Scheme">
14 <meta name="keywords" content="Revised(5) Scheme">
15 <meta name="resource-type" content="document">
16 <meta name="distribution" content="global">
17 <meta name="Generator" content="texi2html 1.82">
18 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
19
20 <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=0.25, maximum-scale=1.6">
21
22 <script>
23
24 function gestureStart() {
25 var metas = document.getElementsByTagName('meta');
26 for (var i=0; i<metas.length; i++) {
27 if (metas[i].name === "viewport") {
28 metas[i].content = "width=device-width, initial-scale=1.0, minimum-scale=0.25, maximum-scale=1.6";
29 }
30 }
31 }
32
33 document.addEventListener("gesturestart", gestureStart, false);
34
35 </script>
36
37 <style type="text/css">
38 <!--
39 body { -webkit-text-size-adjust:none }
40 a.summary-letter {text-decoration: none}
41 a:link {color: #0000e0}
42 a:visited {color: #0000e0}
43 blockquote.smallquotation {font-size: smaller}
44 pre.display {font-family: serif}
45 pre.format {font-size: smaller}
46 pre.menu-comment {font-family: serif}
47 pre.menu-preformatted {font-family: serif}
48 pre.smalldisplay {font-family: serif; font-size: smaller}
49 pre.smallexample {font-size: smaller}
50 pre.example {font-size: smaller}
51 pre.smallformat {font-family: serif; font-size: smaller}
52 pre.smalllisp {font-size: smaller}
53 span.roman {font-family:serif; font-weight:normal;}
54 span.sansserif {font-family:sans-serif; font-weight:normal;}
55 ul.toc {list-style: none}
56 -->
57 </style>
58 </head>
59 <body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000" onLoad="window.location='event:loaded'">
60
61 <a name="Top"></a><hr size="1"><br/><br/><br/>
62 <table cellpadding="1" cellspacing="1" border="0">
63 <tr><td valign="middle" align="left"><a href="#Top" title="Previous section in reading order"><img src="button-empty.png" border="0" alt="Back: Revised(5) Report on the Algorithmic Language Scheme" align="middle" width="32"></a></td>
64 <td valign="middle" align="left"><a href="#Contents" title="Next section in reading order"><img src="button-right.png" border="0" alt="Forward: Introduction" align="middle" width="32"></a></td>
65 <td valign="middle" align="left"> &nbsp; </td>
66 <td valign="middle" align="left"><a href="#Top" title="Beginning of this chapter or previous chapter"><img src="button-empty.png" border="0" alt="FastBack: Revised(5) Report on the Algorithmic Language Scheme" align="middle" width="32"></a></td>
67 <td valign="middle" align="left"><a href="#Top" title="Up section"><img src="button-empty.png" border="0" alt="Up: Revised(5) Report on the Algorithmic Language Scheme" align="middle" width="32"></a></td>
68 <td valign="middle" align="left"><a href="#Introduction" title="Next chapter"><img src="button-right-right.png" border="0" alt="FastForward: Introduction" align="middle" width="32"></a></td>
69 <td valign="middle" align="left"><a href="#Top" title="Cover (top) of document"><img src="button-up-arrow.png" border="0" alt="Top: Revised(5) Report on the Algorithmic Language Scheme" align="middle" width="32"></a></td>
70 <td valign="middle" align="left"><a href="#SEC_Contents" title="Table of contents"><img src="button-compass.png" border="0" alt="Contents: Table of Contents" align="middle" width="32"></a></td>
71 <td valign="middle" align="left"><a href="#Index" title="Index"><img src="button-abc.png" border="0" alt="Index: Alphabetic index of definitions of concepts, keywords, and procedures" align="middle" width="32"></a></td>
72 </tr></table>
73
74 <h1 class="settitle">Revised(5) Report on the Algorithmic Language Scheme</h1>
75
76 <br>
77
78 <center><a href="r5rs.pdf">[View PDF version]</a></center>
79
80 <blockquote><p>R<small>ICHARD</small> K<small>ELSEY</small>, W<small>ILLIAM</small> C<small>LINGER, AND</small> J<small>ONATHAN</small> R<small>EES</small> (<i>Editors</i>)
81 <br>
82 </p><table>
83 <tr><td width="25%">H. A<small>BELSON</small></td><td width="25%">R. K. D<small>YBVIG</small></td><td width="25%">C. T. H<small>AYNES</small></td><td width="25%">G. J. R<small>OZAS</small></td></tr>
84 <tr><td width="25%">N. I. A<small>DAMS IV</small></td><td width="25%">D. P. F<small>RIEDMAN</small></td><td width="25%">E. K<small>OHLBECKER</small></td><td width="25%">G. L. S<small>TEELE</small> J<small>R</small>.</td></tr>
85 <tr><td width="25%">D. H. B<small>ARTLEY</small></td><td width="25%">R. H<small>ALSTEAD</small></td><td width="25%">D. O<small>XLEY</small></td><td width="25%">G. J. S<small>USSMAN</small></td></tr>
86 <tr><td width="25%">G. B<small>ROOKS</small></td><td width="25%">C. H<small>ANSON</small></td><td width="25%">K. M. P<small>ITMAN</small></td><td width="25%">M. W<small>AND</small></td></tr>
87 <tr><td width="25%"></td></tr>
88 </table>
89 </blockquote>
90
91 <p><i>Dedicated to the Memory of Robert Hieb</i>
92 </p>
93
94
95 <a name="Summary"></a>
96 <h1 class="majorheading">Summary</h1>
97
98
99 <p>The report gives a defining description of the programming language
100 Scheme. Scheme is a statically scoped and properly tail-recursive
101 dialect of the Lisp programming language invented by Guy Lewis
102 Steele Jr. and Gerald Jay Sussman. It was designed to have an
103 exceptionally clear and simple semantics and few different ways to
104 form expressions. A wide variety of programming paradigms, including
105 imperative, functional, and message passing styles, find convenient
106 expression in Scheme.
107 </p>
108 <p>The introduction offers a brief history of the language and of
109 the report.
110 </p>
111 <p>The first three chapters present the fundamental ideas of the
112 language and describe the notational conventions used for describing the
113 language and for writing programs in the language.
114 </p>
115 <p>Chapters <a href="#Expressions">Expressions</a> and <a href="#Program-structure">Program structure</a> describe
116 the syntax and semantics of expressions, programs, and definitions.
117 </p>
118 <p>Chapter <a href="#Standard-procedures">Standard procedures</a> describes Scheme's built-in
119 procedures, which include all of the language's data manipulation and
120 input/output primitives.
121 </p>
122 <p>Chapter <a href="#Formal-syntax-and-semantics">Formal syntax and semantics</a> provides a formal syntax for Scheme
123 written in extended BNF, along with a formal denotational semantics.
124 An example of the use of the language follows the formal syntax and
125 semantics.
126 </p>
127 <p>The report concludes with a list of references and an
128 alphabetic index.
129 </p>
130
131
132
133
134
135
136
137
138 <a name="Contents"></a><hr size="1"><br/><br/><br/>
139 <table cellpadding="1" cellspacing="1" border="0">
140 <tr><td valign="middle" align="left"><a href="#Top" title="Previous section in reading order"><img src="button-left.png" border="0" alt="Back: Revised(5) Report on the Algorithmic Language Scheme" align="middle" width="32"></a></td>
141 <td valign="middle" align="left"><a href="#Introduction" title="Next section in reading order"><img src="button-right.png" border="0" alt="Forward: Introduction" align="middle" width="32"></a></td>
142 <td valign="middle" align="left"> &nbsp; </td>
143 <td valign="middle" align="left"><a href="#Top" title="Beginning of this chapter or previous chapter"><img src="button-left-left.png" border="0" alt="FastBack: Revised(5) Report on the Algorithmic Language Scheme" align="middle" width="32"></a></td>
144 <td valign="middle" align="left"><a href="#Top" title="Up section"><img src="button-up.png" border="0" alt="Up: Revised(5) Report on the Algorithmic Language Scheme" align="middle" width="32"></a></td>
145 <td valign="middle" align="left"><a href="#Introduction" title="Next chapter"><img src="button-right-right.png" border="0" alt="FastForward: Introduction" align="middle" width="32"></a></td>
146 <td valign="middle" align="left"><a href="#Top" title="Cover (top) of document"><img src="button-up-arrow.png" border="0" alt="Top: Revised(5) Report on the Algorithmic Language Scheme" align="middle" width="32"></a></td>
147 <td valign="middle" align="left"><a href="#SEC_Contents" title="Table of contents"><img src="button-compass.png" border="0" alt="Contents: Table of Contents" align="middle" width="32"></a></td>
148 <td valign="middle" align="left"><a href="#Index" title="Index"><img src="button-abc.png" border="0" alt="Index: Alphabetic index of definitions of concepts, keywords, and procedures" align="middle" width="32"></a></td>
149 </tr></table>
150 <h1 class="unnumbered">Contents</h1>
151
152 <table class="menu" border="0" cellspacing="0">
153 <tr><td align="left" valign="top"><a href="#Introduction">Introduction</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
154 </td></tr>
155 <tr><td align="left" valign="top"><a href="#Overview-of-Scheme">1. Overview of Scheme</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
156 </td></tr>
157 <tr><td align="left" valign="top"><a href="#Lexical-conventions">2. Lexical conventions</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
158 </td></tr>
159 <tr><td align="left" valign="top"><a href="#Basic-concepts">3. Basic concepts</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
160 </td></tr>
161 <tr><td align="left" valign="top"><a href="#Expressions">4. Expressions</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
162 </td></tr>
163 <tr><td align="left" valign="top"><a href="#Program-structure">5. Program structure</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
164 </td></tr>
165 <tr><td align="left" valign="top"><a href="#Standard-procedures">6. Standard procedures</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
166 </td></tr>
167 <tr><td align="left" valign="top"><a href="#Formal-syntax-and-semantics">7. Formal syntax and semantics</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
168 </td></tr>
169 <tr><td align="left" valign="top"><a href="#Notes">Notes</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
170 </td></tr>
171 <tr><td align="left" valign="top"><a href="#Additional-material">Additional material</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
172 </td></tr>
173 <tr><td align="left" valign="top"><a href="#Example">Example</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
174 </td></tr>
175 <tr><td align="left" valign="top"><a href="#Bibliography">Bibliography</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
176 </td></tr>
177 <tr><td align="left" valign="top"><a href="#Index">Alphabetic index of definitions of concepts, keywords, and procedures</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
178 </td></tr>
179 </table>
180
181
182
183
184
185
186
187
188
189 <a name="Introduction"></a><hr size="1"><br/><br/><br/>
190 <table cellpadding="1" cellspacing="1" border="0">
191 <tr><td valign="middle" align="left"><a href="#Contents" title="Previous section in reading order"><img src="button-left.png" border="0" alt="Back: Contents" align="middle" width="32"></a></td>
192 <td valign="middle" align="left"><a href="#Background" title="Next section in reading order"><img src="button-right.png" border="0" alt="Forward: Background" align="middle" width="32"></a></td>
193 <td valign="middle" align="left"> &nbsp; </td>
194 <td valign="middle" align="left"><a href="#Contents" title="Beginning of this chapter or previous chapter"><img src="button-left-left.png" border="0" alt="FastBack: Contents" align="middle" width="32"></a></td>
195 <td valign="middle" align="left"><a href="#Top" title="Up section"><img src="button-up.png" border="0" alt="Up: Revised(5) Report on the Algorithmic Language Scheme" align="middle" width="32"></a></td>
196 <td valign="middle" align="left"><a href="#Overview-of-Scheme" title="Next chapter"><img src="button-right-right.png" border="0" alt="FastForward: 1. Overview of Scheme" align="middle" width="32"></a></td>
197 <td valign="middle" align="left"><a href="#Top" title="Cover (top) of document"><img src="button-up-arrow.png" border="0" alt="Top: Revised(5) Report on the Algorithmic Language Scheme" align="middle" width="32"></a></td>
198 <td valign="middle" align="left"><a href="#SEC_Contents" title="Table of contents"><img src="button-compass.png" border="0" alt="Contents: Table of Contents" align="middle" width="32"></a></td>
199 <td valign="middle" align="left"><a href="#Index" title="Index"><img src="button-abc.png" border="0" alt="Index: Alphabetic index of definitions of concepts, keywords, and procedures" align="middle" width="32"></a></td>
200 </tr></table>
201 <a name="Introduction-1"></a>
202 <h1 class="unnumbered">Introduction</h1>
203
204 <table class="menu" border="0" cellspacing="0">
205 <tr><td align="left" valign="top"><a href="#Background">Background</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
206 </td></tr>
207 <tr><td align="left" valign="top"><a href="#Acknowledgements">Acknowledgements</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
208 </td></tr>
209 </table>
210
211
212
213
214 <p>Programming languages should be designed not by piling feature on top of
215 feature, but by removing the weaknesses and restrictions that make additional
216 features appear necessary. Scheme demonstrates that a very small number
217 of rules for forming expressions, with no restrictions on how they are
218 composed, suffice to form a practical and efficient programming language
219 that is flexible enough to support most of the major programming
220 paradigms in use today.
221 </p>
222 <p>Scheme
223 was one of the first programming languages to incorporate first class
224 procedures as in the lambda calculus, thereby proving the usefulness of
225 static scope rules and block structure in a dynamically typed language.
226 Scheme was the first major dialect of Lisp to distinguish procedures
227 from lambda expressions and symbols, to use a single lexical
228 environment for all variables, and to evaluate the operator position
229 of a procedure call in the same way as an operand position. By relying
230 entirely on procedure calls to express iteration, Scheme emphasized the
231 fact that tail-recursive procedure calls are essentially goto's that
232 pass arguments. Scheme was the first widely used programming language to
233 embrace first class escape procedures, from which all previously known
234 sequential control structures can be synthesized. A subsequent
235 version of Scheme introduced the concept of exact and inexact numbers,
236 an extension of Common Lisp's generic arithmetic.
237 More recently, Scheme became the first programming language to support
238 hygienic macros, which permit the syntax of a block-structured language
239 to be extended in a consistent and reliable manner.
240 </p>
241
242
243 <a name="Background"></a><hr size="1"><br/><br/><br/>
244 <table cellpadding="1" cellspacing="1" border="0">
245 <tr><td valign="middle" align="left"><a href="#Introduction" title="Previous section in reading order"><img src="button-left.png" border="0" alt="Back: Introduction" align="middle" width="32"></a></td>
246 <td valign="middle" align="left"><a href="#Acknowledgements" title="Next section in reading order"><img src="button-right.png" border="0" alt="Forward: Acknowledgements" align="middle" width="32"></a></td>
247 <td valign="middle" align="left"> &nbsp; </td>
248 <td valign="middle" align="left"><a href="#Introduction" title="Beginning of this chapter or previous chapter"><img src="button-left-left.png" border="0" alt="FastBack: Introduction" align="middle" width="32"></a></td>
249 <td valign="middle" align="left"><a href="#Introduction" title="Up section"><img src="button-up.png" border="0" alt="Up: Introduction" align="middle" width="32"></a></td>
250 <td valign="middle" align="left"><a href="#Overview-of-Scheme" title="Next chapter"><img src="button-right-right.png" border="0" alt="FastForward: 1. Overview of Scheme" align="middle" width="32"></a></td>
251 <td valign="middle" align="left"><a href="#Top" title="Cover (top) of document"><img src="button-up-arrow.png" border="0" alt="Top: Revised(5) Report on the Algorithmic Language Scheme" align="middle" width="32"></a></td>
252 <td valign="middle" align="left"><a href="#SEC_Contents" title="Table of contents"><img src="button-compass.png" border="0" alt="Contents: Table of Contents" align="middle" width="32"></a></td>
253 <td valign="middle" align="left"><a href="#Index" title="Index"><img src="button-abc.png" border="0" alt="Index: Alphabetic index of definitions of concepts, keywords, and procedures" align="middle" width="32"></a></td>
254 </tr></table>
255 <a name="Background-1"></a>
256 <h2 class="unnumberedsec">Background</h2>
257
258
259 <p>The first description of Scheme was written in
260 1975 [Scheme75]. A revised report [Scheme78]
261 appeared in 1978, which described the evolution
262 of the language as its MIT implementation was upgraded to support an
263 innovative compiler [Rabbit]. Three distinct projects began in
264 1981 and 1982 to use variants of Scheme for courses at MIT, Yale, and
265 Indiana University [Rees82], [MITScheme], [Scheme311]. An introductory
266 computer science textbook using Scheme was published in
267 1984 [SICP].
268 </p>
269 <p>As Scheme became more widespread,
270 local dialects began to diverge until students and researchers
271 occasionally found it difficult to understand code written at other
272 sites.
273 Fifteen representatives of the major implementations of Scheme therefore
274 met in October 1984 to work toward a better and more widely accepted
275 standard for Scheme.
276 </p>
277 <p>Their report [RRRS]
278 was published at MIT and Indiana University in the summer of 1985.
279 Further revision took place in the spring of 1986 [R3RS],
280 and in the spring of 1988 [R4RS].
281 The present report reflects further revisions agreed upon in a meeting
282 at Xerox PARC in June 1992.
283 </p>
284
285
286
287
288 <br>
289 <br>
290 <br>
291
292 <p>We intend this report to belong to the entire Scheme community, and so
293 we grant permission to copy it in whole or in part without fee. In
294 particular, we encourage implementors of Scheme to use this report as
295 a starting point for manuals and other documentation, modifying it as
296 necessary.
297 </p>
298
299
300
301 <a name="Acknowledgements"></a><hr size="1"><br/><br/><br/>
302 <table cellpadding="1" cellspacing="1" border="0">
303 <tr><td valign="middle" align="left"><a href="#Background" title="Previous section in reading order"><img src="button-left.png" border="0" alt="Back: Background" align="middle" width="32"></a></td>
304 <td valign="middle" align="left"><a href="#Overview-of-Scheme" title="Next section in reading order"><img src="button-right.png" border="0" alt="Forward: 1. Overview of Scheme" align="middle" width="32"></a></td>
305 <td valign="middle" align="left"> &nbsp; </td>
306 <td valign="middle" align="left"><a href="#Introduction" title="Beginning of this chapter or previous chapter"><img src="button-left-left.png" border="0" alt="FastBack: Introduction" align="middle" width="32"></a></td>
307 <td valign="middle" align="left"><a href="#Introduction" title="Up section"><img src="button-up.png" border="0" alt="Up: Introduction" align="middle" width="32"></a></td>
308 <td valign="middle" align="left"><a href="#Overview-of-Scheme" title="Next chapter"><img src="button-right-right.png" border="0" alt="FastForward: 1. Overview of Scheme" align="middle" width="32"></a></td>
309 <td valign="middle" align="left"><a href="#Top" title="Cover (top) of document"><img src="button-up-arrow.png" border="0" alt="Top: Revised(5) Report on the Algorithmic Language Scheme" align="middle" width="32"></a></td>
310 <td valign="middle" align="left"><a href="#SEC_Contents" title="Table of contents"><img src="button-compass.png" border="0" alt="Contents: Table of Contents" align="middle" width="32"></a></td>
311 <td valign="middle" align="left"><a href="#Index" title="Index"><img src="button-abc.png" border="0" alt="Index: Alphabetic index of definitions of concepts, keywords, and procedures" align="middle" width="32"></a></td>
312 </tr></table>
313 <a name="Acknowledgements-1"></a>
314 <h2 class="unnumberedsec">Acknowledgements</h2>
315
316
317 <p>We would like to thank the following people for their help: Alan Bawden, Michael
318 Blair, George Carrette, Andy Cromarty, Pavel Curtis, Jeff Dalton, Olivier Danvy,
319 Ken Dickey, Bruce Duba, Marc Feeley,
320 Andy Freeman, Richard Gabriel, Yekta G&quot;ursel, Ken Haase, Robert
321 Hieb, Paul Hudak, Morry Katz, Chris Lindblad, Mark Meyer, Jim Miller, Jim Philbin,
322 John Ramsdell, Mike Shaff, Jonathan Shapiro, Julie Sussman,
323 Perry Wagle, Daniel Weise, Henry Wu, and Ozan Yigit.
324 We thank Carol Fessenden, Daniel
325 Friedman, and Christopher Haynes for permission to use text from the Scheme 311
326 version 4 reference manual. We thank Texas Instruments, Inc. for permission to
327 use text from the <em>TI Scheme Language Reference Manual</em>[TImanual85].
328 We gladly acknowledge the influence of manuals for MIT Scheme[MITScheme],
329 T[Rees84], Scheme 84[Scheme84],Common Lisp[CLtL],
330 and Algol 60[Naur63].
331 </p>
332 <p>We also thank Betty Dexter for the extreme effort she put into
333 setting this report in TeX, and Donald Knuth for designing the program
334 that caused her troubles.
335 </p>
336 <p>The Artificial Intelligence Laboratory of the
337 Massachusetts Institute of Technology, the Computer Science
338 Department of Indiana University, the Computer and Information
339 Sciences Department of the University of Oregon, and the NEC Research
340 Institute supported the preparation of this report. Support for the MIT
341 work was provided in part by
342 the Advanced Research Projects Agency of the Department of Defense under Office
343 of Naval Research contract N00014-80-C-0505. Support for the Indiana
344 University work was provided by NSF grants NCS 83-04567 and NCS
345 83-03325.
346 </p>
347
348
349
350 <br>
351 <br>
352
353
354
355 <a name="Overview-of-Scheme"></a><hr size="1"><br/><br/><br/>
356 <table cellpadding="1" cellspacing="1" border="0">
357 <tr><td valign="middle" align="left"><a href="#Acknowledgements" title="Previous section in reading order"><img src="button-left.png" border="0" alt="Back: Acknowledgements" align="middle" width="32"></a></td>
358 <td valign="middle" align="left"><a href="#Semantics" title="Next section in reading order"><img src="button-right.png" border="0" alt="Forward: 1.1 Semantics" align="middle" width="32"></a></td>
359 <td valign="middle" align="left"> &nbsp; </td>
360 <td valign="middle" align="left"><a href="#Introduction" title="Beginning of this chapter or previous chapter"><img src="button-left-left.png" border="0" alt="FastBack: Introduction" align="middle" width="32"></a></td>
361 <td valign="middle" align="left"><a href="#Top" title="Up section"><img src="button-up.png" border="0" alt="Up: Revised(5) Report on the Algorithmic Language Scheme" align="middle" width="32"></a></td>
362 <td valign="middle" align="left"><a href="#Lexical-conventions" title="Next chapter"><img src="button-right-right.png" border="0" alt="FastForward: 2. Lexical conventions" align="middle" width="32"></a></td>
363 <td valign="middle" align="left"><a href="#Top" title="Cover (top) of document"><img src="button-up-arrow.png" border="0" alt="Top: Revised(5) Report on the Algorithmic Language Scheme" align="middle" width="32"></a></td>
364 <td valign="middle" align="left"><a href="#SEC_Contents" title="Table of contents"><img src="button-compass.png" border="0" alt="Contents: Table of Contents" align="middle" width="32"></a></td>
365 <td valign="middle" align="left"><a href="#Index" title="Index"><img src="button-abc.png" border="0" alt="Index: Alphabetic index of definitions of concepts, keywords, and procedures" align="middle" width="32"></a></td>
366 </tr></table>
367 <a name="Overview-of-Scheme-1"></a>
368 <h1 class="chapter">1. Overview of Scheme</h1>
369
370 <table class="menu" border="0" cellspacing="0">
371 <tr><td align="left" valign="top"><a href="#Semantics">1.1 Semantics</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
372 </td></tr>
373 <tr><td align="left" valign="top"><a href="#Syntax">1.2 Syntax</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
374 </td></tr>
375 <tr><td align="left" valign="top"><a href="#Notation-and-terminology">1.3 Notation and terminology</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
376 </td></tr>
377 </table>
378
379
380 <a name="Semantics"></a><hr size="1"><br/><br/><br/>
381 <table cellpadding="1" cellspacing="1" border="0">
382 <tr><td valign="middle" align="left"><a href="#Overview-of-Scheme" title="Previous section in reading order"><img src="button-left.png" border="0" alt="Back: 1. Overview of Scheme" align="middle" width="32"></a></td>
383 <td valign="middle" align="left"><a href="#Syntax" title="Next section in reading order"><img src="button-right.png" border="0" alt="Forward: 1.2 Syntax" align="middle" width="32"></a></td>
384 <td valign="middle" align="left"> &nbsp; </td>
385 <td valign="middle" align="left"><a href="#Overview-of-Scheme" title="Beginning of this chapter or previous chapter"><img src="button-left-left.png" border="0" alt="FastBack: 1. Overview of Scheme" align="middle" width="32"></a></td>
386 <td valign="middle" align="left"><a href="#Overview-of-Scheme" title="Up section"><img src="button-up.png" border="0" alt="Up: 1. Overview of Scheme" align="middle" width="32"></a></td>
387 <td valign="middle" align="left"><a href="#Lexical-conventions" title="Next chapter"><img src="button-right-right.png" border="0" alt="FastForward: 2. Lexical conventions" align="middle" width="32"></a></td>
388 <td valign="middle" align="left"><a href="#Top" title="Cover (top) of document"><img src="button-up-arrow.png" border="0" alt="Top: Revised(5) Report on the Algorithmic Language Scheme" align="middle" width="32"></a></td>
389 <td valign="middle" align="left"><a href="#SEC_Contents" title="Table of contents"><img src="button-compass.png" border="0" alt="Contents: Table of Contents" align="middle" width="32"></a></td>
390 <td valign="middle" align="left"><a href="#Index" title="Index"><img src="button-abc.png" border="0" alt="Index: Alphabetic index of definitions of concepts, keywords, and procedures" align="middle" width="32"></a></td>
391 </tr></table>
392 <a name="Semantics-1"></a>
393 <h2 class="section">1.1 Semantics</h2>
394
395
396
397 <p>This section gives an overview of Scheme's semantics. A
398 detailed informal semantics is the subject of
399 chapters <a href="#Basic-concepts">Basic concepts</a> through <a href="#Standard-procedures">Standard procedures</a>. For reference
400 purposes, section <a href="#Formal-semantics">Formal semantics</a> provides a formal
401 semantics of Scheme.
402 </p>
403 <p>Following Algol, Scheme is a statically scoped programming
404 language. Each use of a variable is associated with a lexically
405 apparent binding of that variable.
406 </p>
407 <p>Scheme has latent as opposed to manifest types. Types
408 are associated with values (also called objects) rather than
409 <a name="index-object"></a>
410 with variables. (Some authors refer to languages with latent types as
411 weakly typed or dynamically typed languages.) Other languages with
412 latent types are APL, Snobol, and other dialects of Lisp. Languages
413 with manifest types (sometimes referred to as strongly typed or
414 statically typed languages) include Algol 60, Pascal, and C.
415 </p>
416 <p>All objects created in the course of a Scheme computation, including
417 procedures and continuations, have unlimited extent.
418 No Scheme object is ever destroyed. The reason that
419 implementations of Scheme do not (usually!) run out of storage is that
420 they are permitted to reclaim the storage occupied by an object if
421 they can prove that the object cannot possibly matter to any future
422 computation. Other languages in which most objects have unlimited
423 extent include APL and other Lisp dialects.
424 </p>
425 <p>Implementations of Scheme are required to be properly tail-recursive.
426 This allows the execution of an iterative computation in constant space,
427 even if the iterative computation is described by a syntactically
428 recursive procedure. Thus with a properly tail-recursive implementation,
429 iteration can be expressed using the ordinary procedure-call
430 mechanics, so that special iteration constructs are useful only as
431 syntactic sugar. See section <a href="#Proper-tail-recursion">Proper tail recursion</a>.
432 </p>
433 <p>Scheme procedures are objects in their own right. Procedures can be
434 created dynamically, stored in data structures, returned as results of
435 procedures, and so on. Other languages with these properties include
436 Common Lisp and ML.
437 </p>
438
439 <p>One distinguishing feature of Scheme is that continuations, which
440 in most other languages only operate behind the scenes, also have
441 &ldquo;first-class&rdquo; status. Continuations are useful for implementing a
442 wide variety of advanced control constructs, including non-local exits,
443 backtracking, and coroutines. See section <a href="#Control-features">Control features</a>.
444 </p>
445 <p>Arguments to Scheme procedures are always passed by value, which
446 means that the actual argument expressions are evaluated before the
447 procedure gains control, whether the procedure needs the result of the
448 evaluation or not. ML, C, and APL are three other languages that always
449 pass arguments by value.
450 This is distinct from the lazy-evaluation semantics of Haskell,
451 or the call-by-name semantics of Algol 60, where an argument
452 expression is not evaluated unless its value is needed by the
453 procedure.
454 </p>
455
456
457 <p>Scheme's model of arithmetic is designed to remain as independent as
458 possible of the particular ways in which numbers are represented within a
459 computer. In Scheme, every integer is a rational number, every rational is a
460 real, and every real is a complex number. Thus the distinction between integer
461 and real arithmetic, so important to many programming languages, does not
462 appear in Scheme. In its place is a distinction between exact arithmetic,
463 which corresponds to the mathematical ideal, and inexact arithmetic on
464 approximations. As in Common Lisp, exact arithmetic is not limited to
465 integers.
466 </p>
467 <a name="Syntax"></a><hr size="1"><br/><br/><br/>
468 <table cellpadding="1" cellspacing="1" border="0">
469 <tr><td valign="middle" align="left"><a href="#Semantics" title="Previous section in reading order"><img src="button-left.png" border="0" alt="Back: 1.1 Semantics" align="middle" width="32"></a></td>
470 <td valign="middle" align="left"><a href="#Notation-and-terminology" title="Next section in reading order"><img src="button-right.png" border="0" alt="Forward: 1.3 Notation and terminology" align="middle" width="32"></a></td>
471 <td valign="middle" align="left"> &nbsp; </td>
472 <td valign="middle" align="left"><a href="#Overview-of-Scheme" title="Beginning of this chapter or previous chapter"><img src="button-left-left.png" border="0" alt="FastBack: 1. Overview of Scheme" align="middle" width="32"></a></td>
473 <td valign="middle" align="left"><a href="#Overview-of-Scheme" title="Up section"><img src="button-up.png" border="0" alt="Up: 1. Overview of Scheme" align="middle" width="32"></a></td>
474 <td valign="middle" align="left"><a href="#Lexical-conventions" title="Next chapter"><img src="button-right-right.png" border="0" alt="FastForward: 2. Lexical conventions" align="middle" width="32"></a></td>
475 <td valign="middle" align="left"><a href="#Top" title="Cover (top) of document"><img src="button-up-arrow.png" border="0" alt="Top: Revised(5) Report on the Algorithmic Language Scheme" align="middle" width="32"></a></td>
476 <td valign="middle" align="left"><a href="#SEC_Contents" title="Table of contents"><img src="button-compass.png" border="0" alt="Contents: Table of Contents" align="middle" width="32"></a></td>
477 <td valign="middle" align="left"><a href="#Index" title="Index"><img src="button-abc.png" border="0" alt="Index: Alphabetic index of definitions of concepts, keywords, and procedures" align="middle" width="32"></a></td>
478 </tr></table>
479 <a name="Syntax-1"></a>
480 <h2 class="section">1.2 Syntax</h2>
481
482
483 <p>Scheme, like most dialects of Lisp, employs a fully parenthesized prefix
484 notation for programs and (other) data; the grammar of Scheme generates a
485 sublanguage of the language used for data. An important
486 consequence of this simple, uniform representation is the susceptibility of
487 Scheme programs and data to uniform treatment by other Scheme programs.
488 For example, the <samp>eval</samp> procedure evaluates a Scheme program expressed
489 as data.
490 </p>
491 <p>The <samp>read</samp> procedure performs syntactic as well as lexical decomposition of
492 the data it reads. The <samp>read</samp> procedure parses its input as data
493 (section see section <a href="#External-representation">External representations</a>), not as program.
494 </p>
495 <p>The formal syntax of Scheme is described in section <a href="#Formal-syntax">Formal syntax</a>.
496 </p>
497
498 <a name="Notation-and-terminology"></a><hr size="1"><br/><br/><br/>
499 <table cellpadding="1" cellspacing="1" border="0">
500 <tr><td valign="middle" align="left"><a href="#Syntax" title="Previous section in reading order"><img src="button-left.png" border="0" alt="Back: 1.2 Syntax" align="middle" width="32"></a></td>
501 <td valign="middle" align="left"><a href="#Primitive_003b-library_003b-and-optional-features" title="Next section in reading order"><img src="button-right.png" border="0" alt="Forward: 1.3.1 Primitive; library; and optional features" align="middle" width="32"></a></td>
502 <td valign="middle" align="left"> &nbsp; </td>
503 <td valign="middle" align="left"><a href="#Overview-of-Scheme" title="Beginning of this chapter or previous chapter"><img src="button-left-left.png" border="0" alt="FastBack: 1. Overview of Scheme" align="middle" width="32"></a></td>
504 <td valign="middle" align="left"><a href="#Overview-of-Scheme" title="Up section"><img src="button-up.png" border="0" alt="Up: 1. Overview of Scheme" align="middle" width="32"></a></td>
505 <td valign="middle" align="left"><a href="#Lexical-conventions" title="Next chapter"><img src="button-right-right.png" border="0" alt="FastForward: 2. Lexical conventions" align="middle" width="32"></a></td>
506 <td valign="middle" align="left"><a href="#Top" title="Cover (top) of document"><img src="button-up-arrow.png" border="0" alt="Top: Revised(5) Report on the Algorithmic Language Scheme" align="middle" width="32"></a></td>
507 <td valign="middle" align="left"><a href="#SEC_Contents" title="Table of contents"><img src="button-compass.png" border="0" alt="Contents: Table of Contents" align="middle" width="32"></a></td>
508 <td valign="middle" align="left"><a href="#Index" title="Index"><img src="button-abc.png" border="0" alt="Index: Alphabetic index of definitions of concepts, keywords, and procedures" align="middle" width="32"></a></td>
509 </tr></table>
510 <a name="Notation-and-terminology-1"></a>
511 <h2 class="section">1.3 Notation and terminology</h2>
512
513 <table class="menu" border="0" cellspacing="0">
514 <tr><td align="left" valign="top"><a href="#Primitive_003b-library_003b-and-optional-features">1.3.1 Primitive; library; and optional features</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
515 </td></tr>
516 <tr><td align="left" valign="top"><a href="#Error-situations-and-unspecified-behavior">1.3.2 Error situations and unspecified behavior</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
517 </td></tr>
518 <tr><td align="left" valign="top"><a href="#Entry-format">1.3.3 Entry format</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
519 </td></tr>
520 <tr><td align="left" valign="top"><a href="#Evaluation-examples">1.3.4 Evaluation examples</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
521 </td></tr>
522 <tr><td align="left" valign="top"><a href="#Naming-conventions">1.3.5 Naming conventions</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
523 </td></tr>
524 </table>
525
526
527
528 <a name="Primitive_003b-library_003b-and-optional-features"></a><hr size="1"><br/><br/><br/>
529 <table cellpadding="1" cellspacing="1" border="0">
530 <tr><td valign="middle" align="left"><a href="#Notation-and-terminology" title="Previous section in reading order"><img src="button-left.png" border="0" alt="Back: 1.3 Notation and terminology" align="middle" width="32"></a></td>
531 <td valign="middle" align="left"><a href="#Error-situations-and-unspecified-behavior" title="Next section in reading order"><img src="button-right.png" border="0" alt="Forward: 1.3.2 Error situations and unspecified behavior" align="middle" width="32"></a></td>
532 <td valign="middle" align="left"> &nbsp; </td>
533 <td valign="middle" align="left"><a href="#Overview-of-Scheme" title="Beginning of this chapter or previous chapter"><img src="button-left-left.png" border="0" alt="FastBack: 1. Overview of Scheme" align="middle" width="32"></a></td>
534 <td valign="middle" align="left"><a href="#Notation-and-terminology" title="Up section"><img src="button-up.png" border="0" alt="Up: 1.3 Notation and terminology" align="middle" width="32"></a></td>
535 <td valign="middle" align="left"><a href="#Lexical-conventions" title="Next chapter"><img src="button-right-right.png" border="0" alt="FastForward: 2. Lexical conventions" align="middle" width="32"></a></td>
536 <td valign="middle" align="left"><a href="#Top" title="Cover (top) of document"><img src="button-up-arrow.png" border="0" alt="Top: Revised(5) Report on the Algorithmic Language Scheme" align="middle" width="32"></a></td>
537 <td valign="middle" align="left"><a href="#SEC_Contents" title="Table of contents"><img src="button-compass.png" border="0" alt="Contents: Table of Contents" align="middle" width="32"></a></td>
538 <td valign="middle" align="left"><a href="#Index" title="Index"><img src="button-abc.png" border="0" alt="Index: Alphabetic index of definitions of concepts, keywords, and procedures" align="middle" width="32"></a></td>
539 </tr></table>
540 <a name="Primitive_003b-library_003b-and-optional-features-1"></a>
541 <h3 class="subsection">1.3.1 Primitive; library; and optional features</h3>
542
543
544
545 <p>It is required that every implementation of Scheme support all
546 features that are not marked as being <em>optional</em>. Implementations are
547 <a name="index-optional"></a>
548 free to omit optional features of Scheme or to add extensions,
549 provided the extensions are not in conflict with the language reported
550 here. In particular, implementations must support portable code by
551 providing a syntactic mode that preempts no lexical conventions of this
552 report.
553 </p>
554 <p>To aid in understanding and implementing Scheme, some features are marked
555 as <em>library</em>. These can be easily implemented in terms of the other,
556 <a name="index-library"></a>
557 primitive, features. They are redundant in the strict sense of
558 the word, but they capture common patterns of usage, and are therefore
559 provided as convenient abbreviations.
560 </p>
561 <a name="Error-situations-and-unspecified-behavior"></a><hr size="1"><br/><br/><br/>
562 <table cellpadding="1" cellspacing="1" border="0">
563 <tr><td valign="middle" align="left"><a href="#Primitive_003b-library_003b-and-optional-features" title="Previous section in reading order"><img src="button-left.png" border="0" alt="Back: 1.3.1 Primitive; library; and optional features" align="middle" width="32"></a></td>
564 <td valign="middle" align="left"><a href="#Entry-format" title="Next section in reading order"><img src="button-right.png" border="0" alt="Forward: 1.3.3 Entry format" align="middle" width="32"></a></td>
565 <td valign="middle" align="left"> &nbsp; </td>
566 <td valign="middle" align="left"><a href="#Overview-of-Scheme" title="Beginning of this chapter or previous chapter"><img src="button-left-left.png" border="0" alt="FastBack: 1. Overview of Scheme" align="middle" width="32"></a></td>
567 <td valign="middle" align="left"><a href="#Notation-and-terminology" title="Up section"><img src="button-up.png" border="0" alt="Up: 1.3 Notation and terminology" align="middle" width="32"></a></td>
568 <td valign="middle" align="left"><a href="#Lexical-conventions" title="Next chapter"><img src="button-right-right.png" border="0" alt="FastForward: 2. Lexical conventions" align="middle" width="32"></a></td>
569 <td valign="middle" align="left"><a href="#Top" title="Cover (top) of document"><img src="button-up-arrow.png" border="0" alt="Top: Revised(5) Report on the Algorithmic Language Scheme" align="middle" width="32"></a></td>
570 <td valign="middle" align="left"><a href="#SEC_Contents" title="Table of contents"><img src="button-compass.png" border="0" alt="Contents: Table of Contents" align="middle" width="32"></a></td>
571 <td valign="middle" align="left"><a href="#Index" title="Index"><img src="button-abc.png" border="0" alt="Index: Alphabetic index of definitions of concepts, keywords, and procedures" align="middle" width="32"></a></td>
572 </tr></table>
573 <a name="Error-situations-and-unspecified-behavior-1"></a>
574 <h3 class="subsection">1.3.2 Error situations and unspecified behavior</h3>
575
576
577
578 <a name="index-error"></a>
579 <p>When speaking of an error situation, this report uses the phrase &ldquo;an
580 error is signalled&rdquo; to indicate that implementations must detect and
581 report the error. If such wording does not appear in the discussion of
582 an error, then implementations are not required to detect or report the
583 error, though they are encouraged to do so. An error situation that
584 implementations are not required to detect is usually referred to simply
585 as &ldquo;an error.&rdquo;
586 </p>
587 <p>For example, it is an error for a procedure to be passed an argument that
588 the procedure is not explicitly specified to handle, even though such
589 domain errors are seldom mentioned in this report. Implementations may
590 extend a procedure's domain of definition to include such arguments.
591 </p>
592 <p>This report uses the phrase &ldquo;may report a violation of an
593 implementation restriction&rdquo; to indicate circumstances under which an
594 implementation is permitted to report that it is unable to continue
595 execution of a correct program because of some restriction imposed by the
596 implementation. Implementation restrictions are of course discouraged,
597 but implementations are encouraged to report violations of implementation
598 restrictions.
599 <a name="index-implementation-restriction"></a>
600 </p>
601 <p>For example, an implementation may report a violation of an
602 implementation restriction if it does not have enough storage to run a
603 program.
604 </p>
605 <p>If the value of an expression is said to be &ldquo;unspecified,&rdquo; then
606 the expression must evaluate to some object without signalling an error,
607 but the value depends on the implementation; this report explicitly does
608 not say what value should be returned.
609 <a name="index-unspecified"></a>
610 </p>
611
612
613
614
615
616 <a name="Entry-format"></a><hr size="1"><br/><br/><br/>
617 <table cellpadding="1" cellspacing="1" border="0">
618 <tr><td valign="middle" align="left"><a href="#Error-situations-and-unspecified-behavior" title="Previous section in reading order"><img src="button-left.png" border="0" alt="Back: 1.3.2 Error situations and unspecified behavior" align="middle" width="32"></a></td>
619 <td valign="middle" align="left"><a href="#Evaluation-examples" title="Next section in reading order"><img src="button-right.png" border="0" alt="Forward: 1.3.4 Evaluation examples" align="middle" width="32"></a></td>
620 <td valign="middle" align="left"> &nbsp; </td>
621 <td valign="middle" align="left"><a href="#Overview-of-Scheme" title="Beginning of this chapter or previous chapter"><img src="button-left-left.png" border="0" alt="FastBack: 1. Overview of Scheme" align="middle" width="32"></a></td>
622 <td valign="middle" align="left"><a href="#Notation-and-terminology" title="Up section"><img src="button-up.png" border="0" alt="Up: 1.3 Notation and terminology" align="middle" width="32"></a></td>
623 <td valign="middle" align="left"><a href="#Lexical-conventions" title="Next chapter"><img src="button-right-right.png" border="0" alt="FastForward: 2. Lexical conventions" align="middle" width="32"></a></td>
624 <td valign="middle" align="left"><a href="#Top" title="Cover (top) of document"><img src="button-up-arrow.png" border="0" alt="Top: Revised(5) Report on the Algorithmic Language Scheme" align="middle" width="32"></a></td>
625 <td valign="middle" align="left"><a href="#SEC_Contents" title="Table of contents"><img src="button-compass.png" border="0" alt="Contents: Table of Contents" align="middle" width="32"></a></td>
626 <td valign="middle" align="left"><a href="#Index" title="Index"><img src="button-abc.png" border="0" alt="Index: Alphabetic index of definitions of concepts, keywords, and procedures" align="middle" width="32"></a></td>
627 </tr></table>
628 <a name="Entry-format-1"></a>
629 <h3 class="subsection">1.3.3 Entry format</h3>
630
631
632 <p>Chapters <a href="#Expressions">Expressions</a> and <a href="#Standard-procedures">Standard procedures</a> are organized
633 into entries. Each entry describes one language feature or a group of
634 related features, where a feature is either a syntactic construct or a
635 built-in procedure. An entry begins with one or more header lines of the form
636 </p>
637
638 <table width="100%"><tr><td align="left"> <b><var>template</var></b></td><td align="right"><var>category</var></td></tr></table>
639
640
641 <p>for required, primitive features, or
642 </p>
643
644 <table width="100%"><tr><td align="left"> <b><var>template</var></b></td><td align="right"><var>qualifier</var> <var>category</var></td></tr></table>
645
646
647 <p>where <var>qualifier</var> is either &ldquo;library&rdquo; or &ldquo;optional&rdquo; as defined
648 in section <a href="#Primitive_003b-library_003b-and-optional-features">Primitive; library; and optional features</a>.
649 </p>
650 <p>If <var>category</var> is &ldquo;syntax&rdquo;, the entry describes an expression
651 type, and the template gives the syntax of the expression type.
652 Components of expressions are designated by syntactic variables, which
653 are written using angle brackets, for example, <span class="roman">&lt;expression&gt;</span>,
654 <span class="roman">&lt;variable&gt;</span>. Syntactic variables should be understood to denote segments of
655 program text; for example, <span class="roman">&lt;expression&gt;</span> stands for any string of
656 characters which is a syntactically valid expression. The notation
657 </p>
658 <table><tr><td>&nbsp;</td><td><pre class="format"> <span class="roman">&lt;thing1&gt;</span> &hellip;
659 </pre></td></tr></table>
660
661 <p>indicates zero or more occurrences of a <span class="roman">&lt;thing&gt;</span>, and
662 </p>
663 <table><tr><td>&nbsp;</td><td><pre class="format"> <span class="roman">&lt;thing1&gt;</span> <span class="roman">&lt;thing2&gt;</span> &hellip;
664 </pre></td></tr></table>
665
666 <p>indicates one or more occurrences of a <span class="roman">&lt;thing&gt;</span>.
667 </p>
668 <p>If <var>category</var> is &ldquo;procedure&rdquo;, then the entry describes a procedure, and
669 the header line gives a template for a call to the procedure. Argument
670 names in the template are <var>italicized</var>. Thus the header line
671 </p>
672
673 <table width="100%"><tr><td align="left"> <code>(</code><code><b>vector-ref</b></code><i> <var>vector</var> <var>k</var></i><code>)</code></td><td align="right">procedure</td></tr></table>
674
675
676 <p>indicates that the built-in procedure <tt>vector-ref</tt> takes
677 two arguments, a vector <var>vector</var> and an exact non-negative integer
678 <var>k</var> (see below). The header lines
679 </p>
680
681
682 <table width="100%"><tr><td align="left"> <code>(</code><code><b>make-vector</b></code><i> <var>k</var></i><code>)</code></td><td align="right">procedure</td></tr></table>
683 <table width="100%"><tr><td align="left"> <code>(</code><code><b>make-vector</b></code><i> <var>k</var> <var>fill</var></i><code>)</code></td><td align="right">procedure</td></tr></table>
684
685
686 <p>indicate that the <tt>make-vector</tt> procedure must be defined to take
687 either one or two arguments.
688 </p>
689
690 <p>It is an error for an operation to be presented with an argument that it
691 is not specified to handle. For succinctness, we follow the convention
692 that if an argument name is also the name of a type listed in
693 section <a href="#Disjointness-of-types">Disjointness of types</a>, then that argument must be of the named type.
694 For example, the header line for <tt>vector-ref</tt> given above dictates that the
695 first argument to <tt>vector-ref</tt> must be a vector. The following naming
696 conventions also imply type restrictions:
697 </p>
698
699 <blockquote><dl compact="compact">
700 <dt> <var>obj</var></dt>
701 </dl>
702 </blockquote>
703 <p>any object
704 </p> <var>list</var>, <var>list1</var>, &hellip; <var>listj</var>, &hellip;
705 <p>list (see section see section <a href="#Pairs-and-lists">Pairs and lists</a>)
706 </p> <var>z</var>, <var>z1</var>, &hellip; <var>zj</var>, &hellip;
707 <p>complex number
708 </p> <var>x</var>, <var>x1</var>, &hellip; <var>xj</var>, &hellip;
709 <p>real number
710 </p> <var>y</var>, <var>y1</var>, &hellip; <var>yj</var>, &hellip;
711 <p>real number
712 </p> <var>q</var>, <var>q1</var>, &hellip; <var>qj</var>, &hellip;
713 <p>rational number
714 </p> <var>n</var>, <var>n1</var>, &hellip; <var>nj</var>, &hellip;
715 <p>integer
716 </p> <var>k</var>, <var>k1</var>, &hellip; <var>kj</var>, &hellip;
717 <p>exact non-negative integer
718 </p>
719
720
721
722
723
724
725
726 <a name="Evaluation-examples"></a><hr size="1"><br/><br/><br/>
727 <table cellpadding="1" cellspacing="1" border="0">
728 <tr><td valign="middle" align="left"><a href="#Entry-format" title="Previous section in reading order"><img src="button-left.png" border="0" alt="Back: 1.3.3 Entry format" align="middle" width="32"></a></td>
729 <td valign="middle" align="left"><a href="#Naming-conventions" title="Next section in reading order"><img src="button-right.png" border="0" alt="Forward: 1.3.5 Naming conventions" align="middle" width="32"></a></td>
730 <td valign="middle" align="left"> &nbsp; </td>
731 <td valign="middle" align="left"><a href="#Overview-of-Scheme" title="Beginning of this chapter or previous chapter"><img src="button-left-left.png" border="0" alt="FastBack: 1. Overview of Scheme" align="middle" width="32"></a></td>
732 <td valign="middle" align="left"><a href="#Notation-and-terminology" title="Up section"><img src="button-up.png" border="0" alt="Up: 1.3 Notation and terminology" align="middle" width="32"></a></td>
733 <td valign="middle" align="left"><a href="#Lexical-conventions" title="Next chapter"><img src="button-right-right.png" border="0" alt="FastForward: 2. Lexical conventions" align="middle" width="32"></a></td>
734 <td valign="middle" align="left"><a href="#Top" title="Cover (top) of document"><img src="button-up-arrow.png" border="0" alt="Top: Revised(5) Report on the Algorithmic Language Scheme" align="middle" width="32"></a></td>
735 <td valign="middle" align="left"><a href="#SEC_Contents" title="Table of contents"><img src="button-compass.png" border="0" alt="Contents: Table of Contents" align="middle" width="32"></a></td>
736 <td valign="middle" align="left"><a href="#Index" title="Index"><img src="button-abc.png" border="0" alt="Index: Alphabetic index of definitions of concepts, keywords, and procedures" align="middle" width="32"></a></td>
737 </tr></table>
738 <a name="Evaluation-examples-1"></a>
739 <h3 class="subsection">1.3.4 Evaluation examples</h3>
740
741
742 <p>The symbol &ldquo;&rArr;&rdquo; used in program examples should be read
743 &ldquo;evaluates to.&rdquo; For example,
744 </p>
745
746 <table><tr><td>&nbsp;</td><td><pre class="example">
747 (* 5 8) ==&gt; 40
748 </pre></td></tr></table>
749
750
751 <p>means that the expression <tt>(* 5 8)</tt> evaluates to the object <tt>40</tt>.
752 Or, more precisely: the expression given by the sequence of characters
753 &ldquo;<tt>(* 5 8)</tt>&rdquo; evaluates, in the initial environment, to an object
754 that may be represented externally by the sequence of characters &ldquo;<tt>40</tt>&rdquo;. See section <a href="#External-representations">External representations</a> for a discussion of external
755 representations of objects.
756 </p>
757 <a name="Naming-conventions"></a><hr size="1"><br/><br/><br/>
758 <table cellpadding="1" cellspacing="1" border="0">
759 <tr><td valign="middle" align="left"><a href="#Evaluation-examples" title="Previous section in reading order"><img src="button-left.png" border="0" alt="Back: 1.3.4 Evaluation examples" align="middle" width="32"></a></td>
760 <td valign="middle" align="left"><a href="#Lexical-conventions" title="Next section in reading order"><img src="button-right.png" border="0" alt="Forward: 2. Lexical conventions" align="middle" width="32"></a></td>
761 <td valign="middle" align="left"> &nbsp; </td>
762 <td valign="middle" align="left"><a href="#Overview-of-Scheme" title="Beginning of this chapter or previous chapter"><img src="button-left-left.png" border="0" alt="FastBack: 1. Overview of Scheme" align="middle" width="32"></a></td>
763 <td valign="middle" align="left"><a href="#Notation-and-terminology" title="Up section"><img src="button-up.png" border="0" alt="Up: 1.3 Notation and terminology" align="middle" width="32"></a></td>
764 <td valign="middle" align="left"><a href="#Lexical-conventions" title="Next chapter"><img src="button-right-right.png" border="0" alt="FastForward: 2. Lexical conventions" align="middle" width="32"></a></td>
765 <td valign="middle" align="left"><a href="#Top" title="Cover (top) of document"><img src="button-up-arrow.png" border="0" alt="Top: Revised(5) Report on the Algorithmic Language Scheme" align="middle" width="32"></a></td>
766 <td valign="middle" align="left"><a href="#SEC_Contents" title="Table of contents"><img src="button-compass.png" border="0" alt="Contents: Table of Contents" align="middle" width="32"></a></td>
767 <td valign="middle" align="left"><a href="#Index" title="Index"><img src="button-abc.png" border="0" alt="Index: Alphabetic index of definitions of concepts, keywords, and procedures" align="middle" width="32"></a></td>
768 </tr></table>
769 <a name="Naming-conventions-1"></a>
770 <h3 class="subsection">1.3.5 Naming conventions</h3>
771
772
773 <p>By convention, the names of procedures that always return a boolean
774 value usually end
775 in &ldquo;<code>?</code>&rdquo;. Such procedures are called predicates.
776 <a name="index-_003f"></a>
777 </p>
778 <p>By convention, the names of procedures that store values into previously
779 allocated locations (see section see section <a href="#Storage-model">Storage model</a>) usually end in
780 &ldquo;<code>!</code>&rdquo;.
781 <a name="index-_0021"></a>
782 Such procedures are called mutation procedures.
783 By convention, the value returned by a mutation procedure is unspecified.
784 </p>
785 <p>By convention, &ldquo;<code>-&gt;</code>&rdquo; appears within the names of procedures that
786 <a name="index-_002d_003e"></a>
787 take an object of one type and return an analogous object of another type.
788 For example, <samp>list-&gt;vector</samp> takes a list and returns a vector whose
789 elements are the same as those of the list.
790 </p>
791
792
793
794
795
796
797 <a name="Lexical-conventions"></a><hr size="1"><br/><br/><br/>
798 <table cellpadding="1" cellspacing="1" border="0">
799 <tr><td valign="middle" align="left"><a href="#Naming-conventions" title="Previous section in reading order"><img src="button-left.png" border="0" alt="Back: 1.3.5 Naming conventions" align="middle" width="32"></a></td>
800 <td valign="middle" align="left"><a href="#Identifiers" title="Next section in reading order"><img src="button-right.png" border="0" alt="Forward: 2.1 Identifiers" align="middle" width="32"></a></td>
801 <td valign="middle" align="left"> &nbsp; </td>
802 <td valign="middle" align="left"><a href="#Overview-of-Scheme" title="Beginning of this chapter or previous chapter"><img src="button-left-left.png" border="0" alt="FastBack: 1. Overview of Scheme" align="middle" width="32"></a></td>
803 <td valign="middle" align="left"><a href="#Top" title="Up section"><img src="button-up.png" border="0" alt="Up: Revised(5) Report on the Algorithmic Language Scheme" align="middle" width="32"></a></td>
804 <td valign="middle" align="left"><a href="#Basic-concepts" title="Next chapter"><img src="button-right-right.png" border="0" alt="FastForward: 3. Basic concepts" align="middle" width="32"></a></td>
805 <td valign="middle" align="left"><a href="#Top" title="Cover (top) of document"><img src="button-up-arrow.png" border="0" alt="Top: Revised(5) Report on the Algorithmic Language Scheme" align="middle" width="32"></a></td>
806 <td valign="middle" align="left"><a href="#SEC_Contents" title="Table of contents"><img src="button-compass.png" border="0" alt="Contents: Table of Contents" align="middle" width="32"></a></td>
807 <td valign="middle" align="left"><a href="#Index" title="Index"><img src="button-abc.png" border="0" alt="Index: Alphabetic index of definitions of concepts, keywords, and procedures" align="middle" width="32"></a></td>
808 </tr></table>
809 <a name="Lexical-conventions-1"></a>
810 <h1 class="chapter">2. Lexical conventions</h1>
811
812 <table class="menu" border="0" cellspacing="0">
813 <tr><td align="left" valign="top"><a href="#Identifiers">2.1 Identifiers</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
814 </td></tr>
815 <tr><td align="left" valign="top"><a href="#Whitespace-and-comments">2.2 Whitespace and comments</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
816 </td></tr>
817 <tr><td align="left" valign="top"><a href="#Other-notations">2.3 Other notations</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
818 </td></tr>
819 </table>
820
821
822 <p>This section gives an informal account of some of the lexical
823 conventions used in writing Scheme programs. For a formal syntax of
824 Scheme, see section <a href="#Formal-syntax">Formal syntax</a>.
825 </p>
826 <p>Upper and lower case forms of a letter are never distinguished
827 except within character and string constants. For example, <samp>Foo</samp> is
828 the same identifier as <samp>FOO</samp>, and <tt>#x1AB</tt> is the same number as
829 <tt>#X1ab</tt>.
830 </p>
831 <a name="Identifiers"></a><hr size="1"><br/><br/><br/>
832 <table cellpadding="1" cellspacing="1" border="0">
833 <tr><td valign="middle" align="left"><a href="#Lexical-conventions" title="Previous section in reading order"><img src="button-left.png" border="0" alt="Back: 2. Lexical conventions" align="middle" width="32"></a></td>
834 <td valign="middle" align="left"><a href="#Whitespace-and-comments" title="Next section in reading order"><img src="button-right.png" border="0" alt="Forward: 2.2 Whitespace and comments" align="middle" width="32"></a></td>
835 <td valign="middle" align="left"> &nbsp; </td>
836 <td valign="middle" align="left"><a href="#Lexical-conventions" title="Beginning of this chapter or previous chapter"><img src="button-left-left.png" border="0" alt="FastBack: 2. Lexical conventions" align="middle" width="32"></a></td>
837 <td valign="middle" align="left"><a href="#Lexical-conventions" title="Up section"><img src="button-up.png" border="0" alt="Up: 2. Lexical conventions" align="middle" width="32"></a></td>
838 <td valign="middle" align="left"><a href="#Basic-concepts" title="Next chapter"><img src="button-right-right.png" border="0" alt="FastForward: 3. Basic concepts" align="middle" width="32"></a></td>
839 <td valign="middle" align="left"><a href="#Top" title="Cover (top) of document"><img src="button-up-arrow.png" border="0" alt="Top: Revised(5) Report on the Algorithmic Language Scheme" align="middle" width="32"></a></td>
840 <td valign="middle" align="left"><a href="#SEC_Contents" title="Table of contents"><img src="button-compass.png" border="0" alt="Contents: Table of Contents" align="middle" width="32"></a></td>
841 <td valign="middle" align="left"><a href="#Index" title="Index"><img src="button-abc.png" border="0" alt="Index: Alphabetic index of definitions of concepts, keywords, and procedures" align="middle" width="32"></a></td>
842 </tr></table>
843 <a name="Identifiers-1"></a>
844 <h2 class="section">2.1 Identifiers</h2>
845
846
847
848 <p>Most identifiers allowed by other programming
849 <a name="index-identifier"></a>
850 languages are also acceptable to Scheme. The precise rules for forming
851 identifiers vary among implementations of Scheme, but in all
852 implementations a sequence of letters, digits, and &ldquo;extended alphabetic
853 characters&rdquo; that begins with a character that cannot begin a number is
854 an identifier. In addition, <code>+</code>, <code>-</code>, and <code>...</code> are identifiers.
855 <a name="index-_002e_002e_002e"></a>
856 <a name="index-_002d"></a>
857 <a name="index-_002b"></a>
858 Here are some examples of identifiers:
859 </p>
860
861 <table><tr><td>&nbsp;</td><td><pre class="example">
862 lambda q
863 list-&gt;vector soup
864 + V17a
865 &lt;=? a34kTMNs
866 the-word-recursion-has-many-meanings
867 </pre></td></tr></table>
868
869
870 <p>Extended alphabetic characters may be used within identifiers as if
871 they were letters. The following are extended alphabetic characters:
872 </p>
873
874 <table><tr><td>&nbsp;</td><td><pre class="example">
875 ! $ % &amp; * + - . / : &lt; = &gt; ? @ ^ _ ~
876 </pre></td></tr></table>
877
878
879 <p>See section <a href="#Lexical-structure">Lexical structure</a> for a formal syntax of identifiers.
880 </p>
881 <p>Identifiers have two uses within Scheme programs:
882 </p>
883
884 <ul>
885 <li>
886 Any identifier may be used as a variable
887 or as a syntactic keyword
888 (see sections see section <a href="#Variables_003b-syntactic-keywords_003b-and-regions">Variables; syntactic keywords; and regions</a> and see section <a href="#Macros">Macros</a>).
889
890 </li><li>
891 When an identifier appears as a literal or within a literal
892 (see section see section <a href="#Literal-expressions">Literal expressions</a>), it is being used to denote a <em>symbol</em>
893 (see section see section <a href="#Symbols">Symbols</a>).
894
895
896 </li></ul>
897
898 <a name="index-syntactic-keyword"></a>
899 <a name="index-variable"></a>
900
901
902
903
904
905 <a name="Whitespace-and-comments"></a><hr size="1"><br/><br/><br/>
906 <table cellpadding="1" cellspacing="1" border="0">
907 <tr><td valign="middle" align="left"><a href="#Identifiers" title="Previous section in reading order"><img src="button-left.png" border="0" alt="Back: 2.1 Identifiers" align="middle" width="32"></a></td>
908 <td valign="middle" align="left"><a href="#Other-notations" title="Next section in reading order"><img src="button-right.png" border="0" alt="Forward: 2.3 Other notations" align="middle" width="32"></a></td>
909 <td valign="middle" align="left"> &nbsp; </td>
910 <td valign="middle" align="left"><a href="#Lexical-conventions" title="Beginning of this chapter or previous chapter"><img src="button-left-left.png" border="0" alt="FastBack: 2. Lexical conventions" align="middle" width="32"></a></td>
911 <td valign="middle" align="left"><a href="#Lexical-conventions" title="Up section"><img src="button-up.png" border="0" alt="Up: 2. Lexical conventions" align="middle" width="32"></a></td>
912 <td valign="middle" align="left"><a href="#Basic-concepts" title="Next chapter"><img src="button-right-right.png" border="0" alt="FastForward: 3. Basic concepts" align="middle" width="32"></a></td>
913 <td valign="middle" align="left"><a href="#Top" title="Cover (top) of document"><img src="button-up-arrow.png" border="0" alt="Top: Revised(5) Report on the Algorithmic Language Scheme" align="middle" width="32"></a></td>
914 <td valign="middle" align="left"><a href="#SEC_Contents" title="Table of contents"><img src="button-compass.png" border="0" alt="Contents: Table of Contents" align="middle" width="32"></a></td>
915 <td valign="middle" align="left"><a href="#Index" title="Index"><img src="button-abc.png" border="0" alt="Index: Alphabetic index of definitions of concepts, keywords, and procedures" align="middle" width="32"></a></td>
916 </tr></table>
917 <a name="Whitespace-and-comments-1"></a>
918 <h2 class="section">2.2 Whitespace and comments</h2>
919
920
921 <p><em>Whitespace</em> characters are spaces and newlines.
922 <a name="index-Whitespace"></a>
923 (Implementations typically provide additional whitespace characters such
924 as tab or page break.) Whitespace is used for improved readability and
925 as necessary to separate tokens from each other, a token being an
926 indivisible lexical unit such as an identifier or number, but is
927 otherwise insignificant. Whitespace may occur between any two tokens,
928 but not within a token. Whitespace may also occur inside a string,
929 where it is significant.
930 </p>
931 <p>A semicolon (<tt>;</tt>) indicates the start of a
932 comment. The comment continues to the
933 <a name="index-_003b"></a>
934 <a name="index-comment"></a>
935 end of the line on which the semicolon appears. Comments are invisible
936 to Scheme, but the end of the line is visible as whitespace. This
937 prevents a comment from appearing in the middle of an identifier or
938 number.
939 </p>
940
941 <table><tr><td>&nbsp;</td><td><pre class="example">
942 ;;; The FACT procedure computes the factorial
943 ;;; of a non-negative integer.
944 (define fact
945 (lambda (n)
946 (if (= n 0)
947 1 ;Base case: return 1
948 (* n (fact (- n 1))))))
949 </pre></td></tr></table>
950
951
952
953 <a name="Other-notations"></a><hr size="1"><br/><br/><br/>
954 <table cellpadding="1" cellspacing="1" border="0">
955 <tr><td valign="middle" align="left"><a href="#Whitespace-and-comments" title="Previous section in reading order"><img src="button-left.png" border="0" alt="Back: 2.2 Whitespace and comments" align="middle" width="32"></a></td>
956 <td valign="middle" align="left"><a href="#Basic-concepts" title="Next section in reading order"><img src="button-right.png" border="0" alt="Forward: 3. Basic concepts" align="middle" width="32"></a></td>
957 <td valign="middle" align="left"> &nbsp; </td>
958 <td valign="middle" align="left"><a href="#Lexical-conventions" title="Beginning of this chapter or previous chapter"><img src="button-left-left.png" border="0" alt="FastBack: 2. Lexical conventions" align="middle" width="32"></a></td>
959 <td valign="middle" align="left"><a href="#Lexical-conventions" title="Up section"><img src="button-up.png" border="0" alt="Up: 2. Lexical conventions" align="middle" width="32"></a></td>
960 <td valign="middle" align="left"><a href="#Basic-concepts" title="Next chapter"><img src="button-right-right.png" border="0" alt="FastForward: 3. Basic concepts" align="middle" width="32"></a></td>
961 <td valign="middle" align="left"><a href="#Top" title="Cover (top) of document"><img src="button-up-arrow.png" border="0" alt="Top: Revised(5) Report on the Algorithmic Language Scheme" align="middle" width="32"></a></td>
962 <td valign="middle" align="left"><a href="#SEC_Contents" title="Table of contents"><img src="button-compass.png" border="0" alt="Contents: Table of Contents" align="middle" width="32"></a></td>
963 <td valign="middle" align="left"><a href="#Index" title="Index"><img src="button-abc.png" border="0" alt="Index: Alphabetic index of definitions of concepts, keywords, and procedures" align="middle" width="32"></a></td>
964 </tr></table>
965 <a name="Other-notations-1"></a>
966 <h2 class="section">2.3 Other notations</h2>
967
968
969
970
971 <p>For a description of the notations used for numbers, see
972 section <a href="#Numbers">Numbers</a>.
973 </p>
974
975 <dl compact="compact">
976 <dt> <tt>. + -</tt></dt>
977 <dd><p>These are used in numbers, and may also occur anywhere in an identifier
978 except as the first character. A delimited plus or minus sign by itself
979 is also an identifier.
980 A delimited period (not occurring within a number or identifier) is used
981 in the notation for pairs (section see section <a href="#Pairs-and-lists">Pairs and lists</a>), and to indicate a
982 rest-parameter in a formal parameter list (section see section <a href="#Procedures">Procedures</a>).
983 A delimited sequence of three successive periods is also an identifier.
984 </p>
985 </dd>
986 <dt> <tt>( )</tt></dt>
987 <dd><p>Parentheses are used for grouping and to notate lists
988 (section see section <a href="#Pairs-and-lists">Pairs and lists</a>).
989 </p>
990 </dd>
991 <dt> <tt>'</tt></dt>
992 <dd><p>The single quote character is used to indicate literal data (section see section <a href="#Literal-expressions">Literal expressions</a>).
993 </p>
994 </dd>
995 <dt> <tt>&lsquo;</tt></dt>
996 <dd><p>The backquote character is used to indicate almost-constant
997 data (section see section <a href="#Quasiquotation">Quasiquotation</a>).
998 </p>
999 </dd>
1000 <dt> <tt>, ,@</tt></dt>
1001 <dd><p>The character comma and the sequence comma at-sign are used in conjunction
1002 with backquote (section see section <a href="#Quasiquotation">Quasiquotation</a>).
1003 </p>
1004 </dd>
1005 <dt> <tt>&quot;</tt></dt>
1006 <dd><p>The double quote character is used to delimit strings (section see section <a href="#Strings">Strings</a>).
1007 </p>
1008 </dd>
1009 <dt> <tt>\</tt></dt>
1010 <dd><p>Backslash is used in the syntax for character constants
1011 (section see section <a href="#Characters">Characters</a>) and as an escape character within string
1012 constants (section see section <a href="#Strings">Strings</a>).
1013 </p>
1014
1015 </dd>
1016 <dt> <tt>[ ] { } |</tt></dt>
1017 <dd><p>Left and right square brackets and curly braces and vertical bar
1018 are reserved for possible future extensions to the language.
1019 </p>
1020 </dd>
1021 <dt> <tt>#</tt></dt>
1022 <dd><p> Sharp sign is used for a variety of purposes depending on
1023 the character that immediately follows it:
1024 </p>
1025 </dd>
1026 <dt> <tt>#t</tt> <tt>#f</tt></dt>
1027 <dd><p>These are the boolean constants (section see section <a href="#Booleans">Booleans</a>).
1028 </p>
1029 </dd>
1030 <dt> <tt>#\</tt></dt>
1031 <dd><p>This introduces a character constant (section see section <a href="#Characters">Characters</a>).
1032 </p>
1033 </dd>
1034 <dt> <tt>#(</tt></dt>
1035 <dd><p>This introduces a vector constant (section see section <a href="#Vectors">Vectors</a>). Vector constants
1036 are terminated by <tt>)</tt> .
1037 </p>
1038 </dd>
1039 <dt> <tt>#e #i #b #o #d #x</tt></dt>
1040 <dd><p>These are used in the notation for numbers (section see section <a href="#Syntax-of-numerical-constants">Syntax of numerical constants</a>).
1041 </p>
1042 </dd>
1043 </dl>
1044
1045
1046
1047 <a name="Basic-concepts"></a><hr size="1"><br/><br/><br/>
1048 <table cellpadding="1" cellspacing="1" border="0">
1049 <tr><td valign="middle" align="left"><a href="#Other-notations" title="Previous section in reading order"><img src="button-left.png" border="0" alt="Back: 2.3 Other notations" align="middle" width="32"></a></td>
1050 <td valign="middle" align="left"><a href="#Variables_003b-syntactic-keywords_003b-and-regions" title="Next section in reading order"><img src="button-right.png" border="0" alt="Forward: 3.1 Variables; syntactic keywords; and regions" align="middle" width="32"></a></td>
1051 <td valign="middle" align="left"> &nbsp; </td>
1052 <td valign="middle" align="left"><a href="#Lexical-conventions" title="Beginning of this chapter or previous chapter"><img src="button-left-left.png" border="0" alt="FastBack: 2. Lexical conventions" align="middle" width="32"></a></td>
1053 <td valign="middle" align="left"><a href="#Top" title="Up section"><img src="button-up.png" border="0" alt="Up: Revised(5) Report on the Algorithmic Language Scheme" align="middle" width="32"></a></td>
1054 <td valign="middle" align="left"><a href="#Expressions" title="Next chapter"><img src="button-right-right.png" border="0" alt="FastForward: 4. Expressions" align="middle" width="32"></a></td>
1055 <td valign="middle" align="left"><a href="#Top" title="Cover (top) of document"><img src="button-up-arrow.png" border="0" alt="Top: Revised(5) Report on the Algorithmic Language Scheme" align="middle" width="32"></a></td>
1056 <td valign="middle" align="left"><a href="#SEC_Contents" title="Table of contents"><img src="button-compass.png" border="0" alt="Contents: Table of Contents" align="middle" width="32"></a></td>
1057 <td valign="middle" align="left"><a href="#Index" title="Index"><img src="button-abc.png" border="0" alt="Index: Alphabetic index of definitions of concepts, keywords, and procedures" align="middle" width="32"></a></td>
1058 </tr></table>
1059 <a name="Basic-concepts-1"></a>
1060 <h1 class="chapter">3. Basic concepts</h1>
1061
1062 <table class="menu" border="0" cellspacing="0">
1063 <tr><td align="left" valign="top"><a href="#Variables_003b-syntactic-keywords_003b-and-regions">3.1 Variables; syntactic keywords; and regions</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
1064 </td></tr>
1065 <tr><td align="left" valign="top"><a href="#Disjointness-of-types">3.2 Disjointness of types</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
1066 </td></tr>
1067 <tr><td align="left" valign="top"><a href="#External-representations">3.3 External representations</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
1068 </td></tr>
1069 <tr><td align="left" valign="top"><a href="#Storage-model">3.4 Storage model</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
1070 </td></tr>
1071 <tr><td align="left" valign="top"><a href="#Proper-tail-recursion">3.5 Proper tail recursion</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
1072 </td></tr>
1073 </table>
1074
1075
1076
1077 <a name="Variables_003b-syntactic-keywords_003b-and-regions"></a><hr size="1"><br/><br/><br/>
1078 <table cellpadding="1" cellspacing="1" border="0">
1079 <tr><td valign="middle" align="left"><a href="#Basic-concepts" title="Previous section in reading order"><img src="button-left.png" border="0" alt="Back: 3. Basic concepts" align="middle" width="32"></a></td>
1080 <td valign="middle" align="left"><a href="#Disjointness-of-types" title="Next section in reading order"><img src="button-right.png" border="0" alt="Forward: 3.2 Disjointness of types" align="middle" width="32"></a></td>
1081 <td valign="middle" align="left"> &nbsp; </td>
1082 <td valign="middle" align="left"><a href="#Basic-concepts" title="Beginning of this chapter or previous chapter"><img src="button-left-left.png" border="0" alt="FastBack: 3. Basic concepts" align="middle" width="32"></a></td>
1083 <td valign="middle" align="left"><a href="#Basic-concepts" title="Up section"><img src="button-up.png" border="0" alt="Up: 3. Basic concepts" align="middle" width="32"></a></td>
1084 <td valign="middle" align="left"><a href="#Expressions" title="Next chapter"><img src="button-right-right.png" border="0" alt="FastForward: 4. Expressions" align="middle" width="32"></a></td>
1085 <td valign="middle" align="left"><a href="#Top" title="Cover (top) of document"><img src="button-up-arrow.png" border="0" alt="Top: Revised(5) Report on the Algorithmic Language Scheme" align="middle" width="32"></a></td>
1086 <td valign="middle" align="left"><a href="#SEC_Contents" title="Table of contents"><img src="button-compass.png" border="0" alt="Contents: Table of Contents" align="middle" width="32"></a></td>
1087 <td valign="middle" align="left"><a href="#Index" title="Index"><img src="button-abc.png" border="0" alt="Index: Alphabetic index of definitions of concepts, keywords, and procedures" align="middle" width="32"></a></td>
1088 </tr></table>
1089 <a name="Variables_003b-syntactic-keywords_003b-and-regions-1"></a>
1090 <h2 class="section">3.1 Variables; syntactic keywords; and regions</h2>
1091
1092
1093
1094
1095 <p>An identifier may name a type of syntax, or it may name
1096 <a name="index-identifier-1"></a>
1097 a location where a value can be stored. An identifier that names a type
1098 of syntax is called a <em>syntactic keyword</em>
1099 <a name="index-syntactic-keyword-1"></a>
1100 and is said to be <em>bound</em> to that syntax. An identifier that names a
1101 location is called a <em>variable</em> and is said to be
1102 <a name="index-variable-1"></a>
1103 <em>bound</em> to that location. The set of all visible
1104 bindings in effect at some point in a program is
1105 <a name="index-binding"></a>
1106 known as the <em>environment</em> in effect at that point. The value
1107 stored in the location to which a variable is bound is called the
1108 variable's value. By abuse of terminology, the variable is sometimes
1109 said to name the value or to be bound to the value. This is not quite
1110 accurate, but confusion rarely results from this practice.
1111 </p>
1112
1113
1114
1115
1116 <p>Certain expression types are used to create new kinds of syntax
1117 and bind syntactic keywords to those new syntaxes, while other
1118 expression types create new locations and bind variables to those
1119 locations. These expression types are called <em>binding constructs</em>.
1120 </p>
1121 <a name="index-binding-construct"></a>
1122 <p>Those that bind syntactic keywords are listed in section <a href="#Macros">Macros</a>.
1123 The most fundamental of the variable binding constructs is the
1124 <samp>lambda</samp> expression, because all other variable binding constructs
1125 can be explained in terms of <samp>lambda</samp> expressions. The other
1126 variable binding constructs are <samp>let</samp>, <samp>let*</samp>, <samp>letrec</samp>,
1127 and <samp>do</samp> expressions (see sections see section <a href="#Procedures">Procedures</a>, see section <a href="#Binding-constructs">Binding constructs</a>, and
1128 see section <a href="#Iteration">Iteration</a>).
1129 </p>
1130
1131 <p>Like Algol and Pascal, and unlike most other dialects of Lisp
1132 except for Common Lisp, Scheme is a statically scoped language with
1133 block structure. To each place where an identifier is bound in a program
1134 there corresponds a <em>region</em> of the program text within which
1135 <a name="index-region"></a>
1136 the binding is visible. The region is determined by the particular
1137 binding construct that establishes the binding; if the binding is
1138 established by a <samp>lambda</samp> expression, for example, then its region
1139 is the entire <samp>lambda</samp> expression. Every mention of an identifier
1140 refers to the binding of the identifier that established the
1141 innermost of the regions containing the use. If there is no binding of
1142 the identifier whose region contains the use, then the use refers to the
1143 binding for the variable in the top level environment, if any
1144 (chapters see section <a href="#Expressions">Expressions</a> and see section <a href="#Standard-procedures">Standard procedures</a>); if there is no
1145 binding for the identifier,
1146 it is said to be <em>unbound</em>.
1147 <a name="index-top-level-environment"></a>
1148 <a name="index-bound"></a>
1149 <a name="index-unbound"></a>
1150 </p>
1151
1152
1153
1154
1155
1156
1157 <a name="Disjointness-of-types"></a><hr size="1"><br/><br/><br/>
1158 <table cellpadding="1" cellspacing="1" border="0">
1159 <tr><td valign="middle" align="left"><a href="#Variables_003b-syntactic-keywords_003b-and-regions" title="Previous section in reading order"><img src="button-left.png" border="0" alt="Back: 3.1 Variables; syntactic keywords; and regions" align="middle" width="32"></a></td>
1160 <td valign="middle" align="left"><a href="#External-representations" title="Next section in reading order"><img src="button-right.png" border="0" alt="Forward: 3.3 External representations" align="middle" width="32"></a></td>
1161 <td valign="middle" align="left"> &nbsp; </td>
1162 <td valign="middle" align="left"><a href="#Basic-concepts" title="Beginning of this chapter or previous chapter"><img src="button-left-left.png" border="0" alt="FastBack: 3. Basic concepts" align="middle" width="32"></a></td>
1163 <td valign="middle" align="left"><a href="#Basic-concepts" title="Up section"><img src="button-up.png" border="0" alt="Up: 3. Basic concepts" align="middle" width="32"></a></td>
1164 <td valign="middle" align="left"><a href="#Expressions" title="Next chapter"><img src="button-right-right.png" border="0" alt="FastForward: 4. Expressions" align="middle" width="32"></a></td>
1165 <td valign="middle" align="left"><a href="#Top" title="Cover (top) of document"><img src="button-up-arrow.png" border="0" alt="Top: Revised(5) Report on the Algorithmic Language Scheme" align="middle" width="32"></a></td>
1166 <td valign="middle" align="left"><a href="#SEC_Contents" title="Table of contents"><img src="button-compass.png" border="0" alt="Contents: Table of Contents" align="middle" width="32"></a></td>
1167 <td valign="middle" align="left"><a href="#Index" title="Index"><img src="button-abc.png" border="0" alt="Index: Alphabetic index of definitions of concepts, keywords, and procedures" align="middle" width="32"></a></td>
1168 </tr></table>
1169 <a name="Disjointness-of-types-1"></a>
1170 <h2 class="section">3.2 Disjointness of types</h2>
1171
1172
1173
1174 <p>No object satisfies more than one of the following predicates:
1175 </p>
1176
1177 <table><tr><td>&nbsp;</td><td><pre class="example">
1178 boolean? pair?
1179 symbol? number?
1180 char? string?
1181 vector? port?
1182 procedure?
1183 </pre></td></tr></table>
1184
1185
1186 <p>These predicates define the types <em>boolean</em>, <em>pair</em>, <em>symbol</em>, <em>number</em>, <em>char</em> (or <em>character</em>), <em>string</em>, <em>vector</em>, <em>port</em>, and <em>procedure</em>. The empty list is a special
1187 object of its own type; it satisfies none of the above predicates.
1188 </p>
1189 <a name="index-symbol_003f"></a>
1190 <a name="index-pair_003f"></a>
1191 <a name="index-boolean_003f"></a>
1192 <a name="index-type"></a>
1193
1194 <a name="index-vector_003f"></a>
1195 <a name="index-string_003f"></a>
1196 <a name="index-char_003f"></a>
1197 <a name="index-number_003f"></a>
1198
1199 <a name="index-empty-list"></a>
1200 <a name="index-procedure_003f"></a>
1201 <a name="index-port_003f"></a>
1202
1203 <p>Although there is a separate boolean type,
1204 any Scheme value can be used as a boolean value for the purpose of a
1205 conditional test. As explained in section <a href="#Booleans">Booleans</a>, all
1206 values count as true in such a test except for <tt>#f</tt>.
1207 This report uses the word &ldquo;true&rdquo; to refer to any
1208 Scheme value except <tt>#f</tt>, and the word &ldquo;false&rdquo; to refer to
1209 <tt>#f</tt>.
1210 <a name="index-false"></a>
1211 <a name="index-true"></a>
1212 </p>
1213 <a name="External-representations"></a><hr size="1"><br/><br/><br/>
1214 <table cellpadding="1" cellspacing="1" border="0">
1215 <tr><td valign="middle" align="left"><a href="#Disjointness-of-types" title="Previous section in reading order"><img src="button-left.png" border="0" alt="Back: 3.2 Disjointness of types" align="middle" width="32"></a></td>
1216 <td valign="middle" align="left"><a href="#Storage-model" title="Next section in reading order"><img src="button-right.png" border="0" alt="Forward: 3.4 Storage model" align="middle" width="32"></a></td>
1217 <td valign="middle" align="left"> &nbsp; </td>
1218 <td valign="middle" align="left"><a href="#Basic-concepts" title="Beginning of this chapter or previous chapter"><img src="button-left-left.png" border="0" alt="FastBack: 3. Basic concepts" align="middle" width="32"></a></td>
1219 <td valign="middle" align="left"><a href="#Basic-concepts" title="Up section"><img src="button-up.png" border="0" alt="Up: 3. Basic concepts" align="middle" width="32"></a></td>
1220 <td valign="middle" align="left"><a href="#Expressions" title="Next chapter"><img src="button-right-right.png" border="0" alt="FastForward: 4. Expressions" align="middle" width="32"></a></td>
1221 <td valign="middle" align="left"><a href="#Top" title="Cover (top) of document"><img src="button-up-arrow.png" border="0" alt="Top: Revised(5) Report on the Algorithmic Language Scheme" align="middle" width="32"></a></td>
1222 <td valign="middle" align="left"><a href="#SEC_Contents" title="Table of contents"><img src="button-compass.png" border="0" alt="Contents: Table of Contents" align="middle" width="32"></a></td>
1223 <td valign="middle" align="left"><a href="#Index" title="Index"><img src="button-abc.png" border="0" alt="Index: Alphabetic index of definitions of concepts, keywords, and procedures" align="middle" width="32"></a></td>
1224 </tr></table>
1225 <a name="External-representations-2"></a>
1226 <h2 class="section">3.3 External representations</h2>
1227
1228
1229
1230 <p>An important concept in Scheme (and Lisp) is that of the <em>external
1231 representation</em> of an object as a sequence of characters. For example,
1232 an external representation of the integer 28 is the sequence of
1233 characters &ldquo;<tt>28</tt>&rdquo;, and an external representation of a list consisting
1234 of the integers 8 and 13 is the sequence of characters &ldquo;<tt>(8 13)</tt>&rdquo;.
1235 </p>
1236 <p>The external representation of an object is not necessarily unique. The
1237 integer 28 also has representations &ldquo;<tt>#e28.000</tt>&rdquo; and &ldquo;<tt>#x1c</tt>&rdquo;, and the
1238 list in the previous paragraph also has the representations &ldquo;<tt>( 08 13
1239 )</tt>&rdquo; and &ldquo;<tt>(8 . (13 . ()))</tt>&rdquo; (see section see section <a href="#Pairs-and-lists">Pairs and lists</a>).
1240 </p>
1241 <p>Many objects have standard external representations, but some, such as
1242 procedures, do not have standard representations (although particular
1243 implementations may define representations for them).
1244 </p>
1245 <p>An external representation may be written in a program to obtain the
1246 corresponding object (see <samp>quote</samp>, section see section <a href="#Literal-expressions">Literal expressions</a>).
1247 </p>
1248 <p>External representations can also be used for input and output. The
1249 procedure <samp>read</samp> (section see section <a href="#Input">Input</a>) parses external
1250 representations, and the procedure <samp>write</samp> (section see section <a href="#Output">Output</a>)
1251 generates them. Together, they provide an elegant and powerful
1252 input/output facility.
1253 </p>
1254 <p>Note that the sequence of characters &ldquo;<tt>(+ 2 6)</tt>&rdquo; is <em>not</em> an
1255 external representation of the integer 8, even though it <em>is</em> an
1256 expression evaluating to the integer 8; rather, it is an external
1257 representation of a three-element list, the elements of which are the symbol
1258 <tt>+</tt> and the integers 2 and 6. Scheme's syntax has the property that
1259 any sequence of characters that is an expression is also the external
1260 representation of some object. This can lead to confusion, since it may
1261 not be obvious out of context whether a given sequence of characters is
1262 intended to denote data or program, but it is also a source of power,
1263 since it facilitates writing programs such as interpreters and
1264 compilers that treat programs as data (or vice versa).
1265 </p>
1266 <p>The syntax of external representations of various kinds of objects
1267 accompanies the description of the primitives for manipulating the
1268 objects in the appropriate sections of chapter <a href="#Standard-procedures">Standard procedures</a>.
1269 </p>
1270 <a name="Storage-model"></a><hr size="1"><br/><br/><br/>
1271 <table cellpadding="1" cellspacing="1" border="0">
1272 <tr><td valign="middle" align="left"><a href="#External-representations" title="Previous section in reading order"><img src="button-left.png" border="0" alt="Back: 3.3 External representations" align="middle" width="32"></a></td>
1273 <td valign="middle" align="left"><a href="#Proper-tail-recursion" title="Next section in reading order"><img src="button-right.png" border="0" alt="Forward: 3.5 Proper tail recursion" align="middle" width="32"></a></td>
1274 <td valign="middle" align="left"> &nbsp; </td>
1275 <td valign="middle" align="left"><a href="#Basic-concepts" title="Beginning of this chapter or previous chapter"><img src="button-left-left.png" border="0" alt="FastBack: 3. Basic concepts" align="middle" width="32"></a></td>
1276 <td valign="middle" align="left"><a href="#Basic-concepts" title="Up section"><img src="button-up.png" border="0" alt="Up: 3. Basic concepts" align="middle" width="32"></a></td>
1277 <td valign="middle" align="left"><a href="#Expressions" title="Next chapter"><img src="button-right-right.png" border="0" alt="FastForward: 4. Expressions" align="middle" width="32"></a></td>
1278 <td valign="middle" align="left"><a href="#Top" title="Cover (top) of document"><img src="button-up-arrow.png" border="0" alt="Top: Revised(5) Report on the Algorithmic Language Scheme" align="middle" width="32"></a></td>
1279 <td valign="middle" align="left"><a href="#SEC_Contents" title="Table of contents"><img src="button-compass.png" border="0" alt="Contents: Table of Contents" align="middle" width="32"></a></td>
1280 <td valign="middle" align="left"><a href="#Index" title="Index"><img src="button-abc.png" border="0" alt="Index: Alphabetic index of definitions of concepts, keywords, and procedures" align="middle" width="32"></a></td>
1281 </tr></table>
1282 <a name="Storage-model-1"></a>
1283 <h2 class="section">3.4 Storage model</h2>
1284
1285
1286
1287 <p>Variables and objects such as pairs, vectors, and strings implicitly
1288 denote locations or sequences of locations. A string, for
1289 <a name="index-location"></a>
1290 example, denotes as many locations as there are characters in the string.
1291 (These locations need not correspond to a full machine word.) A new value may be
1292 stored into one of these locations using the <tt>string-set!</tt> procedure, but
1293 the string continues to denote the same locations as before.
1294 </p>
1295 <p>An object fetched from a location, by a variable reference or by
1296 a procedure such as <samp>car</samp>, <samp>vector-ref</samp>, or <samp>string-ref</samp>, is
1297 equivalent in the sense of <code>eqv?</code>
1298 (section see section <a href="#Equivalence-predicates">Equivalence predicates</a>)
1299 <a name="index-eqv_003f"></a>
1300 to the object last stored in the location before the fetch.
1301 </p>
1302 <p>Every location is marked to show whether it is in use.
1303 No variable or object ever refers to a location that is not in use.
1304 Whenever this report speaks of storage being allocated for a variable
1305 or object, what is meant is that an appropriate number of locations are
1306 chosen from the set of locations that are not in use, and the chosen
1307 locations are marked to indicate that they are now in use before the variable
1308 or object is made to denote them.
1309 </p>
1310 <p>In many systems it is desirable for constants (i.e. the values of
1311 <a name="index-constant"></a>
1312 literal expressions) to reside in read-only-memory. To express this, it is
1313 convenient to imagine that every object that denotes locations is associated
1314 with a flag telling whether that object is mutable or
1315 <a name="index-mutable"></a>
1316 immutable. In such systems literal constants and the strings
1317 <a name="index-immutable"></a>
1318 returned by <code>symbol-&gt;string</code> are immutable objects, while all objects
1319 <a name="index-symbol_002d_003estring"></a>
1320 created by the other procedures listed in this report are mutable. It is an
1321 error to attempt to store a new value into a location that is denoted by an
1322 immutable object.
1323 </p>
1324 <a name="Proper-tail-recursion"></a><hr size="1"><br/><br/><br/>
1325 <table cellpadding="1" cellspacing="1" border="0">
1326 <tr><td valign="middle" align="left"><a href="#Storage-model" title="Previous section in reading order"><img src="button-left.png" border="0" alt="Back: 3.4 Storage model" align="middle" width="32"></a></td>
1327 <td valign="middle" align="left"><a href="#Expressions" title="Next section in reading order"><img src="button-right.png" border="0" alt="Forward: 4. Expressions" align="middle" width="32"></a></td>
1328 <td valign="middle" align="left"> &nbsp; </td>
1329 <td valign="middle" align="left"><a href="#Basic-concepts" title="Beginning of this chapter or previous chapter"><img src="button-left-left.png" border="0" alt="FastBack: 3. Basic concepts" align="middle" width="32"></a></td>
1330 <td valign="middle" align="left"><a href="#Basic-concepts" title="Up section"><img src="button-up.png" border="0" alt="Up: 3. Basic concepts" align="middle" width="32"></a></td>
1331 <td valign="middle" align="left"><a href="#Expressions" title="Next chapter"><img src="button-right-right.png" border="0" alt="FastForward: 4. Expressions" align="middle" width="32"></a></td>
1332 <td valign="middle" align="left"><a href="#Top" title="Cover (top) of document"><img src="button-up-arrow.png" border="0" alt="Top: Revised(5) Report on the Algorithmic Language Scheme" align="middle" width="32"></a></td>
1333 <td valign="middle" align="left"><a href="#SEC_Contents" title="Table of contents"><img src="button-compass.png" border="0" alt="Contents: Table of Contents" align="middle" width="32"></a></td>
1334 <td valign="middle" align="left"><a href="#Index" title="Index"><img src="button-abc.png" border="0" alt="Index: Alphabetic index of definitions of concepts, keywords, and procedures" align="middle" width="32"></a></td>
1335 </tr></table>
1336 <a name="Proper-tail-recursion-1"></a>
1337 <h2 class="section">3.5 Proper tail recursion</h2>
1338
1339
1340
1341 <p>Implementations of Scheme are required to be
1342 <em>properly tail-recursive</em>.
1343 <a name="index-proper-tail-recursion"></a>
1344 Procedure calls that occur in certain syntactic
1345 contexts defined below are &lsquo;tail calls'. A Scheme implementation is
1346 properly tail-recursive if it supports an unbounded number of active
1347 tail calls. A call is <em>active</em> if the called procedure may still
1348 return. Note that this includes calls that may be returned from either
1349 by the current continuation or by continuations captured earlier by
1350 <samp>call-with-current-continuation</samp> that are later invoked.
1351 In the absence of captured continuations, calls could
1352 return at most once and the active calls would be those that had not
1353 yet returned.
1354 A formal definition of proper tail recursion can be found
1355 in [propertailrecursion].
1356 </p>
1357
1358 <blockquote><p><em>Rationale:</em>
1359 </p>
1360 <p>Intuitively, no space is needed for an active tail call because the
1361 continuation that is used in the tail call has the same semantics as the
1362 continuation passed to the procedure containing the call. Although an improper
1363 implementation might use a new continuation in the call, a return
1364 to this new continuation would be followed immediately by a return
1365 to the continuation passed to the procedure. A properly tail-recursive
1366 implementation returns to that continuation directly.
1367 </p>
1368 <p>Proper tail recursion was one of the central ideas in Steele and
1369 Sussman's original version of Scheme. Their first Scheme interpreter
1370 implemented both functions and actors. Control flow was expressed using
1371 actors, which differed from functions in that they passed their results
1372 on to another actor instead of returning to a caller. In the terminology
1373 of this section, each actor finished with a tail call to another actor.
1374 </p>
1375 <p>Steele and Sussman later observed that in their interpreter the code
1376 for dealing with actors was identical to that for functions and thus
1377 there was no need to include both in the language.
1378 </p>
1379 </blockquote>
1380
1381
1382 <p>A <em>tail call</em> is a procedure call that occurs
1383 <a name="index-tail-call"></a>
1384 in a <em>tail context</em>. Tail contexts are defined inductively. Note
1385 that a tail context is always determined with respect to a particular lambda
1386 expression.
1387 </p>
1388
1389
1390 <ul>
1391 <li>
1392 The last expression within the body of a lambda expression,
1393 shown as <span class="roman">&lt;tail expression&gt;</span> below, occurs in a tail context.
1394
1395 <table><tr><td>&nbsp;</td><td><pre class="format">(lambda &lt;formals&gt;
1396 &lt;definition&gt;* &lt;expression&gt;* &lt;tail expression&gt;)
1397 </pre></td></tr></table>
1398
1399
1400
1401 </li><li>
1402 If one of the following expressions is in a tail context,
1403 then the subexpressions shown as &lt;tail expression&gt; are in a tail context.
1404 These were derived from rules in the grammar given in
1405 chapter <a href="#Formal-syntax-and-semantics">Formal syntax and semantics</a> by replacing some occurrences of &lt;expression&gt;
1406 with &lt;tail expression&gt;. Only those rules that contain tail contexts
1407 are shown here.
1408
1409
1410 <table><tr><td>&nbsp;</td><td><pre class="format">(if &lt;expression&gt; &lt;tail expression&gt; &lt;tail expression&gt;)
1411 (if &lt;expression&gt; &lt;tail expression&gt;)
1412
1413 (cond &lt;cond clause&gt;+)
1414 (cond &lt;cond clause&gt;* (else &lt;tail sequence&gt;))
1415
1416 (case &lt;expression&gt;
1417 &lt;case clause&gt;+)
1418 (case &lt;expression&gt;
1419 &lt;case clause&gt;*
1420 (else &lt;tail sequence&gt;))
1421
1422 (and &lt;expression&gt;* &lt;tail expression&gt;)
1423 (or &lt;expression&gt;* &lt;tail expression&gt;)
1424
1425 (let (&lt;binding spec&gt;*) &lt;tail body&gt;)
1426 (let &lt;variable&gt; (&lt;binding spec&gt;*) &lt;tail body&gt;)
1427 (let* (&lt;binding spec&gt;*) &lt;tail body&gt;)
1428 (letrec (&lt;binding spec&gt;*) &lt;tail body&gt;)
1429
1430 (let-syntax (&lt;syntax spec&gt;*) &lt;tail body&gt;)
1431 (letrec-syntax (&lt;syntax spec&gt;*) &lt;tail body&gt;)
1432
1433 (begin &lt;tail sequence&gt;)
1434
1435 (do (&lt;iteration spec&gt;*)
1436 (&lt;test&gt; &lt;tail sequence&gt;)
1437 &lt;expression&gt;*)
1438
1439 <span class="roman">where</span>
1440
1441 &lt;cond clause&gt; &ndash;&gt; (&lt;test&gt; &lt;tail sequence&gt;)
1442 &lt;case clause&gt; &ndash;&gt; ((&lt;datum&gt;*) &lt;tail sequence&gt;)
1443
1444 &lt;tail body&gt; &ndash;&gt; &lt;definition&gt;* &lt;tail sequence&gt;
1445 &lt;tail sequence&gt; &ndash;&gt; &lt;expression&gt;* &lt;tail expression&gt;
1446 </pre></td></tr></table>
1447
1448
1449
1450 </li><li>
1451 If a <samp>cond</samp> expression is in a tail context, and has a clause of
1452 the form <samp>(<span class="roman">&lt;expression1&gt;</span> =&gt; <span class="roman">&lt;expression2&gt;</span>)</samp>
1453 then the (implied) call to
1454 the procedure that results from the evaluation of <span class="roman">&lt;expression2&gt;</span> is in a
1455 tail context. <span class="roman">&lt;expression2&gt;</span> itself is not in a tail context.
1456
1457
1458 </li></ul>
1459
1460
1461 <p>Certain built-in procedures are also required to perform tail calls.
1462 The first argument passed to <code>apply</code> and to
1463 <a name="index-apply"></a>
1464 <code>call-with-current-continuation</code>, and the second argument passed to
1465 <a name="index-call_002dwith_002dcurrent_002dcontinuation"></a>
1466 <code>call-with-values</code>, must be called via a tail call.
1467 <a name="index-call_002dwith_002dvalues"></a>
1468 Similarly, <code>eval</code> must evaluate its argument as if it
1469 <a name="index-eval"></a>
1470 were in tail position within the <code>eval</code> procedure.
1471 <a name="index-eval-1"></a>
1472 </p>
1473 <p>In the following example the only tail call is the call to <samp>f</samp>.
1474 None of the calls to <samp>g</samp> or <samp>h</samp> are tail calls. The reference to
1475 <samp>x</samp> is in a tail context, but it is not a call and thus is not a
1476 tail call.
1477 </p>
1478 <table><tr><td>&nbsp;</td><td><pre class="example">
1479 (lambda ()
1480 (if (g)
1481 (let ((x (h)))
1482 x)
1483 (and (g) (f))))
1484 </pre></td></tr></table>
1485
1486
1487
1488 <blockquote><p><em>Note:</em>
1489 Implementations are allowed, but not required, to
1490 recognize that some non-tail calls, such as the call to <samp>h</samp>
1491 above, can be evaluated as though they were tail calls.
1492 In the example above, the <samp>let</samp> expression could be compiled
1493 as a tail call to <samp>h</samp>. (The possibility of <samp>h</samp> returning
1494 an unexpected number of values can be ignored, because in that
1495 case the effect of the <samp>let</samp> is explicitly unspecified and
1496 implementation-dependent.)
1497 </p></blockquote>
1498
1499
1500
1501
1502 <a name="Expressions"></a><hr size="1"><br/><br/><br/>
1503 <table cellpadding="1" cellspacing="1" border="0">
1504 <tr><td valign="middle" align="left"><a href="#Proper-tail-recursion" title="Previous section in reading order"><img src="button-left.png" border="0" alt="Back: 3.5 Proper tail recursion" align="middle" width="32"></a></td>
1505 <td valign="middle" align="left"><a href="#Primitive-expression-types" title="Next section in reading order"><img src="button-right.png" border="0" alt="Forward: 4.1 Primitive expression types" align="middle" width="32"></a></td>
1506 <td valign="middle" align="left"> &nbsp; </td>
1507 <td valign="middle" align="left"><a href="#Basic-concepts" title="Beginning of this chapter or previous chapter"><img src="button-left-left.png" border="0" alt="FastBack: 3. Basic concepts" align="middle" width="32"></a></td>
1508 <td valign="middle" align="left"><a href="#Top" title="Up section"><img src="button-up.png" border="0" alt="Up: Revised(5) Report on the Algorithmic Language Scheme" align="middle" width="32"></a></td>
1509 <td valign="middle" align="left"><a href="#Program-structure" title="Next chapter"><img src="button-right-right.png" border="0" alt="FastForward: 5. Program structure" align="middle" width="32"></a></td>
1510 <td valign="middle" align="left"><a href="#Top" title="Cover (top) of document"><img src="button-up-arrow.png" border="0" alt="Top: Revised(5) Report on the Algorithmic Language Scheme" align="middle" width="32"></a></td>
1511 <td valign="middle" align="left"><a href="#SEC_Contents" title="Table of contents"><img src="button-compass.png" border="0" alt="Contents: Table of Contents" align="middle" width="32"></a></td>
1512 <td valign="middle" align="left"><a href="#Index" title="Index"><img src="button-abc.png" border="0" alt="Index: Alphabetic index of definitions of concepts, keywords, and procedures" align="middle" width="32"></a></td>
1513 </tr></table>
1514 <a name="Expressions-2"></a>
1515 <h1 class="chapter">4. Expressions</h1>
1516
1517 <table class="menu" border="0" cellspacing="0">
1518 <tr><td align="left" valign="top"><a href="#Primitive-expression-types">4.1 Primitive expression types</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
1519 </td></tr>
1520 <tr><td align="left" valign="top"><a href="#Derived-expression-types">4.2 Derived expression types</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
1521 </td></tr>
1522 <tr><td align="left" valign="top"><a href="#Macros">4.3 Macros</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
1523 </td></tr>
1524 </table>
1525
1526
1527
1528
1529
1530 <p>Expression types are categorized as <em>primitive</em> or <em>derived</em>.
1531 Primitive expression types include variables and procedure calls.
1532 Derived expression types are not semantically primitive, but can instead
1533 be defined as macros.
1534 With the exception of <samp>quasiquote</samp>, whose macro definition is complex,
1535 the derived expressions are classified as library features.
1536 Suitable definitions are given in section <a href="#Derived-expression-type">Derived expression types</a>.
1537 </p>
1538 <a name="Primitive-expression-types"></a><hr size="1"><br/><br/><br/>
1539 <table cellpadding="1" cellspacing="1" border="0">
1540 <tr><td valign="middle" align="left"><a href="#Expressions" title="Previous section in reading order"><img src="button-left.png" border="0" alt="Back: 4. Expressions" align="middle" width="32"></a></td>
1541 <td valign="middle" align="left"><a href="#Variable-references" title="Next section in reading order"><img src="button-right.png" border="0" alt="Forward: 4.1.1 Variable references" align="middle" width="32"></a></td>
1542 <td valign="middle" align="left"> &nbsp; </td>
1543 <td valign="middle" align="left"><a href="#Expressions" title="Beginning of this chapter or previous chapter"><img src="button-left-left.png" border="0" alt="FastBack: 4. Expressions" align="middle" width="32"></a></td>
1544 <td valign="middle" align="left"><a href="#Expressions" title="Up section"><img src="button-up.png" border="0" alt="Up: 4. Expressions" align="middle" width="32"></a></td>
1545 <td valign="middle" align="left"><a href="#Program-structure" title="Next chapter"><img src="button-right-right.png" border="0" alt="FastForward: 5. Program structure" align="middle" width="32"></a></td>
1546 <td valign="middle" align="left"><a href="#Top" title="Cover (top) of document"><img src="button-up-arrow.png" border="0" alt="Top: Revised(5) Report on the Algorithmic Language Scheme" align="middle" width="32"></a></td>
1547 <td valign="middle" align="left"><a href="#SEC_Contents" title="Table of contents"><img src="button-compass.png" border="0" alt="Contents: Table of Contents" align="middle" width="32"></a></td>
1548 <td valign="middle" align="left"><a href="#Index" title="Index"><img src="button-abc.png" border="0" alt="Index: Alphabetic index of definitions of concepts, keywords, and procedures" align="middle" width="32"></a></td>
1549 </tr></table>
1550 <a name="Primitive-expression-types-1"></a>
1551 <h2 class="section">4.1 Primitive expression types</h2>
1552
1553 <table class="menu" border="0" cellspacing="0">
1554 <tr><td align="left" valign="top"><a href="#Variable-references">4.1.1 Variable references</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
1555 </td></tr>
1556 <tr><td align="left" valign="top"><a href="#Literal-expressions">4.1.2 Literal expressions</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
1557 </td></tr>
1558 <tr><td align="left" valign="top"><a href="#Procedure-calls">4.1.3 Procedure calls</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
1559 </td></tr>
1560 <tr><td align="left" valign="top"><a href="#Procedures">4.1.4 Procedures</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
1561 </td></tr>
1562 <tr><td align="left" valign="top"><a href="#Conditionals">4.1.5 Conditionals</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
1563 </td></tr>
1564 <tr><td align="left" valign="top"><a href="#Assignments">4.1.6 Assignments</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
1565 </td></tr>
1566 </table>
1567
1568
1569
1570 <a name="Variable-references"></a><hr size="1"><br/><br/><br/>
1571 <table cellpadding="1" cellspacing="1" border="0">
1572 <tr><td valign="middle" align="left"><a href="#Primitive-expression-types" title="Previous section in reading order"><img src="button-left.png" border="0" alt="Back: 4.1 Primitive expression types" align="middle" width="32"></a></td>
1573 <td valign="middle" align="left"><a href="#Literal-expressions" title="Next section in reading order"><img src="button-right.png" border="0" alt="Forward: 4.1.2 Literal expressions" align="middle" width="32"></a></td>
1574 <td valign="middle" align="left"> &nbsp; </td>
1575 <td valign="middle" align="left"><a href="#Expressions" title="Beginning of this chapter or previous chapter"><img src="button-left-left.png" border="0" alt="FastBack: 4. Expressions" align="middle" width="32"></a></td>
1576 <td valign="middle" align="left"><a href="#Primitive-expression-types" title="Up section"><img src="button-up.png" border="0" alt="Up: 4.1 Primitive expression types" align="middle" width="32"></a></td>
1577 <td valign="middle" align="left"><a href="#Program-structure" title="Next chapter"><img src="button-right-right.png" border="0" alt="FastForward: 5. Program structure" align="middle" width="32"></a></td>
1578 <td valign="middle" align="left"><a href="#Top" title="Cover (top) of document"><img src="button-up-arrow.png" border="0" alt="Top: Revised(5) Report on the Algorithmic Language Scheme" align="middle" width="32"></a></td>
1579 <td valign="middle" align="left"><a href="#SEC_Contents" title="Table of contents"><img src="button-compass.png" border="0" alt="Contents: Table of Contents" align="middle" width="32"></a></td>
1580 <td valign="middle" align="left"><a href="#Index" title="Index"><img src="button-abc.png" border="0" alt="Index: Alphabetic index of definitions of concepts, keywords, and procedures" align="middle" width="32"></a></td>
1581 </tr></table>
1582 <a name="Variable-references-1"></a>
1583 <h3 class="subsection">4.1.1 Variable references</h3>
1584
1585
1586
1587 <table width="100%"><tr><td align="left"> <code><b><span class="roman">&lt;variable&gt;</span></b></code></td><td align="right">syntax</td></tr></table>
1588
1589
1590 <p>An expression consisting of a variable
1591 <a name="index-variable-2"></a>
1592 (section see section <a href="#Variables_003b-syntactic-keywords_003b-and-regions">Variables; syntactic keywords; and regions</a>) is a variable reference. The value of
1593 the variable reference is the value stored in the location to which the
1594 variable is bound. It is an error to reference an
1595 unbound variable.
1596 <a name="index-unbound-1"></a>
1597 </p>
1598
1599 <table><tr><td>&nbsp;</td><td><pre class="format">(define x 28)
1600 x ==&gt; 28
1601 </pre></td></tr></table>
1602
1603
1604
1605 <a name="Literal-expressions"></a><hr size="1"><br/><br/><br/>
1606 <table cellpadding="1" cellspacing="1" border="0">
1607 <tr><td valign="middle" align="left"><a href="#Variable-references" title="Previous section in reading order"><img src="button-left.png" border="0" alt="Back: 4.1.1 Variable references" align="middle" width="32"></a></td>
1608 <td valign="middle" align="left"><a href="#Procedure-calls" title="Next section in reading order"><img src="button-right.png" border="0" alt="Forward: 4.1.3 Procedure calls" align="middle" width="32"></a></td>
1609 <td valign="middle" align="left"> &nbsp; </td>
1610 <td valign="middle" align="left"><a href="#Expressions" title="Beginning of this chapter or previous chapter"><img src="button-left-left.png" border="0" alt="FastBack: 4. Expressions" align="middle" width="32"></a></td>
1611 <td valign="middle" align="left"><a href="#Primitive-expression-types" title="Up section"><img src="button-up.png" border="0" alt="Up: 4.1 Primitive expression types" align="middle" width="32"></a></td>
1612 <td valign="middle" align="left"><a href="#Program-structure" title="Next chapter"><img src="button-right-right.png" border="0" alt="FastForward: 5. Program structure" align="middle" width="32"></a></td>
1613 <td valign="middle" align="left"><a href="#Top" title="Cover (top) of document"><img src="button-up-arrow.png" border="0" alt="Top: Revised(5) Report on the Algorithmic Language Scheme" align="middle" width="32"></a></td>
1614 <td valign="middle" align="left"><a href="#SEC_Contents" title="Table of contents"><img src="button-compass.png" border="0" alt="Contents: Table of Contents" align="middle" width="32"></a></td>
1615 <td valign="middle" align="left"><a href="#Index" title="Index"><img src="button-abc.png" border="0" alt="Index: Alphabetic index of definitions of concepts, keywords, and procedures" align="middle" width="32"></a></td>
1616 </tr></table>
1617 <a name="Literal-expressions-1"></a>
1618 <h3 class="subsection">4.1.2 Literal expressions</h3>
1619
1620
1621
1622
1623 <a name="Definition_of_quote"></a><a name="Syntax_quote"></a><a name="index-quote"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Syntax_quote">quote</a></b></code><i> <span class="roman">&lt;datum&gt;</span></i><code>)</code></td><td align="right">syntax</td></tr></table>
1624 <a name="index-_0027"></a><table width="100%"><tr><td align="left"> <code><b><tt>'</tt></b></code><i><span class="roman">&lt;datum&gt;</span></i></td><td align="right">syntax</td></tr></table>
1625 <table width="100%"><tr><td align="left"> <code><b><span class="roman">&lt;constant&gt;</span></b></code></td><td align="right">syntax</td></tr></table>
1626
1627
1628 <p><samp>(quote <span class="roman">&lt;datum&gt;</span>)</samp> evaluates to <span class="roman">&lt;datum&gt;</span>.
1629 <a name="index-_0027-1"></a>
1630 <span class="roman">&lt;Datum&gt;</span>
1631 may be any external representation of a Scheme object (see
1632 section see section <a href="#External-representations">External representations</a>). This notation is used to include literal
1633 constants in Scheme code.
1634 </p>
1635
1636 <table><tr><td>&nbsp;</td><td><pre class="format">
1637 (quote a) ==&gt; a
1638 (quote #(a b c)) ==&gt; #(a b c)
1639 (quote (+ 1 2)) ==&gt; (+ 1 2)
1640 </pre></td></tr></table>
1641
1642
1643 <p><samp>(quote <span class="roman">&lt;datum&gt;</span>)</samp> may be abbreviated as
1644 <tt>'</tt><span class="roman">&lt;datum&gt;</span>. The two notations are equivalent in all
1645 respects.
1646 </p>
1647
1648 <table><tr><td>&nbsp;</td><td><pre class="format">'a ==&gt; a
1649 '#(a b c) ==&gt; #(a b c)
1650 '() ==&gt; ()
1651 '(+ 1 2) ==&gt; (+ 1 2)
1652 '(quote a) ==&gt; (quote a)
1653 ''a ==&gt; (quote a)
1654 </pre></td></tr></table>
1655
1656
1657 <p>Numerical constants, string constants, character constants, and boolean
1658 constants evaluate &ldquo;to themselves&rdquo;; they need not be quoted.
1659 </p>
1660
1661 <table><tr><td>&nbsp;</td><td><pre class="format">'&quot;abc&quot; ==&gt; &quot;abc&quot;
1662 &quot;abc&quot; ==&gt; &quot;abc&quot;
1663 '145932 ==&gt; 145932
1664 145932 ==&gt; 145932
1665 '#t ==&gt; #t
1666 #t ==&gt; #t
1667 </pre></td></tr></table>
1668
1669
1670 <p>As noted in section <a href="#Storage-model">Storage model</a>, it is an error to alter a constant
1671 (i.e. the value of a literal expression) using a mutation procedure like
1672 <samp>set-car!</samp> or <samp>string-set!</samp>.
1673 </p>
1674
1675
1676
1677 <a name="Procedure-calls"></a><hr size="1"><br/><br/><br/>
1678 <table cellpadding="1" cellspacing="1" border="0">
1679 <tr><td valign="middle" align="left"><a href="#Literal-expressions" title="Previous section in reading order"><img src="button-left.png" border="0" alt="Back: 4.1.2 Literal expressions" align="middle" width="32"></a></td>
1680 <td valign="middle" align="left"><a href="#Procedures" title="Next section in reading order"><img src="button-right.png" border="0" alt="Forward: 4.1.4 Procedures" align="middle" width="32"></a></td>
1681 <td valign="middle" align="left"> &nbsp; </td>
1682 <td valign="middle" align="left"><a href="#Expressions" title="Beginning of this chapter or previous chapter"><img src="button-left-left.png" border="0" alt="FastBack: 4. Expressions" align="middle" width="32"></a></td>
1683 <td valign="middle" align="left"><a href="#Primitive-expression-types" title="Up section"><img src="button-up.png" border="0" alt="Up: 4.1 Primitive expression types" align="middle" width="32"></a></td>
1684 <td valign="middle" align="left"><a href="#Program-structure" title="Next chapter"><img src="button-right-right.png" border="0" alt="FastForward: 5. Program structure" align="middle" width="32"></a></td>
1685 <td valign="middle" align="left"><a href="#Top" title="Cover (top) of document"><img src="button-up-arrow.png" border="0" alt="Top: Revised(5) Report on the Algorithmic Language Scheme" align="middle" width="32"></a></td>
1686 <td valign="middle" align="left"><a href="#SEC_Contents" title="Table of contents"><img src="button-compass.png" border="0" alt="Contents: Table of Contents" align="middle" width="32"></a></td>
1687 <td valign="middle" align="left"><a href="#Index" title="Index"><img src="button-abc.png" border="0" alt="Index: Alphabetic index of definitions of concepts, keywords, and procedures" align="middle" width="32"></a></td>
1688 </tr></table>
1689 <a name="Procedure-calls-1"></a>
1690 <h3 class="subsection">4.1.3 Procedure calls</h3>
1691
1692
1693
1694 <table width="100%"><tr><td align="left"> <code>(</code><code><b><span class="roman">&lt;operator&gt;</span></b></code><i> <span class="roman">&lt;operand1&gt;</span> &hellip;</i><code>)</code></td><td align="right">syntax</td></tr></table>
1695
1696
1697 <p>A procedure call is written by simply enclosing in parentheses
1698 expressions for the procedure to be called and the arguments to be
1699 passed to it. The operator and operand expressions are evaluated (in an
1700 unspecified order) and the resulting procedure is passed the resulting
1701 arguments.
1702 <a name="index-procedure-call"></a>
1703 <a name="index-call"></a>
1704 </p>
1705 <table><tr><td>&nbsp;</td><td><pre class="format">(+ 3 4) ==&gt; 7
1706 ((if #f + *) 3 4) ==&gt; 12
1707 </pre></td></tr></table>
1708
1709
1710 <p>A number of procedures are available as the values of variables in the
1711 initial environment; for example, the addition and multiplication
1712 procedures in the above examples are the values of the variables <samp>+</samp>
1713 and <samp>*</samp>. New procedures are created by evaluating lambda expressions
1714 (see section see section <a href="#Procedures">Procedures</a>).
1715 </p>
1716
1717 <p>Procedure calls may return any number of values (see <code>values</code> in
1718 <a name="index-values"></a>
1719 section see section <a href="#Control-features">Control features</a>). With the exception of <samp>values</samp>
1720 the procedures available in the initial environment return one
1721 value or, for procedures such as <samp>apply</samp>, pass on the values returned
1722 by a call to one of their arguments.
1723 </p>
1724 <p>Procedure calls are also called <em>combinations</em>.
1725 </p>
1726 <a name="index-combination"></a>
1727
1728
1729 <blockquote><p><em>Note:</em> In contrast to other dialects of Lisp, the order of
1730 evaluation is unspecified, and the operator expression and the operand
1731 expressions are always evaluated with the same evaluation rules.
1732 </p></blockquote>
1733
1734
1735
1736 <blockquote><p><em>Note:</em>
1737 Although the order of evaluation is otherwise unspecified, the effect of
1738 any concurrent evaluation of the operator and operand expressions is
1739 constrained to be consistent with some sequential order of evaluation.
1740 The order of evaluation may be chosen differently for each procedure call.
1741 </p></blockquote>
1742
1743
1744
1745 <blockquote><p><em>Note:</em> In many dialects of Lisp, the empty combination, <tt>()</tt>, is a legitimate expression. In Scheme, combinations must have at
1746 least one subexpression, so <tt>()</tt> is not a syntactically valid
1747 expression.
1748 </p>
1749 </blockquote>
1750
1751
1752
1753
1754
1755
1756
1757 <a name="Procedures"></a><hr size="1"><br/><br/><br/>
1758 <table cellpadding="1" cellspacing="1" border="0">
1759 <tr><td valign="middle" align="left"><a href="#Procedure-calls" title="Previous section in reading order"><img src="button-left.png" border="0" alt="Back: 4.1.3 Procedure calls" align="middle" width="32"></a></td>
1760 <td valign="middle" align="left"><a href="#Conditionals" title="Next section in reading order"><img src="button-right.png" border="0" alt="Forward: 4.1.5 Conditionals" align="middle" width="32"></a></td>
1761 <td valign="middle" align="left"> &nbsp; </td>
1762 <td valign="middle" align="left"><a href="#Expressions" title="Beginning of this chapter or previous chapter"><img src="button-left-left.png" border="0" alt="FastBack: 4. Expressions" align="middle" width="32"></a></td>
1763 <td valign="middle" align="left"><a href="#Primitive-expression-types" title="Up section"><img src="button-up.png" border="0" alt="Up: 4.1 Primitive expression types" align="middle" width="32"></a></td>
1764 <td valign="middle" align="left"><a href="#Program-structure" title="Next chapter"><img src="button-right-right.png" border="0" alt="FastForward: 5. Program structure" align="middle" width="32"></a></td>
1765 <td valign="middle" align="left"><a href="#Top" title="Cover (top) of document"><img src="button-up-arrow.png" border="0" alt="Top: Revised(5) Report on the Algorithmic Language Scheme" align="middle" width="32"></a></td>
1766 <td valign="middle" align="left"><a href="#SEC_Contents" title="Table of contents"><img src="button-compass.png" border="0" alt="Contents: Table of Contents" align="middle" width="32"></a></td>
1767 <td valign="middle" align="left"><a href="#Index" title="Index"><img src="button-abc.png" border="0" alt="Index: Alphabetic index of definitions of concepts, keywords, and procedures" align="middle" width="32"></a></td>
1768 </tr></table>
1769 <a name="Procedures-2"></a>
1770 <h3 class="subsection">4.1.4 Procedures</h3>
1771
1772
1773
1774
1775 <a name="Definition_of_lambda"></a><a name="Syntax_lambda"></a><a name="index-lambda"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Syntax_lambda">lambda</a></b></code><i> <span class="roman">&lt;formals&gt;</span> <span class="roman">&lt;body&gt;</span></i><code>)</code></td><td align="right">syntax</td></tr></table>
1776
1777 <p><em>Syntax:</em>
1778 <span class="roman">&lt;Formals&gt;</span> should be a formal arguments list as described below,
1779 and <span class="roman">&lt;body&gt;</span> should be a sequence of one or more expressions.
1780 </p>
1781 <p><em>Semantics:</em>
1782 A lambda expression evaluates to a procedure. The environment in
1783 effect when the lambda expression was evaluated is remembered as part of the
1784 procedure. When the procedure is later called with some actual
1785 arguments, the environment in which the lambda expression was evaluated will
1786 be extended by binding the variables in the formal argument list to
1787 fresh locations, the corresponding actual argument values will be stored
1788 in those locations, and the expressions in the body of the lambda expression
1789 will be evaluated sequentially in the extended environment.
1790 The result(s) of the last expression in the body will be returned as
1791 the result(s) of the procedure call.
1792 </p>
1793
1794 <table><tr><td>&nbsp;</td><td><pre class="format">(lambda (x) (+ x x)) ==&gt; <em></em>a procedure
1795 ((lambda (x) (+ x x)) 4) ==&gt; 8
1796
1797 (define reverse-subtract
1798 (lambda (x y) (- y x)))
1799 (reverse-subtract 7 10) ==&gt; 3
1800
1801 (define add4
1802 (let ((x 4))
1803 (lambda (y) (+ x y))))
1804 (add4 6) ==&gt; 10
1805 </pre></td></tr></table>
1806
1807
1808 <p><span class="roman">&lt;Formals&gt;</span> should have one of the following forms:
1809 </p>
1810
1811
1812 <ul>
1813 <li>
1814 <tt>(<span class="roman">&lt;variable1&gt;</span> &hellip;)</tt>:
1815 The procedure takes a fixed number of arguments; when the procedure is
1816 called, the arguments will be stored in the bindings of the
1817 corresponding variables.
1818
1819 </li><li>
1820 <span class="roman">&lt;variable&gt;</span>:
1821 The procedure takes any number of arguments; when the procedure is
1822 called, the sequence of actual arguments is converted into a newly
1823 allocated list, and the list is stored in the binding of the
1824 <span class="roman">&lt;variable&gt;</span>.
1825
1826 </li><li>
1827 <tt>(<span class="roman">&lt;variable1&gt;</span> &hellip; <span class="roman">&lt;variable_n&gt;</span> <b>.</b>
1828 <span class="roman">&lt;variable_n+1&gt;</span>)</tt>:
1829 If a space-delimited period precedes the last variable, then
1830 the procedure takes n or more arguments, where n is the
1831 number of formal arguments before the period (there must
1832 be at least one).
1833 The value stored in the binding of the last variable will be a
1834 newly allocated
1835 list of the actual arguments left over after all the other actual
1836 arguments have been matched up against the other formal arguments.
1837
1838 </li></ul>
1839
1840
1841 <p>It is an error for a <span class="roman">&lt;variable&gt;</span> to appear more than once in
1842 <span class="roman">&lt;formals&gt;</span>.
1843 </p>
1844
1845 <table><tr><td>&nbsp;</td><td><pre class="format">((lambda x x) 3 4 5 6) ==&gt; (3 4 5 6)
1846 ((lambda (x y . z) z)
1847 3 4 5 6) ==&gt; (5 6)
1848 </pre></td></tr></table>
1849
1850
1851 <p>Each procedure created as the result of evaluating a lambda expression is
1852 (conceptually) tagged
1853 with a storage location, in order to make <code>eqv?</code> and
1854 <a name="index-eqv_003f-1"></a>
1855 <code>eq?</code> work on procedures (see section see section <a href="#Equivalence-predicates">Equivalence predicates</a>).
1856 <a name="index-eq_003f"></a>
1857 </p>
1858
1859
1860
1861 <a name="Conditionals"></a><hr size="1"><br/><br/><br/>
1862 <table cellpadding="1" cellspacing="1" border="0">
1863 <tr><td valign="middle" align="left"><a href="#Procedures" title="Previous section in reading order"><img src="button-left.png" border="0" alt="Back: 4.1.4 Procedures" align="middle" width="32"></a></td>
1864 <td valign="middle" align="left"><a href="#Assignments" title="Next section in reading order"><img src="button-right.png" border="0" alt="Forward: 4.1.6 Assignments" align="middle" width="32"></a></td>
1865 <td valign="middle" align="left"> &nbsp; </td>
1866 <td valign="middle" align="left"><a href="#Expressions" title="Beginning of this chapter or previous chapter"><img src="button-left-left.png" border="0" alt="FastBack: 4. Expressions" align="middle" width="32"></a></td>
1867 <td valign="middle" align="left"><a href="#Primitive-expression-types" title="Up section"><img src="button-up.png" border="0" alt="Up: 4.1 Primitive expression types" align="middle" width="32"></a></td>
1868 <td valign="middle" align="left"><a href="#Program-structure" title="Next chapter"><img src="button-right-right.png" border="0" alt="FastForward: 5. Program structure" align="middle" width="32"></a></td>
1869 <td valign="middle" align="left"><a href="#Top" title="Cover (top) of document"><img src="button-up-arrow.png" border="0" alt="Top: Revised(5) Report on the Algorithmic Language Scheme" align="middle" width="32"></a></td>
1870 <td valign="middle" align="left"><a href="#SEC_Contents" title="Table of contents"><img src="button-compass.png" border="0" alt="Contents: Table of Contents" align="middle" width="32"></a></td>
1871 <td valign="middle" align="left"><a href="#Index" title="Index"><img src="button-abc.png" border="0" alt="Index: Alphabetic index of definitions of concepts, keywords, and procedures" align="middle" width="32"></a></td>
1872 </tr></table>
1873 <a name="Conditionals-1"></a>
1874 <h3 class="subsection">4.1.5 Conditionals</h3>
1875
1876
1877
1878 <a name="Definition_of_if"></a><a name="Syntax_if"></a><a name="index-if"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Syntax_if">if</a></b></code><i> <span class="roman">&lt;test&gt;</span> <span class="roman">&lt;consequent&gt;</span> <span class="roman">&lt;alternate&gt;</span></i><code>)</code></td><td align="right">syntax</td></tr></table>
1879 <a name="Definition_of_if"></a><a name="Syntax_if"></a><a name="index-if-1"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Syntax_if">if</a></b></code><i> <span class="roman">&lt;test&gt;</span> <span class="roman">&lt;consequent&gt;</span></i><code>)</code></td><td align="right">syntax</td></tr></table>
1880
1881 <p><em>Syntax:</em>
1882 <span class="roman">&lt;Test&gt;</span>, <span class="roman">&lt;consequent&gt;</span>, and <span class="roman">&lt;alternate&gt;</span> may be arbitrary
1883 expressions.
1884 </p>
1885 <p><em>Semantics:</em>
1886 An <samp>if</samp> expression is evaluated as follows: first,
1887 <span class="roman">&lt;test&gt;</span> is evaluated. If it yields a true value (see
1888 <a name="index-true-1"></a>
1889 section see section <a href="#Booleans">Booleans</a>), then <span class="roman">&lt;consequent&gt;</span> is evaluated and
1890 its value(s) is(are) returned. Otherwise <span class="roman">&lt;alternate&gt;</span> is evaluated and its
1891 value(s) is(are) returned. If <span class="roman">&lt;test&gt;</span> yields a false value and no
1892 <span class="roman">&lt;alternate&gt;</span> is specified, then the result of the expression is
1893 unspecified.
1894 </p>
1895
1896 <table><tr><td>&nbsp;</td><td><pre class="format">(if (&gt; 3 2) 'yes 'no) ==&gt; yes
1897 (if (&gt; 2 3) 'yes 'no) ==&gt; no
1898 (if (&gt; 3 2)
1899 (- 3 2)
1900 (+ 3 2)) ==&gt; 1
1901 </pre></td></tr></table>
1902
1903
1904
1905
1906
1907 <a name="Assignments"></a><hr size="1"><br/><br/><br/>
1908 <table cellpadding="1" cellspacing="1" border="0">
1909 <tr><td valign="middle" align="left"><a href="#Conditionals" title="Previous section in reading order"><img src="button-left.png" border="0" alt="Back: 4.1.5 Conditionals" align="middle" width="32"></a></td>
1910 <td valign="middle" align="left"><a href="#Derived-expression-types" title="Next section in reading order"><img src="button-right.png" border="0" alt="Forward: 4.2 Derived expression types" align="middle" width="32"></a></td>
1911 <td valign="middle" align="left"> &nbsp; </td>
1912 <td valign="middle" align="left"><a href="#Expressions" title="Beginning of this chapter or previous chapter"><img src="button-left-left.png" border="0" alt="FastBack: 4. Expressions" align="middle" width="32"></a></td>
1913 <td valign="middle" align="left"><a href="#Primitive-expression-types" title="Up section"><img src="button-up.png" border="0" alt="Up: 4.1 Primitive expression types" align="middle" width="32"></a></td>
1914 <td valign="middle" align="left"><a href="#Program-structure" title="Next chapter"><img src="button-right-right.png" border="0" alt="FastForward: 5. Program structure" align="middle" width="32"></a></td>
1915 <td valign="middle" align="left"><a href="#Top" title="Cover (top) of document"><img src="button-up-arrow.png" border="0" alt="Top: Revised(5) Report on the Algorithmic Language Scheme" align="middle" width="32"></a></td>
1916 <td valign="middle" align="left"><a href="#SEC_Contents" title="Table of contents"><img src="button-compass.png" border="0" alt="Contents: Table of Contents" align="middle" width="32"></a></td>
1917 <td valign="middle" align="left"><a href="#Index" title="Index"><img src="button-abc.png" border="0" alt="Index: Alphabetic index of definitions of concepts, keywords, and procedures" align="middle" width="32"></a></td>
1918 </tr></table>
1919 <a name="Assignments-1"></a>
1920 <h3 class="subsection">4.1.6 Assignments</h3>
1921
1922
1923
1924
1925 <a name="Definition_of_set!"></a><a name="Syntax_set!"></a><a name="index-set_0021"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Syntax_set!">set!</a></b></code><i> <span class="roman">&lt;variable&gt;</span> <span class="roman">&lt;expression&gt;</span></i><code>)</code></td><td align="right">syntax</td></tr></table>
1926
1927 <p><span class="roman">&lt;Expression&gt;</span> is evaluated, and the resulting value is stored in
1928 the location to which <span class="roman">&lt;variable&gt;</span> is bound. <span class="roman">&lt;Variable&gt;</span> must
1929 be bound either in some region enclosing the <samp>set!</samp> expression
1930 <a name="index-region-1"></a>
1931 or at top level. The result of the <samp>set!</samp> expression is
1932 unspecified.
1933 </p>
1934
1935 <table><tr><td>&nbsp;</td><td><pre class="format">(define x 2)
1936 (+ x 1) ==&gt; 3
1937 (set! x 4) ==&gt; <em>unspecified</em>
1938 (+ x 1) ==&gt; 5
1939 </pre></td></tr></table>
1940
1941
1942
1943
1944
1945 <a name="Derived-expression-types"></a><hr size="1"><br/><br/><br/>
1946 <table cellpadding="1" cellspacing="1" border="0">
1947 <tr><td valign="middle" align="left"><a href="#Assignments" title="Previous section in reading order"><img src="button-left.png" border="0" alt="Back: 4.1.6 Assignments" align="middle" width="32"></a></td>
1948 <td valign="middle" align="left"><a href="#Conditional" title="Next section in reading order"><img src="button-right.png" border="0" alt="Forward: 4.2.1 Conditionals" align="middle" width="32"></a></td>
1949 <td valign="middle" align="left"> &nbsp; </td>
1950 <td valign="middle" align="left"><a href="#Expressions" title="Beginning of this chapter or previous chapter"><img src="button-left-left.png" border="0" alt="FastBack: 4. Expressions" align="middle" width="32"></a></td>
1951 <td valign="middle" align="left"><a href="#Expressions" title="Up section"><img src="button-up.png" border="0" alt="Up: 4. Expressions" align="middle" width="32"></a></td>
1952 <td valign="middle" align="left"><a href="#Program-structure" title="Next chapter"><img src="button-right-right.png" border="0" alt="FastForward: 5. Program structure" align="middle" width="32"></a></td>
1953 <td valign="middle" align="left"><a href="#Top" title="Cover (top) of document"><img src="button-up-arrow.png" border="0" alt="Top: Revised(5) Report on the Algorithmic Language Scheme" align="middle" width="32"></a></td>
1954 <td valign="middle" align="left"><a href="#SEC_Contents" title="Table of contents"><img src="button-compass.png" border="0" alt="Contents: Table of Contents" align="middle" width="32"></a></td>
1955 <td valign="middle" align="left"><a href="#Index" title="Index"><img src="button-abc.png" border="0" alt="Index: Alphabetic index of definitions of concepts, keywords, and procedures" align="middle" width="32"></a></td>
1956 </tr></table>
1957 <a name="Derived-expression-types-1"></a>
1958 <h2 class="section">4.2 Derived expression types</h2>
1959
1960 <table class="menu" border="0" cellspacing="0">
1961 <tr><td align="left" valign="top"><a href="#Conditional">4.2.1 Conditionals</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
1962 </td></tr>
1963 <tr><td align="left" valign="top"><a href="#Binding-constructs">4.2.2 Binding constructs</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
1964 </td></tr>
1965 <tr><td align="left" valign="top"><a href="#Sequencing">4.2.3 Sequencing</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
1966 </td></tr>
1967 <tr><td align="left" valign="top"><a href="#Iteration">4.2.4 Iteration</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
1968 </td></tr>
1969 <tr><td align="left" valign="top"><a href="#Delayed-evaluation">4.2.5 Delayed evaluation</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
1970 </td></tr>
1971 <tr><td align="left" valign="top"><a href="#Quasiquotation">4.2.6 Quasiquotation</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
1972 </td></tr>
1973 </table>
1974
1975
1976
1977 <p>The constructs in this section are hygienic, as discussed in
1978 section <a href="#Macros">Macros</a>.
1979 For reference purposes, section <a href="#Derived-expression-type">Derived expression types</a> gives macro definitions
1980 that will convert most of the constructs described in this section
1981 into the primitive constructs described in the previous section.
1982 </p>
1983
1984
1985 <a name="Conditional"></a><hr size="1"><br/><br/><br/>
1986 <table cellpadding="1" cellspacing="1" border="0">
1987 <tr><td valign="middle" align="left"><a href="#Derived-expression-types" title="Previous section in reading order"><img src="button-left.png" border="0" alt="Back: 4.2 Derived expression types" align="middle" width="32"></a></td>
1988 <td valign="middle" align="left"><a href="#Binding-constructs" title="Next section in reading order"><img src="button-right.png" border="0" alt="Forward: 4.2.2 Binding constructs" align="middle" width="32"></a></td>
1989 <td valign="middle" align="left"> &nbsp; </td>
1990 <td valign="middle" align="left"><a href="#Expressions" title="Beginning of this chapter or previous chapter"><img src="button-left-left.png" border="0" alt="FastBack: 4. Expressions" align="middle" width="32"></a></td>
1991 <td valign="middle" align="left"><a href="#Derived-expression-types" title="Up section"><img src="button-up.png" border="0" alt="Up: 4.2 Derived expression types" align="middle" width="32"></a></td>
1992 <td valign="middle" align="left"><a href="#Program-structure" title="Next chapter"><img src="button-right-right.png" border="0" alt="FastForward: 5. Program structure" align="middle" width="32"></a></td>
1993 <td valign="middle" align="left"><a href="#Top" title="Cover (top) of document"><img src="button-up-arrow.png" border="0" alt="Top: Revised(5) Report on the Algorithmic Language Scheme" align="middle" width="32"></a></td>
1994 <td valign="middle" align="left"><a href="#SEC_Contents" title="Table of contents"><img src="button-compass.png" border="0" alt="Contents: Table of Contents" align="middle" width="32"></a></td>
1995 <td valign="middle" align="left"><a href="#Index" title="Index"><img src="button-abc.png" border="0" alt="Index: Alphabetic index of definitions of concepts, keywords, and procedures" align="middle" width="32"></a></td>
1996 </tr></table>
1997 <a name="Conditionals-2"></a>
1998 <h3 class="subsection">4.2.1 Conditionals</h3>
1999
2000
2001
2002 <a name="Definition_of_cond"></a><a name="Library_syntax_cond"></a><a name="index-cond"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Library_syntax_cond">cond</a></b></code><i> &lt;clause1&gt; &lt;clause2&gt; &hellip;</i><code>)</code></td><td align="right">library syntax</td></tr></table>
2003
2004 <p><em>Syntax:</em>
2005 Each <span class="roman">&lt;clause&gt;</span> should be of the form
2006 </p>
2007 <table><tr><td>&nbsp;</td><td><pre class="format">(<span class="roman">&lt;test&gt;</span> <span class="roman">&lt;expression1&gt;</span> &hellip;)
2008 </pre></td></tr></table>
2009
2010 <p>where <span class="roman">&lt;test&gt;</span> is any expression. Alternatively, a <span class="roman">&lt;clause&gt;</span> may be
2011 of the form
2012 </p>
2013 <table><tr><td>&nbsp;</td><td><pre class="format">(<span class="roman">&lt;test&gt;</span> =&gt; <span class="roman">&lt;expression&gt;</span>)
2014 </pre></td></tr></table>
2015
2016 <p>The last <span class="roman">&lt;clause&gt;</span> may be
2017 an &ldquo;else clause,&rdquo; which has the form
2018 </p>
2019 <table><tr><td>&nbsp;</td><td><pre class="format">(else <span class="roman">&lt;expression1&gt;</span> <span class="roman">&lt;expression2&gt;</span> &hellip;)<span class="roman">.</span>
2020 </pre></td></tr></table>
2021
2022
2023 <a name="index-else"></a>
2024
2025 <a name="index-_003d_003e"></a>
2026
2027 <p><em>Semantics:</em>
2028 A <samp>cond</samp> expression is evaluated by evaluating the <span class="roman">&lt;test&gt;</span>
2029 expressions of successive <span class="roman">&lt;clause&gt;</span>s in order until one of them
2030 evaluates to a true value (see
2031 <a name="index-true-2"></a>
2032 section see section <a href="#Booleans">Booleans</a>). When a <span class="roman">&lt;test&gt;</span> evaluates to a true
2033 value, then the remaining <span class="roman">&lt;expression&gt;</span>s in its <span class="roman">&lt;clause&gt;</span> are
2034 evaluated in order, and the result(s) of the last <span class="roman">&lt;expression&gt;</span> in the
2035 <span class="roman">&lt;clause&gt;</span> is(are) returned as the result(s) of the entire <samp>cond</samp>
2036 expression. If the selected <span class="roman">&lt;clause&gt;</span> contains only the
2037 <span class="roman">&lt;test&gt;</span> and no <span class="roman">&lt;expression&gt;</span>s, then the value of the
2038 <span class="roman">&lt;test&gt;</span> is returned as the result. If the selected <span class="roman">&lt;clause&gt;</span> uses the
2039 <code>=&gt;</code> alternate form, then the <span class="roman">&lt;expression&gt;</span> is evaluated.
2040 <a name="index-_003d_003e-1"></a>
2041 Its value must be a procedure that accepts one argument; this procedure is then
2042 called on the value of the <span class="roman">&lt;test&gt;</span> and the value(s) returned by this
2043 procedure is(are) returned by the <samp>cond</samp> expression.
2044 If all <span class="roman">&lt;test&gt;</span>s evaluate
2045 to false values, and there is no else clause, then the result of
2046 the conditional expression is unspecified; if there is an else
2047 clause, then its <span class="roman">&lt;expression&gt;</span>s are evaluated, and the value(s) of
2048 the last one is(are) returned.
2049 </p>
2050
2051 <table><tr><td>&nbsp;</td><td><pre class="format">(cond ((&gt; 3 2) 'greater)
2052 ((&lt; 3 2) 'less)) ==&gt; greater
2053
2054 (cond ((&gt; 3 3) 'greater)
2055 ((&lt; 3 3) 'less)
2056 (else 'equal)) ==&gt; equal
2057
2058 (cond ((assv 'b '((a 1) (b 2))) =&gt; cadr)
2059 (else #f)) ==&gt; 2
2060 </pre></td></tr></table>
2061
2062
2063
2064
2065
2066
2067
2068 <a name="Definition_of_case"></a><a name="Library_syntax_case"></a><a name="index-case"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Library_syntax_case">case</a></b></code><i> <span class="roman">&lt;key&gt;</span> &lt;clause1&gt; &lt;clause2&gt; &hellip;</i><code>)</code></td><td align="right">library syntax</td></tr></table>
2069
2070 <p><em>Syntax:</em>
2071 <span class="roman">&lt;Key&gt;</span> may be any expression. Each <span class="roman">&lt;clause&gt;</span> should have
2072 the form
2073 </p>
2074 <table><tr><td>&nbsp;</td><td><pre class="format">((<span class="roman">&lt;datum1&gt;</span> &hellip;) <span class="roman">&lt;expression1&gt;</span> <span class="roman">&lt;expression2&gt;</span> &hellip;)<span class="roman">,</span>
2075 </pre></td></tr></table>
2076
2077 <p>where each <span class="roman">&lt;datum&gt;</span> is an external representation of some object.
2078 All the <span class="roman">&lt;datum&gt;</span>s must be distinct.
2079 The last <span class="roman">&lt;clause&gt;</span> may be an &ldquo;else clause,&rdquo; which has the form
2080 </p>
2081 <table><tr><td>&nbsp;</td><td><pre class="format">(else <span class="roman">&lt;expression1&gt;</span> <span class="roman">&lt;expression2&gt;</span> &hellip;)<span class="roman">.</span>
2082 </pre></td></tr></table>
2083
2084
2085 <a name="index-else-1"></a>
2086
2087 <p><em>Semantics:</em>
2088 A <samp>case</samp> expression is evaluated as follows. <span class="roman">&lt;Key&gt;</span> is
2089 evaluated and its result is compared against each <span class="roman">&lt;datum&gt;</span>. If the
2090 result of evaluating <span class="roman">&lt;key&gt;</span> is equivalent (in the sense of
2091 <samp>eqv?</samp>; see section see section <a href="#Equivalence-predicates">Equivalence predicates</a>) to a <span class="roman">&lt;datum&gt;</span>, then the
2092 expressions in the corresponding <span class="roman">&lt;clause&gt;</span> are evaluated from left
2093 to right and the result(s) of the last expression in the <span class="roman">&lt;clause&gt;</span> is(are)
2094 returned as the result(s) of the <samp>case</samp> expression. If the result of
2095 evaluating <span class="roman">&lt;key&gt;</span> is different from every <span class="roman">&lt;datum&gt;</span>, then if
2096 there is an else clause its expressions are evaluated and the
2097 result(s) of the last is(are) the result(s) of the <samp>case</samp> expression;
2098 otherwise the result of the <samp>case</samp> expression is unspecified.
2099 </p>
2100
2101 <table><tr><td>&nbsp;</td><td><pre class="format">(case (* 2 3)
2102 ((2 3 5 7) 'prime)
2103 ((1 4 6 8 9) 'composite)) ==&gt; composite
2104 (case (car '(c d))
2105 ((a) 'a)
2106 ((b) 'b)) ==&gt; <em>unspecified</em>
2107 (case (car '(c d))
2108 ((a e i o u) 'vowel)
2109 ((w y) 'semivowel)
2110 (else 'consonant)) ==&gt; consonant
2111 </pre></td></tr></table>
2112
2113
2114
2115
2116
2117
2118 <a name="Definition_of_and"></a><a name="Library_syntax_and"></a><a name="index-and"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Library_syntax_and">and</a></b></code><i> &lt;test1&gt; &hellip;</i><code>)</code></td><td align="right">library syntax</td></tr></table>
2119
2120 <p>The <span class="roman">&lt;test&gt;</span> expressions are evaluated from left to right, and the
2121 value of the first expression that evaluates to a false value (see
2122 section see section <a href="#Booleans">Booleans</a>) is returned. Any remaining expressions
2123 are not evaluated. If all the expressions evaluate to true values, the
2124 value of the last expression is returned. If there are no expressions
2125 then <tt>#t</tt> is returned.
2126 </p>
2127
2128 <table><tr><td>&nbsp;</td><td><pre class="format">(and (= 2 2) (&gt; 2 1)) ==&gt; #t
2129 (and (= 2 2) (&lt; 2 1)) ==&gt; #f
2130 (and 1 2 'c '(f g)) ==&gt; (f g)
2131 (and) ==&gt; #t
2132 </pre></td></tr></table>
2133
2134
2135
2136
2137
2138
2139 <a name="Definition_of_or"></a><a name="Library_syntax_or"></a><a name="index-or"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Library_syntax_or">or</a></b></code><i> &lt;test1&gt; &hellip;</i><code>)</code></td><td align="right">library syntax</td></tr></table>
2140
2141 <p>The <span class="roman">&lt;test&gt;</span> expressions are evaluated from left to right, and the value of the
2142 first expression that evaluates to a true value (see
2143 section see section <a href="#Booleans">Booleans</a>) is returned. Any remaining expressions
2144 are not evaluated. If all expressions evaluate to false values, the
2145 value of the last expression is returned. If there are no
2146 expressions then <tt>#f</tt> is returned.
2147 </p>
2148
2149 <table><tr><td>&nbsp;</td><td><pre class="format">(or (= 2 2) (&gt; 2 1)) ==&gt; #t
2150 (or (= 2 2) (&lt; 2 1)) ==&gt; #t
2151 (or #f #f #f) ==&gt; #f
2152 (or (memq 'b '(a b c))
2153 (/ 3 0)) ==&gt; (b c)
2154 </pre></td></tr></table>
2155
2156
2157
2158
2159
2160 <a name="Binding-constructs"></a><hr size="1"><br/><br/><br/>
2161 <table cellpadding="1" cellspacing="1" border="0">
2162 <tr><td valign="middle" align="left"><a href="#Conditional" title="Previous section in reading order"><img src="button-left.png" border="0" alt="Back: 4.2.1 Conditionals" align="middle" width="32"></a></td>
2163 <td valign="middle" align="left"><a href="#Sequencing" title="Next section in reading order"><img src="button-right.png" border="0" alt="Forward: 4.2.3 Sequencing" align="middle" width="32"></a></td>
2164 <td valign="middle" align="left"> &nbsp; </td>
2165 <td valign="middle" align="left"><a href="#Expressions" title="Beginning of this chapter or previous chapter"><img src="button-left-left.png" border="0" alt="FastBack: 4. Expressions" align="middle" width="32"></a></td>
2166 <td valign="middle" align="left"><a href="#Derived-expression-types" title="Up section"><img src="button-up.png" border="0" alt="Up: 4.2 Derived expression types" align="middle" width="32"></a></td>
2167 <td valign="middle" align="left"><a href="#Program-structure" title="Next chapter"><img src="button-right-right.png" border="0" alt="FastForward: 5. Program structure" align="middle" width="32"></a></td>
2168 <td valign="middle" align="left"><a href="#Top" title="Cover (top) of document"><img src="button-up-arrow.png" border="0" alt="Top: Revised(5) Report on the Algorithmic Language Scheme" align="middle" width="32"></a></td>
2169 <td valign="middle" align="left"><a href="#SEC_Contents" title="Table of contents"><img src="button-compass.png" border="0" alt="Contents: Table of Contents" align="middle" width="32"></a></td>
2170 <td valign="middle" align="left"><a href="#Index" title="Index"><img src="button-abc.png" border="0" alt="Index: Alphabetic index of definitions of concepts, keywords, and procedures" align="middle" width="32"></a></td>
2171 </tr></table>
2172 <a name="Binding-constructs-1"></a>
2173 <h3 class="subsection">4.2.2 Binding constructs</h3>
2174
2175
2176 <p>The three binding constructs <samp>let</samp>, <samp>let*</samp>, and <samp>letrec</samp>
2177 give Scheme a block structure, like Algol 60. The syntax of the three
2178 constructs is identical, but they differ in the regions they establish
2179 <a name="index-region-2"></a>
2180 for their variable bindings. In a <samp>let</samp> expression, the initial
2181 values are computed before any of the variables become bound; in a
2182 <samp>let*</samp> expression, the bindings and evaluations are performed
2183 sequentially; while in a <samp>letrec</samp> expression, all the bindings are in
2184 effect while their initial values are being computed, thus allowing
2185 mutually recursive definitions.
2186 </p>
2187
2188 <a name="Definition_of_let"></a><a name="Library_syntax_let"></a><a name="index-let"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Library_syntax_let">let</a></b></code><i> <span class="roman">&lt;bindings&gt;</span> <span class="roman">&lt;body&gt;</span></i><code>)</code></td><td align="right">library syntax</td></tr></table>
2189
2190 <p><em>Syntax:</em>
2191 <span class="roman">&lt;Bindings&gt;</span> should have the form
2192 </p>
2193 <table><tr><td>&nbsp;</td><td><pre class="format">((<span class="roman">&lt;variable1&gt;</span> <span class="roman">&lt;init1&gt;</span>) &hellip;)<span class="roman">,</span>
2194 </pre></td></tr></table>
2195
2196 <p>where each <span class="roman">&lt;init&gt;</span> is an expression, and <span class="roman">&lt;body&gt;</span> should be a
2197 sequence of one or more expressions. It is
2198 an error for a <span class="roman">&lt;variable&gt;</span> to appear more than once in the list of variables
2199 being bound.
2200 </p>
2201 <p><em>Semantics:</em>
2202 The <span class="roman">&lt;init&gt;</span>s are evaluated in the current environment (in some
2203 unspecified order), the <span class="roman">&lt;variable&gt;</span>s are bound to fresh locations
2204 holding the results, the <span class="roman">&lt;body&gt;</span> is evaluated in the extended
2205 environment, and the value(s) of the last expression of <span class="roman">&lt;body&gt;</span>
2206 is(are) returned. Each binding of a <span class="roman">&lt;variable&gt;</span> has <span class="roman">&lt;body&gt;</span> as its
2207 region.
2208 <a name="index-region-3"></a>
2209 </p>
2210
2211 <table><tr><td>&nbsp;</td><td><pre class="format">(let ((x 2) (y 3))
2212 (* x y)) ==&gt; 6
2213
2214 (let ((x 2) (y 3))
2215 (let ((x 7)
2216 (z (+ x y)))
2217 (* z x))) ==&gt; 35
2218 </pre></td></tr></table>
2219
2220
2221 <p>See also named <samp>let</samp>, section <a href="#Iteration">Iteration</a>.
2222 </p>
2223
2224
2225
2226
2227 <a name="Definition_of_let%2A"></a><a name="Library_syntax_let%2A"></a><a name="index-let_002a"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Library_syntax_let%2A">let*</a></b></code><i> <span class="roman">&lt;bindings&gt;</span> <span class="roman">&lt;body&gt;</span></i><code>)</code></td><td align="right">library syntax</td></tr></table>
2228
2229
2230 <p><em>Syntax:</em>
2231 <span class="roman">&lt;Bindings&gt;</span> should have the form
2232 </p>
2233 <table><tr><td>&nbsp;</td><td><pre class="format">((<span class="roman">&lt;variable1&gt;</span> <span class="roman">&lt;init1&gt;</span>) &hellip;)<span class="roman">,</span>
2234 </pre></td></tr></table>
2235
2236 <p>and <span class="roman">&lt;body&gt;</span> should be a sequence of
2237 one or more expressions.
2238 </p>
2239 <p><em>Semantics:</em>
2240 <samp>Let*</samp> is similar to <samp>let</samp>, but the bindings are performed
2241 sequentially from left to right, and the region of a binding indicated
2242 <a name="index-region-4"></a>
2243 by <samp>(<span class="roman">&lt;variable&gt;</span> <span class="roman">&lt;init&gt;</span>)</samp> is that part of the <samp>let*</samp>
2244 expression to the right of the binding. Thus the second binding is done
2245 in an environment in which the first binding is visible, and so on.
2246 </p>
2247
2248 <table><tr><td>&nbsp;</td><td><pre class="format">(let ((x 2) (y 3))
2249 (let* ((x 7)
2250 (z (+ x y)))
2251 (* z x))) ==&gt; 70
2252 </pre></td></tr></table>
2253
2254
2255
2256
2257
2258
2259 <a name="Definition_of_letrec"></a><a name="Library_syntax_letrec"></a><a name="index-letrec"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Library_syntax_letrec">letrec</a></b></code><i> <span class="roman">&lt;bindings&gt;</span> <span class="roman">&lt;body&gt;</span></i><code>)</code></td><td align="right">library syntax</td></tr></table>
2260
2261 <p><em>Syntax:</em>
2262 <span class="roman">&lt;Bindings&gt;</span> should have the form
2263 </p>
2264 <table><tr><td>&nbsp;</td><td><pre class="format">((<span class="roman">&lt;variable1&gt;</span> <span class="roman">&lt;init1&gt;</span>) &hellip;)<span class="roman">,</span>
2265 </pre></td></tr></table>
2266
2267 <p>and <span class="roman">&lt;body&gt;</span> should be a sequence of
2268 one or more expressions. It is an error for a <span class="roman">&lt;variable&gt;</span> to appear more
2269 than once in the list of variables being bound.
2270 </p>
2271 <p><em>Semantics:</em>
2272 The <span class="roman">&lt;variable&gt;</span>s are bound to fresh locations holding undefined
2273 values, the <span class="roman">&lt;init&gt;</span>s are evaluated in the resulting environment (in
2274 some unspecified order), each <span class="roman">&lt;variable&gt;</span> is assigned to the result
2275 of the corresponding <span class="roman">&lt;init&gt;</span>, the <span class="roman">&lt;body&gt;</span> is evaluated in the
2276 resulting environment, and the value(s) of the last expression in
2277 <span class="roman">&lt;body&gt;</span> is(are) returned. Each binding of a <span class="roman">&lt;variable&gt;</span> has the
2278 entire <samp>letrec</samp> expression as its region, making it possible to
2279 <a name="index-region-5"></a>
2280 define mutually recursive procedures.
2281 </p>
2282
2283 <table><tr><td>&nbsp;</td><td><pre class="format">(letrec ((even?
2284 (lambda (n)
2285 (if (zero? n)
2286 #t
2287 (odd? (- n 1)))))
2288 (odd?
2289 (lambda (n)
2290 (if (zero? n)
2291 #f
2292 (even? (- n 1))))))
2293 (even? 88))
2294 ==&gt; #t
2295 </pre></td></tr></table>
2296
2297
2298 <p>One restriction on <samp>letrec</samp> is very important: it must be possible
2299 to evaluate each <span class="roman">&lt;init&gt;</span> without assigning or referring to the value of any
2300 <span class="roman">&lt;variable&gt;</span>. If this restriction is violated, then it is an error. The
2301 restriction is necessary because Scheme passes arguments by value rather than by
2302 name. In the most common uses of <samp>letrec</samp>, all the <span class="roman">&lt;init&gt;</span>s are
2303 lambda expressions and the restriction is satisfied automatically.
2304 </p>
2305
2306
2307
2308
2309 <a name="Sequencing"></a><hr size="1"><br/><br/><br/>
2310 <table cellpadding="1" cellspacing="1" border="0">
2311 <tr><td valign="middle" align="left"><a href="#Binding-constructs" title="Previous section in reading order"><img src="button-left.png" border="0" alt="Back: 4.2.2 Binding constructs" align="middle" width="32"></a></td>
2312 <td valign="middle" align="left"><a href="#Iteration" title="Next section in reading order"><img src="button-right.png" border="0" alt="Forward: 4.2.4 Iteration" align="middle" width="32"></a></td>
2313 <td valign="middle" align="left"> &nbsp; </td>
2314 <td valign="middle" align="left"><a href="#Expressions" title="Beginning of this chapter or previous chapter"><img src="button-left-left.png" border="0" alt="FastBack: 4. Expressions" align="middle" width="32"></a></td>
2315 <td valign="middle" align="left"><a href="#Derived-expression-types" title="Up section"><img src="button-up.png" border="0" alt="Up: 4.2 Derived expression types" align="middle" width="32"></a></td>
2316 <td valign="middle" align="left"><a href="#Program-structure" title="Next chapter"><img src="button-right-right.png" border="0" alt="FastForward: 5. Program structure" align="middle" width="32"></a></td>
2317 <td valign="middle" align="left"><a href="#Top" title="Cover (top) of document"><img src="button-up-arrow.png" border="0" alt="Top: Revised(5) Report on the Algorithmic Language Scheme" align="middle" width="32"></a></td>
2318 <td valign="middle" align="left"><a href="#SEC_Contents" title="Table of contents"><img src="button-compass.png" border="0" alt="Contents: Table of Contents" align="middle" width="32"></a></td>
2319 <td valign="middle" align="left"><a href="#Index" title="Index"><img src="button-abc.png" border="0" alt="Index: Alphabetic index of definitions of concepts, keywords, and procedures" align="middle" width="32"></a></td>
2320 </tr></table>
2321 <a name="Sequencing-1"></a>
2322 <h3 class="subsection">4.2.3 Sequencing</h3>
2323
2324
2325
2326 <a name="Definition_of_begin"></a><a name="Library_syntax_begin"></a><a name="index-begin"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Library_syntax_begin">begin</a></b></code><i> &lt;expression1&gt; &lt;expression2&gt; &hellip;</i><code>)</code></td><td align="right">library syntax</td></tr></table>
2327
2328 <p>The <span class="roman">&lt;expression&gt;</span>s are evaluated sequentially from left to right,
2329 and the value(s) of the last <span class="roman">&lt;expression&gt;</span> is(are) returned. This
2330 expression type is used to sequence side effects such as input and
2331 output.
2332 </p>
2333
2334 <table><tr><td>&nbsp;</td><td><pre class="format">(define x 0)
2335
2336 (begin (set! x 5)
2337 (+ x 1)) ==&gt; 6
2338
2339 (begin (display &quot;4 plus 1 equals &quot;)
2340 (display (+ 4 1))) ==&gt; <em>unspecified</em>
2341 <em>and prints</em> 4 plus 1 equals 5
2342 </pre></td></tr></table>
2343
2344
2345
2346
2347
2348 <a name="Iteration"></a><hr size="1"><br/><br/><br/>
2349 <table cellpadding="1" cellspacing="1" border="0">
2350 <tr><td valign="middle" align="left"><a href="#Sequencing" title="Previous section in reading order"><img src="button-left.png" border="0" alt="Back: 4.2.3 Sequencing" align="middle" width="32"></a></td>
2351 <td valign="middle" align="left"><a href="#Delayed-evaluation" title="Next section in reading order"><img src="button-right.png" border="0" alt="Forward: 4.2.5 Delayed evaluation" align="middle" width="32"></a></td>
2352 <td valign="middle" align="left"> &nbsp; </td>
2353 <td valign="middle" align="left"><a href="#Expressions" title="Beginning of this chapter or previous chapter"><img src="button-left-left.png" border="0" alt="FastBack: 4. Expressions" align="middle" width="32"></a></td>
2354 <td valign="middle" align="left"><a href="#Derived-expression-types" title="Up section"><img src="button-up.png" border="0" alt="Up: 4.2 Derived expression types" align="middle" width="32"></a></td>
2355 <td valign="middle" align="left"><a href="#Program-structure" title="Next chapter"><img src="button-right-right.png" border="0" alt="FastForward: 5. Program structure" align="middle" width="32"></a></td>
2356 <td valign="middle" align="left"><a href="#Top" title="Cover (top) of document"><img src="button-up-arrow.png" border="0" alt="Top: Revised(5) Report on the Algorithmic Language Scheme" align="middle" width="32"></a></td>
2357 <td valign="middle" align="left"><a href="#SEC_Contents" title="Table of contents"><img src="button-compass.png" border="0" alt="Contents: Table of Contents" align="middle" width="32"></a></td>
2358 <td valign="middle" align="left"><a href="#Index" title="Index"><img src="button-abc.png" border="0" alt="Index: Alphabetic index of definitions of concepts, keywords, and procedures" align="middle" width="32"></a></td>
2359 </tr></table>
2360 <a name="Iteration-1"></a>
2361 <h3 class="subsection">4.2.4 Iteration</h3>
2362
2363
2364
2365
2366 <a name="Definition_of_do"></a><a name="Library_syntax_do"></a><a name="index-do"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Library_syntax_do">do</a></b></code><i> ((<span class="roman">&lt;variable1&gt;</span> <span class="roman">&lt;init1&gt;</span> <span class="roman">&lt;step1&gt;</span>) &hellip;) (<span class="roman">&lt;test&gt;</span> <span class="roman">&lt;expression&gt;</span> &hellip;) <span class="roman">&lt;command&gt;</span> &hellip;</i><code>)</code></td><td align="right">library syntax</td></tr></table>
2367 <a name="index-do-1"></a>
2368
2369 <p><samp>Do</samp> is an iteration construct. It specifies a set of variables to
2370 be bound, how they are to be initialized at the start, and how they are
2371 to be updated on each iteration. When a termination condition is met,
2372 the loop exits after evaluating the <span class="roman">&lt;expression&gt;</span>s.
2373 </p>
2374 <p><samp>Do</samp> expressions are evaluated as follows:
2375 The <span class="roman">&lt;init&gt;</span> expressions are evaluated (in some unspecified order),
2376 the <span class="roman">&lt;variable&gt;</span>s are bound to fresh locations, the results of the
2377 <span class="roman">&lt;init&gt;</span> expressions are stored in the bindings of the
2378 <span class="roman">&lt;variable&gt;</span>s, and then the iteration phase begins.
2379 </p>
2380 <p>Each iteration begins by evaluating <span class="roman">&lt;test&gt;</span>; if the result is
2381 false (see section see section <a href="#Booleans">Booleans</a>), then the <span class="roman">&lt;command&gt;</span>
2382 expressions are evaluated in order for effect, the <span class="roman">&lt;step&gt;</span>
2383 expressions are evaluated in some unspecified order, the
2384 <span class="roman">&lt;variable&gt;</span>s are bound to fresh locations, the results of the
2385 <span class="roman">&lt;step&gt;</span>s are stored in the bindings of the
2386 <span class="roman">&lt;variable&gt;</span>s, and the next iteration begins.
2387 </p>
2388 <p>If <span class="roman">&lt;test&gt;</span> evaluates to a true value, then the
2389 <span class="roman">&lt;expression&gt;</span>s are evaluated from left to right and the value(s) of
2390 the last <span class="roman">&lt;expression&gt;</span> is(are) returned. If no <span class="roman">&lt;expression&gt;</span>s
2391 are present, then the value of the <samp>do</samp> expression is unspecified.
2392 </p>
2393 <p>The region of the binding of a <span class="roman">&lt;variable&gt;</span>
2394 <a name="index-region-6"></a>
2395 consists of the entire <samp>do</samp> expression except for the <span class="roman">&lt;init&gt;</span>s.
2396 It is an error for a <span class="roman">&lt;variable&gt;</span> to appear more than once in the
2397 list of <samp>do</samp> variables.
2398 </p>
2399 <p>A <span class="roman">&lt;step&gt;</span> may be omitted, in which case the effect is the
2400 same as if <samp>(<span class="roman">&lt;variable&gt;</span> <span class="roman">&lt;init&gt;</span> <span class="roman">&lt;variable&gt;</span>)</samp> had
2401 been written instead of <samp>(<span class="roman">&lt;variable&gt;</span> <span class="roman">&lt;init&gt;</span>)</samp>.
2402 </p>
2403
2404 <table><tr><td>&nbsp;</td><td><pre class="format">(do ((vec (make-vector 5))
2405 (i 0 (+ i 1)))
2406 ((= i 5) vec)
2407 (vector-set! vec i i)) ==&gt; #(0 1 2 3 4)
2408
2409 (let ((x '(1 3 5 7 9)))
2410 (do ((x x (cdr x))
2411 (sum 0 (+ sum (car x))))
2412 ((null? x) sum))) ==&gt; 25
2413 </pre></td></tr></table>
2414
2415
2416
2417
2418
2419 <a name="Definition_of_let"></a><a name="Library_syntax_let"></a><a name="index-let-1"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Library_syntax_let">let</a></b></code><i> <span class="roman">&lt;variable&gt;</span> <span class="roman">&lt;bindings&gt;</span> <span class="roman">&lt;body&gt;</span></i><code>)</code></td><td align="right">library syntax</td></tr></table>
2420
2421
2422 <p>&ldquo;Named <samp>let</samp>&rdquo; is a variant on the syntax of <code>let</code> which provides
2423 <a name="index-let-2"></a>
2424 a more general looping construct than <samp>do</samp> and may also be used to express
2425 recursions.
2426 It has the same syntax and semantics as ordinary <samp>let</samp>
2427 except that <span class="roman">&lt;variable&gt;</span> is bound within <span class="roman">&lt;body&gt;</span> to a procedure
2428 whose formal arguments are the bound variables and whose body is
2429 <span class="roman">&lt;body&gt;</span>. Thus the execution of <span class="roman">&lt;body&gt;</span> may be repeated by
2430 invoking the procedure named by <span class="roman">&lt;variable&gt;</span>.
2431 </p>
2432
2433 <table><tr><td>&nbsp;</td><td><pre class="format">(let loop ((numbers '(3 -2 1 6 -5))
2434 (nonneg '())
2435 (neg '()))
2436 (cond ((null? numbers) (list nonneg neg))
2437 ((&gt;= (car numbers) 0)
2438 (loop (cdr numbers)
2439 (cons (car numbers) nonneg)
2440 neg))
2441 ((&lt; (car numbers) 0)
2442 (loop (cdr numbers)
2443 nonneg
2444 (cons (car numbers) neg)))))
2445 ==&gt; ((6 1 3) (-5 -2))
2446 </pre></td></tr></table>
2447
2448
2449
2450
2451
2452 <a name="Delayed-evaluation"></a><hr size="1"><br/><br/><br/>
2453 <table cellpadding="1" cellspacing="1" border="0">
2454 <tr><td valign="middle" align="left"><a href="#Iteration" title="Previous section in reading order"><img src="button-left.png" border="0" alt="Back: 4.2.4 Iteration" align="middle" width="32"></a></td>
2455 <td valign="middle" align="left"><a href="#Quasiquotation" title="Next section in reading order"><img src="button-right.png" border="0" alt="Forward: 4.2.6 Quasiquotation" align="middle" width="32"></a></td>
2456 <td valign="middle" align="left"> &nbsp; </td>
2457 <td valign="middle" align="left"><a href="#Expressions" title="Beginning of this chapter or previous chapter"><img src="button-left-left.png" border="0" alt="FastBack: 4. Expressions" align="middle" width="32"></a></td>
2458 <td valign="middle" align="left"><a href="#Derived-expression-types" title="Up section"><img src="button-up.png" border="0" alt="Up: 4.2 Derived expression types" align="middle" width="32"></a></td>
2459 <td valign="middle" align="left"><a href="#Program-structure" title="Next chapter"><img src="button-right-right.png" border="0" alt="FastForward: 5. Program structure" align="middle" width="32"></a></td>
2460 <td valign="middle" align="left"><a href="#Top" title="Cover (top) of document"><img src="button-up-arrow.png" border="0" alt="Top: Revised(5) Report on the Algorithmic Language Scheme" align="middle" width="32"></a></td>
2461 <td valign="middle" align="left"><a href="#SEC_Contents" title="Table of contents"><img src="button-compass.png" border="0" alt="Contents: Table of Contents" align="middle" width="32"></a></td>
2462 <td valign="middle" align="left"><a href="#Index" title="Index"><img src="button-abc.png" border="0" alt="Index: Alphabetic index of definitions of concepts, keywords, and procedures" align="middle" width="32"></a></td>
2463 </tr></table>
2464 <a name="Delayed-evaluation-1"></a>
2465 <h3 class="subsection">4.2.5 Delayed evaluation</h3>
2466
2467
2468
2469 <a name="Definition_of_delay"></a><a name="Library_syntax_delay"></a><a name="index-delay"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Library_syntax_delay">delay</a></b></code><i> <span class="roman">&lt;expression&gt;</span></i><code>)</code></td><td align="right">library syntax</td></tr></table>
2470
2471
2472
2473 <p>The <samp>delay</samp> construct is used together with the procedure <code>force</code> to
2474 <a name="index-force"></a>
2475 implement <em>lazy evaluation</em> or <em>call by need</em>.
2476 <a name="index-call-by-need"></a>
2477 <a name="index-lazy-evaluation"></a>
2478 <tt>(delay <span class="roman">&lt;expression&gt;</span>)</tt> returns an object called a
2479 <em>promise</em> which at some point in the future may be asked (by
2480 <a name="index-promise"></a>
2481 the <samp>force</samp> procedure)
2482 to evaluate
2483 <span class="roman">&lt;expression&gt;</span>, and deliver the resulting value.
2484 The effect of <span class="roman">&lt;expression&gt;</span> returning multiple values
2485 is unspecified.
2486 </p>
2487 <p>See the description of <samp>force</samp> (section see section <a href="#Control-features">Control features</a>) for a
2488 more complete description of <samp>delay</samp>.
2489 </p>
2490
2491
2492
2493 <a name="Quasiquotation"></a><hr size="1"><br/><br/><br/>
2494 <table cellpadding="1" cellspacing="1" border="0">
2495 <tr><td valign="middle" align="left"><a href="#Delayed-evaluation" title="Previous section in reading order"><img src="button-left.png" border="0" alt="Back: 4.2.5 Delayed evaluation" align="middle" width="32"></a></td>
2496 <td valign="middle" align="left"><a href="#Macros" title="Next section in reading order"><img src="button-right.png" border="0" alt="Forward: 4.3 Macros" align="middle" width="32"></a></td>
2497 <td valign="middle" align="left"> &nbsp; </td>
2498 <td valign="middle" align="left"><a href="#Expressions" title="Beginning of this chapter or previous chapter"><img src="button-left-left.png" border="0" alt="FastBack: 4. Expressions" align="middle" width="32"></a></td>
2499 <td valign="middle" align="left"><a href="#Derived-expression-types" title="Up section"><img src="button-up.png" border="0" alt="Up: 4.2 Derived expression types" align="middle" width="32"></a></td>
2500 <td valign="middle" align="left"><a href="#Program-structure" title="Next chapter"><img src="button-right-right.png" border="0" alt="FastForward: 5. Program structure" align="middle" width="32"></a></td>
2501 <td valign="middle" align="left"><a href="#Top" title="Cover (top) of document"><img src="button-up-arrow.png" border="0" alt="Top: Revised(5) Report on the Algorithmic Language Scheme" align="middle" width="32"></a></td>
2502 <td valign="middle" align="left"><a href="#SEC_Contents" title="Table of contents"><img src="button-compass.png" border="0" alt="Contents: Table of Contents" align="middle" width="32"></a></td>
2503 <td valign="middle" align="left"><a href="#Index" title="Index"><img src="button-abc.png" border="0" alt="Index: Alphabetic index of definitions of concepts, keywords, and procedures" align="middle" width="32"></a></td>
2504 </tr></table>
2505 <a name="Quasiquotation-1"></a>
2506 <h3 class="subsection">4.2.6 Quasiquotation</h3>
2507
2508
2509
2510
2511 <a name="Definition_of_quasiquote"></a><a name="Syntax_quasiquote"></a><a name="index-quasiquote"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Syntax_quasiquote">quasiquote</a></b></code><i> <span class="roman">&lt;qq template&gt;</span></i><code>)</code></td><td align="right">syntax</td></tr></table>
2512 <a name="index-_0060"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><tt>`</tt></b></code><i><span class="roman">&lt;qq template&gt;</span></i><code>)</code></td><td align="right">syntax</td></tr></table>
2513
2514
2515 <p>&ldquo;Backquote&rdquo; or &ldquo;quasiquote&rdquo; expressions are useful
2516 <a name="index-backquote"></a>
2517 for constructing a list or vector structure when most but not all of the
2518 desired structure is known in advance. If no
2519 commas appear within the <span class="roman">&lt;qq template&gt;</span>, the result of
2520 <a name="index-comma"></a>
2521 evaluating
2522 <tt>&lsquo;</tt><span class="roman">&lt;qq template&gt;</span> is equivalent to the result of evaluating
2523 <tt>'</tt><span class="roman">&lt;qq template&gt;</span>. If a comma appears within the
2524 <a name="index-_002c"></a>
2525 <span class="roman">&lt;qq template&gt;</span>, however, the expression following the comma is
2526 evaluated (&ldquo;unquoted&rdquo;) and its result is inserted into the structure
2527 instead of the comma and the expression. If a comma appears followed
2528 immediately by an at-sign (@), then the following
2529 <a name="index-_002c_0040"></a>
2530 expression must evaluate to a list; the opening and closing parentheses
2531 of the list are then &ldquo;stripped away&rdquo; and the elements of the list are
2532 inserted in place of the comma at-sign expression sequence. A comma
2533 at-sign should only appear within a list or vector <span class="roman">&lt;qq template&gt;</span>.
2534 </p>
2535
2536
2537 <table><tr><td>&nbsp;</td><td><pre class="format">&lsquo;(list ,(+ 1 2) 4) ==&gt; (list 3 4)
2538 (let ((name 'a)) &lsquo;(list ,name ',name))
2539 ==&gt; (list a (quote a))
2540 &lsquo;(a ,(+ 1 2) ,@(map abs '(4 -5 6)) b)
2541 ==&gt; (a 3 4 5 6 b)
2542 &lsquo;((<samp>foo</samp> ,(- 10 3)) ,@(cdr '(c)) . ,(car '(cons)))
2543 ==&gt; ((foo 7) . cons)
2544 &lsquo;#(10 5 ,(sqrt 4) ,@(map sqrt '(16 9)) 8)
2545 ==&gt; #(10 5 2 4 3 8)
2546 </pre></td></tr></table>
2547
2548
2549 <p>Quasiquote forms may be nested. Substitutions are made only for
2550 unquoted components appearing at the same nesting level
2551 as the outermost backquote. The nesting level increases by one inside
2552 each successive quasiquotation, and decreases by one inside each
2553 unquotation.
2554 </p>
2555
2556 <table><tr><td>&nbsp;</td><td><pre class="format">&lsquo;(a &lsquo;(b ,(+ 1 2) ,(foo ,(+ 1 3) d) e) f)
2557 ==&gt; (a &lsquo;(b ,(+ 1 2) ,(foo 4 d) e) f)
2558 (let ((name1 'x)
2559 (name2 'y))
2560 &lsquo;(a &lsquo;(b ,,name1 ,',name2 d) e))
2561 ==&gt; (a &lsquo;(b ,x ,'y d) e)
2562 </pre></td></tr></table>
2563
2564
2565 <p>The two notations
2566 <tt>&lsquo;</tt><span class="roman">&lt;qq template&gt;</span> and <tt>(quasiquote <span class="roman">&lt;qq template&gt;</span>)</tt>
2567 are identical in all respects.
2568 <samp>,<span class="roman">&lt;expression&gt;</span></samp> is identical to <samp>(unquote <span class="roman">&lt;expression&gt;</span>)</samp>,
2569 and
2570 <samp>,@<span class="roman">&lt;expression&gt;</span></samp> is identical to <samp>(unquote-splicing <span class="roman">&lt;expression&gt;</span>)</samp>.
2571 The external syntax generated by <code>write</code> for two-element lists whose
2572 <a name="index-write"></a>
2573 car is one of these symbols may vary between implementations.
2574 </p>
2575 <a name="index-_0060-1"></a>
2576
2577
2578 <table><tr><td>&nbsp;</td><td><pre class="format">(quasiquote (list (unquote (+ 1 2)) 4))
2579 ==&gt; (list 3 4)
2580 '(quasiquote (list (unquote (+ 1 2)) 4))
2581 ==&gt; &lsquo;(list ,(+ 1 2) 4)
2582 <em></em>i.e., (quasiquote (list (unquote (+ 1 2)) 4))
2583 </pre></td></tr></table>
2584
2585
2586 <p>Unpredictable behavior can result if any of the symbols
2587 <code>quasiquote</code>, <code>unquote</code>, or <code>unquote-splicing</code> appear in
2588 <a name="index-unquote_002dsplicing"></a>
2589 <a name="index-unquote"></a>
2590 <a name="index-quasiquote-1"></a>
2591 positions within a <span class="roman">&lt;qq template&gt;</span> otherwise than as described above.
2592 </p>
2593
2594
2595 <a name="Macros"></a><hr size="1"><br/><br/><br/>
2596 <table cellpadding="1" cellspacing="1" border="0">
2597 <tr><td valign="middle" align="left"><a href="#Quasiquotation" title="Previous section in reading order"><img src="button-left.png" border="0" alt="Back: 4.2.6 Quasiquotation" align="middle" width="32"></a></td>
2598 <td valign="middle" align="left"><a href="#Binding-constructs-for-syntactic-keywords" title="Next section in reading order"><img src="button-right.png" border="0" alt="Forward: 4.3.1 Binding constructs for syntactic keywords" align="middle" width="32"></a></td>
2599 <td valign="middle" align="left"> &nbsp; </td>
2600 <td valign="middle" align="left"><a href="#Expressions" title="Beginning of this chapter or previous chapter"><img src="button-left-left.png" border="0" alt="FastBack: 4. Expressions" align="middle" width="32"></a></td>
2601 <td valign="middle" align="left"><a href="#Expressions" title="Up section"><img src="button-up.png" border="0" alt="Up: 4. Expressions" align="middle" width="32"></a></td>
2602 <td valign="middle" align="left"><a href="#Program-structure" title="Next chapter"><img src="button-right-right.png" border="0" alt="FastForward: 5. Program structure" align="middle" width="32"></a></td>
2603 <td valign="middle" align="left"><a href="#Top" title="Cover (top) of document"><img src="button-up-arrow.png" border="0" alt="Top: Revised(5) Report on the Algorithmic Language Scheme" align="middle" width="32"></a></td>
2604 <td valign="middle" align="left"><a href="#SEC_Contents" title="Table of contents"><img src="button-compass.png" border="0" alt="Contents: Table of Contents" align="middle" width="32"></a></td>
2605 <td valign="middle" align="left"><a href="#Index" title="Index"><img src="button-abc.png" border="0" alt="Index: Alphabetic index of definitions of concepts, keywords, and procedures" align="middle" width="32"></a></td>
2606 </tr></table>
2607 <a name="Macros-1"></a>
2608 <h2 class="section">4.3 Macros</h2>
2609
2610 <table class="menu" border="0" cellspacing="0">
2611 <tr><td align="left" valign="top"><a href="#Binding-constructs-for-syntactic-keywords">4.3.1 Binding constructs for syntactic keywords</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
2612 </td></tr>
2613 <tr><td align="left" valign="top"><a href="#Pattern-language">4.3.2 Pattern language</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
2614 </td></tr>
2615 </table>
2616
2617
2618
2619 <p>Scheme programs can define and use new derived expression types,
2620 called <em>macros</em>.
2621 <a name="index-macro"></a>
2622 Program-defined expression types have the syntax
2623 </p>
2624 <table><tr><td>&nbsp;</td><td><pre class="example">
2625 (<span class="roman">&lt;keyword&gt;</span> <span class="roman">&lt;datum&gt;</span> ...)
2626 </pre></td></tr></table>
2627
2628 <p>where <span class="roman">&lt;keyword&gt;</span> is an identifier that uniquely determines the
2629 expression type. This identifier is called the <em>syntactic
2630 keyword</em>, or simply <em>keyword</em>, of the macro. The
2631 <a name="index-macro-keyword"></a>
2632 <a name="index-keyword"></a>
2633 <a name="index-syntactic-keyword-2"></a>
2634 number of the <span class="roman">&lt;datum&gt;</span>s, and their syntax, depends on the
2635 expression type.
2636 </p>
2637 <p>Each instance of a macro is called a <em>use</em>
2638 <a name="index-macro-use"></a>
2639 of the macro.
2640 The set of rules that specifies
2641 how a use of a macro is transcribed into a more primitive expression
2642 is called the <em>transformer</em>
2643 <a name="index-macro-transformer"></a>
2644 of the macro.
2645 </p>
2646 <p>The macro definition facility consists of two parts:
2647 </p>
2648
2649
2650 <ul>
2651 <li>
2652 A set of expressions used to establish that certain identifiers
2653 are macro keywords, associate them with macro transformers, and control
2654 the scope within which a macro is defined, and
2655
2656 </li><li>
2657 a pattern language for specifying macro transformers.
2658
2659 </li></ul>
2660
2661
2662 <p>The syntactic keyword of a macro may shadow variable bindings, and local
2663 variable bindings may shadow keyword bindings. All macros
2664 <a name="index-keyword-1"></a>
2665 defined using the pattern language are &ldquo;hygienic&rdquo; and &ldquo;referentially
2666 transparent&rdquo; and thus preserve Scheme's lexical scoping [Kohlbecker86], [
2667 hygienic], [Bawden88], [macrosthatwork], [syntacticabstraction]:
2668 </p>
2669 <a name="index-hygienic"></a>
2670
2671 <a name="index-referentially-transparent"></a>
2672
2673
2674
2675
2676 <ul>
2677 <li>
2678 If a macro transformer inserts a binding for an identifier
2679 (variable or keyword), the identifier will in effect be renamed
2680 throughout its scope to avoid conflicts with other identifiers.
2681 Note that a <code>define</code> at top level may or may not introduce a binding;
2682 see section <a href="#Definitions">Definitions</a>.
2683
2684 </li><li>
2685 If a macro transformer inserts a free reference to an
2686 identifier, the reference refers to the binding that was visible
2687 where the transformer was specified, regardless of any local
2688 bindings that may surround the use of the macro.
2689
2690
2691 </li></ul>
2692
2693 <a name="index-define"></a>
2694
2695
2696
2697 <a name="Binding-constructs-for-syntactic-keywords"></a><hr size="1"><br/><br/><br/>
2698 <table cellpadding="1" cellspacing="1" border="0">
2699 <tr><td valign="middle" align="left"><a href="#Macros" title="Previous section in reading order"><img src="button-left.png" border="0" alt="Back: 4.3 Macros" align="middle" width="32"></a></td>
2700 <td valign="middle" align="left"><a href="#Pattern-language" title="Next section in reading order"><img src="button-right.png" border="0" alt="Forward: 4.3.2 Pattern language" align="middle" width="32"></a></td>
2701 <td valign="middle" align="left"> &nbsp; </td>
2702 <td valign="middle" align="left"><a href="#Expressions" title="Beginning of this chapter or previous chapter"><img src="button-left-left.png" border="0" alt="FastBack: 4. Expressions" align="middle" width="32"></a></td>
2703 <td valign="middle" align="left"><a href="#Macros" title="Up section"><img src="button-up.png" border="0" alt="Up: 4.3 Macros" align="middle" width="32"></a></td>
2704 <td valign="middle" align="left"><a href="#Program-structure" title="Next chapter"><img src="button-right-right.png" border="0" alt="FastForward: 5. Program structure" align="middle" width="32"></a></td>
2705 <td valign="middle" align="left"><a href="#Top" title="Cover (top) of document"><img src="button-up-arrow.png" border="0" alt="Top: Revised(5) Report on the Algorithmic Language Scheme" align="middle" width="32"></a></td>
2706 <td valign="middle" align="left"><a href="#SEC_Contents" title="Table of contents"><img src="button-compass.png" border="0" alt="Contents: Table of Contents" align="middle" width="32"></a></td>
2707 <td valign="middle" align="left"><a href="#Index" title="Index"><img src="button-abc.png" border="0" alt="Index: Alphabetic index of definitions of concepts, keywords, and procedures" align="middle" width="32"></a></td>
2708 </tr></table>
2709 <a name="Binding-constructs-for-syntactic-keywords-1"></a>
2710 <h3 class="subsection">4.3.1 Binding constructs for syntactic keywords</h3>
2711
2712
2713
2714 <p><samp>Let-syntax</samp> and <samp>letrec-syntax</samp> are
2715 analogous to <samp>let</samp> and <samp>letrec</samp>, but they bind
2716 syntactic keywords to macro transformers instead of binding variables
2717 to locations that contain values. Syntactic keywords may also be
2718 bound at top level; see section <a href="#Syntax-definitions">Syntax definitions</a>.
2719 </p>
2720
2721 <a name="Definition_of_let-syntax"></a><a name="Syntax_let-syntax"></a><a name="index-let_002dsyntax"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Syntax_let-syntax">let-syntax</a></b></code><i> <span class="roman">&lt;bindings&gt;</span> <span class="roman">&lt;body&gt;</span></i><code>)</code></td><td align="right">syntax</td></tr></table>
2722
2723 <p><em>Syntax:</em>
2724 <span class="roman">&lt;Bindings&gt;</span> should have the form
2725 </p>
2726 <table><tr><td>&nbsp;</td><td><pre class="format">((<span class="roman">&lt;keyword&gt;</span> <span class="roman">&lt;transformer spec&gt;</span>) &hellip;)
2727 </pre></td></tr></table>
2728
2729 <p>Each <span class="roman">&lt;keyword&gt;</span> is an identifier,
2730 each <span class="roman">&lt;transformer spec&gt;</span> is an instance of <samp>syntax-rules</samp>, and
2731 <span class="roman">&lt;body&gt;</span> should be a sequence of one or more expressions. It is an error
2732 for a <span class="roman">&lt;keyword&gt;</span> to appear more than once in the list of keywords
2733 being bound.
2734 </p>
2735 <p><em>Semantics:</em>
2736 The <span class="roman">&lt;body&gt;</span> is expanded in the syntactic environment
2737 obtained by extending the syntactic environment of the
2738 <samp>let-syntax</samp> expression with macros whose keywords are
2739 the <span class="roman">&lt;keyword&gt;</span>s, bound to the specified transformers.
2740 Each binding of a <span class="roman">&lt;keyword&gt;</span> has <span class="roman">&lt;body&gt;</span> as its region.
2741 </p>
2742
2743 <table><tr><td>&nbsp;</td><td><pre class="format">(let-syntax ((when (syntax-rules ()
2744 ((when test stmt1 stmt2 ...)
2745 (if test
2746 (begin stmt1
2747 stmt2 ...))))))
2748 (let ((if #t))
2749 (when if (set! if 'now))
2750 if)) ==&gt; now
2751
2752 (let ((x 'outer))
2753 (let-syntax ((m (syntax-rules () ((m) x))))
2754 (let ((x 'inner))
2755 (m)))) ==&gt; outer
2756 </pre></td></tr></table>
2757
2758
2759
2760
2761
2762 <a name="Definition_of_letrec-syntax"></a><a name="Syntax_letrec-syntax"></a><a name="index-letrec_002dsyntax"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Syntax_letrec-syntax">letrec-syntax</a></b></code><i> <span class="roman">&lt;bindings&gt;</span> <span class="roman">&lt;body&gt;</span></i><code>)</code></td><td align="right">syntax</td></tr></table>
2763
2764 <p><em>Syntax:</em>
2765 Same as for <samp>let-syntax</samp>.
2766 </p>
2767 <p><em>Semantics:</em>
2768 The <span class="roman">&lt;body&gt;</span> is expanded in the syntactic environment obtained by
2769 extending the syntactic environment of the <samp>letrec-syntax</samp>
2770 expression with macros whose keywords are the
2771 <span class="roman">&lt;keyword&gt;</span>s, bound to the specified transformers.
2772 Each binding of a <span class="roman">&lt;keyword&gt;</span> has the <span class="roman">&lt;bindings&gt;</span>
2773 as well as the <span class="roman">&lt;body&gt;</span> within its region,
2774 so the transformers can
2775 transcribe expressions into uses of the macros
2776 introduced by the <samp>letrec-syntax</samp> expression.
2777 </p>
2778
2779 <table><tr><td>&nbsp;</td><td><pre class="format">(letrec-syntax
2780 ((my-or (syntax-rules ()
2781 ((my-or) #f)
2782 ((my-or e) e)
2783 ((my-or e1 e2 ...)
2784 (let ((temp e1))
2785 (if temp
2786 temp
2787 (my-or e2 ...)))))))
2788 (let ((x #f)
2789 (y 7)
2790 (temp 8)
2791 (let odd?)
2792 (if even?))
2793 (my-or x
2794 (let temp)
2795 (if y)
2796 y))) ==&gt; 7
2797 </pre></td></tr></table>
2798
2799
2800
2801
2802 <a name="Pattern-language"></a><hr size="1"><br/><br/><br/>
2803 <table cellpadding="1" cellspacing="1" border="0">
2804 <tr><td valign="middle" align="left"><a href="#Binding-constructs-for-syntactic-keywords" title="Previous section in reading order"><img src="button-left.png" border="0" alt="Back: 4.3.1 Binding constructs for syntactic keywords" align="middle" width="32"></a></td>
2805 <td valign="middle" align="left"><a href="#Program-structure" title="Next section in reading order"><img src="button-right.png" border="0" alt="Forward: 5. Program structure" align="middle" width="32"></a></td>
2806 <td valign="middle" align="left"> &nbsp; </td>
2807 <td valign="middle" align="left"><a href="#Expressions" title="Beginning of this chapter or previous chapter"><img src="button-left-left.png" border="0" alt="FastBack: 4. Expressions" align="middle" width="32"></a></td>
2808 <td valign="middle" align="left"><a href="#Macros" title="Up section"><img src="button-up.png" border="0" alt="Up: 4.3 Macros" align="middle" width="32"></a></td>
2809 <td valign="middle" align="left"><a href="#Program-structure" title="Next chapter"><img src="button-right-right.png" border="0" alt="FastForward: 5. Program structure" align="middle" width="32"></a></td>
2810 <td valign="middle" align="left"><a href="#Top" title="Cover (top) of document"><img src="button-up-arrow.png" border="0" alt="Top: Revised(5) Report on the Algorithmic Language Scheme" align="middle" width="32"></a></td>
2811 <td valign="middle" align="left"><a href="#SEC_Contents" title="Table of contents"><img src="button-compass.png" border="0" alt="Contents: Table of Contents" align="middle" width="32"></a></td>
2812 <td valign="middle" align="left"><a href="#Index" title="Index"><img src="button-abc.png" border="0" alt="Index: Alphabetic index of definitions of concepts, keywords, and procedures" align="middle" width="32"></a></td>
2813 </tr></table>
2814 <a name="Pattern-language-1"></a>
2815 <h3 class="subsection">4.3.2 Pattern language</h3>
2816
2817
2818
2819 <p>A <span class="roman">&lt;transformer spec&gt;</span> has the following form:
2820 </p>
2821
2822 <a name="Definition_of_syntax-rules"></a><a name="_syntax-rules"></a><a name="index-syntax_002drules"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:_syntax-rules">syntax-rules</a></b></code><i> <span class="roman">&lt;literals&gt;</span> <span class="roman">&lt;syntax rule&gt;</span> &hellip;</i><code>)</code></td><td align="right"></td></tr></table>
2823
2824 <p><em>Syntax:</em>
2825 <span class="roman">&lt;Literals&gt;</span> is a list of identifiers and each <span class="roman">&lt;syntax rule&gt;</span>
2826 should be of the form
2827 </p>
2828 <table><tr><td>&nbsp;</td><td><pre class="format">(<span class="roman">&lt;pattern&gt;</span> <span class="roman">&lt;template&gt;</span>)
2829 </pre></td></tr></table>
2830
2831 <p>The <span class="roman">&lt;pattern&gt;</span> in a <span class="roman">&lt;syntax rule&gt;</span> is a list <span class="roman">&lt;pattern&gt;</span>
2832 that begins with the keyword for the macro.
2833 </p>
2834 <p>A <span class="roman">&lt;pattern&gt;</span> is either an identifier, a constant, or one of the
2835 following
2836 </p>
2837 <table><tr><td>&nbsp;</td><td><pre class="format">(<span class="roman">&lt;pattern&gt;</span> &hellip;)
2838 (<span class="roman">&lt;pattern&gt;</span> <span class="roman">&lt;pattern&gt;</span> &hellip; . <span class="roman">&lt;pattern&gt;</span>)
2839 (<span class="roman">&lt;pattern&gt;</span> &hellip; <span class="roman">&lt;pattern&gt;</span> <span class="roman">&lt;ellipsis&gt;</span>)
2840 #(<span class="roman">&lt;pattern&gt;</span> &hellip;)
2841 #(<span class="roman">&lt;pattern&gt;</span> &hellip; <span class="roman">&lt;pattern&gt;</span> <span class="roman">&lt;ellipsis&gt;</span>)
2842 </pre></td></tr></table>
2843
2844 <p>and a template is either an identifier, a constant, or one of the following
2845 </p>
2846 <table><tr><td>&nbsp;</td><td><pre class="format">(<span class="roman">&lt;element&gt;</span> &hellip;)
2847 (<span class="roman">&lt;element&gt;</span> <span class="roman">&lt;element&gt;</span> &hellip; . <span class="roman">&lt;template&gt;</span>)
2848 #(<span class="roman">&lt;element&gt;</span> &hellip;)
2849 </pre></td></tr></table>
2850
2851 <p>where an <span class="roman">&lt;element&gt;</span> is a <span class="roman">&lt;template&gt;</span> optionally
2852 followed by an <span class="roman">&lt;ellipsis&gt;</span> and
2853 an <span class="roman">&lt;ellipsis&gt;</span> is the identifier &ldquo;<samp>...</samp>&rdquo; (which cannot be used as
2854 an identifier in either a template or a pattern).
2855 <a name="index-_002e_002e_002e-1"></a>
2856 </p>
2857 <p><em>Semantics:</em> An instance of <samp>syntax-rules</samp> produces a new macro
2858 transformer by specifying a sequence of hygienic rewrite rules. A use
2859 of a macro whose keyword is associated with a transformer specified by
2860 <samp>syntax-rules</samp> is matched against the patterns contained in the
2861 <span class="roman">&lt;syntax rule&gt;</span>s, beginning with the leftmost <span class="roman">&lt;syntax rule&gt;</span>.
2862 When a match is found, the macro use is transcribed hygienically
2863 according to the template.
2864 </p>
2865 <p>An identifier that appears in the pattern of a <span class="roman">&lt;syntax rule&gt;</span> is
2866 a <em>pattern variable</em>, unless it is the keyword that begins the pattern,
2867 is listed in <span class="roman">&lt;literals&gt;</span>, or is the identifier &ldquo;<samp>...</samp>&rdquo;.
2868 Pattern variables match arbitrary input elements and
2869 are used to refer to elements of the input in the template. It is an
2870 error for the same pattern variable to appear more than once in a
2871 <span class="roman">&lt;pattern&gt;</span>.
2872 </p>
2873 <p>The keyword at the beginning of the pattern in a
2874 <span class="roman">&lt;syntax rule&gt;</span> is not involved in the matching and
2875 is not considered a pattern variable or literal identifier.
2876 </p>
2877
2878 <blockquote><p><em>Rationale:</em>
2879 The scope of the keyword is determined by the expression or syntax
2880 definition that binds it to the associated macro transformer.
2881 If the keyword were a pattern variable or literal
2882 identifier, then
2883 the template that follows the pattern would be within its scope
2884 regardless of whether the keyword were bound by <samp>let-syntax</samp>
2885 or by <samp>letrec-syntax</samp>.
2886 </p></blockquote>
2887
2888
2889 <p>Identifiers that appear in <span class="roman">&lt;literals&gt;</span> are interpreted as literal
2890 identifiers to be matched against corresponding subforms of the input.
2891 A subform
2892 in the input matches a literal identifier if and only if it is an
2893 identifier
2894 and either both its occurrence in the macro expression and its
2895 occurrence in the macro definition have the same lexical binding, or
2896 the two identifiers are equal and both have no lexical binding.
2897 </p>
2898
2899 <p>A subpattern followed by <samp>...</samp> can match zero or more elements of the
2900 input. It is an error for <samp>...</samp> to appear in <span class="roman">&lt;literals&gt;</span>.
2901 Within a pattern the identifier <samp>...</samp> must follow the last element of
2902 a nonempty sequence of subpatterns.
2903 </p>
2904 <p>More formally, an input form F matches a pattern P if and only if:
2905 </p>
2906
2907
2908 <ul>
2909 <li>
2910 P is a non-literal identifier; or
2911
2912 </li><li>
2913 P is a literal identifier and F is an identifier with the same
2914 binding; or
2915
2916 </li><li>
2917 P is a list <samp>(P_1 &hellip; P_n)</samp> and F is a
2918 list of n
2919 forms that match P_1 through P_n, respectively; or
2920
2921 </li><li>
2922 P is an improper list
2923 <samp>(P_1 P_2 &hellip; P_n . P_n+1)</samp>
2924 and F is a list or
2925 improper list of n or more forms that match P_1 through P_n,
2926 respectively, and whose nth &ldquo;cdr&rdquo; matches P_n+1; or
2927
2928 </li><li>
2929 P is of the form
2930 <samp>(P_1 &hellip; P_n P_n+1 &lt;ellipsis&gt;)</samp>
2931 where &lt;ellipsis&gt; is the identifier <samp>...</samp>
2932 and F is
2933 a proper list of at least n forms, the first n of which match
2934 P_1 through P_n, respectively, and each remaining element of F
2935 matches P_n+1; or
2936
2937 </li><li>
2938 P is a vector of the form <samp>#(P_1 &hellip; P_n)</samp>
2939 and F is a vector
2940 of n forms that match P_1 through P_n; or
2941
2942 </li><li>
2943 P is of the form
2944 <samp>#(P_1 &hellip; P_n P_n+1 &lt;ellipsis&gt;)</samp>
2945 where &lt;ellipsis&gt; is the identifier <samp>...</samp>
2946 and F is a vector of n
2947 or more forms the first n of which match
2948 P_1 through P_n, respectively, and each remaining element of F
2949 matches P_n+1; or
2950
2951 </li><li>
2952 P is a datum and F is equal to P in the sense of
2953 the <samp>equal?</samp> procedure.
2954
2955 </li></ul>
2956
2957
2958 <p>It is an error to use a macro keyword, within the scope of its
2959 binding, in an expression that does not match any of the patterns.
2960 </p>
2961 <p>When a macro use is transcribed according to the template of the
2962 matching <span class="roman">&lt;syntax rule&gt;</span>, pattern variables that occur in the
2963 template are replaced by the subforms they match in the input.
2964 Pattern variables that occur in subpatterns followed by one or more
2965 instances of the identifier
2966 <samp>...</samp> are allowed only in subtemplates that are
2967 followed by as many instances of <samp>...</samp>.
2968 They are replaced in the
2969 output by all of the subforms they match in the input, distributed as
2970 indicated. It is an error if the output cannot be built up as
2971 specified.
2972 </p>
2973
2974 <p>Identifiers that appear in the template but are not pattern variables
2975 or the identifier
2976 <samp>...</samp> are inserted into the output as literal identifiers. If a
2977 literal identifier is inserted as a free identifier then it refers to the
2978 binding of that identifier within whose scope the instance of
2979 <samp>syntax-rules</samp> appears.
2980 If a literal identifier is inserted as a bound identifier then it is
2981 in effect renamed to prevent inadvertent captures of free identifiers.
2982 </p>
2983 <p>As an example, if <code>let</code> and <code>cond</code> are defined as in
2984 <a name="index-cond-1"></a>
2985 <a name="index-let-3"></a>
2986 section <a href="#Derived-expression-type">Derived expression types</a> then they are hygienic (as required) and
2987 the following is not an error.
2988 </p>
2989
2990 <table><tr><td>&nbsp;</td><td><pre class="format">(let ((=&gt; #f))
2991 (cond (#t =&gt; 'ok))) ==&gt; ok
2992 </pre></td></tr></table>
2993
2994
2995 <p>The macro transformer for <samp>cond</samp> recognizes <samp>=&gt;</samp>
2996 as a local variable, and hence an expression, and not as the
2997 top-level identifier <samp>=&gt;</samp>, which the macro transformer treats
2998 as a syntactic keyword. Thus the example expands into
2999 </p>
3000
3001 <table><tr><td>&nbsp;</td><td><pre class="format">(let ((=&gt; #f))
3002 (if #t (begin =&gt; 'ok)))
3003 </pre></td></tr></table>
3004
3005
3006 <p>instead of
3007 </p>
3008
3009 <table><tr><td>&nbsp;</td><td><pre class="format">(let ((=&gt; #f))
3010 (let ((temp #t))
3011 (if temp ('ok temp))))
3012 </pre></td></tr></table>
3013
3014
3015 <p>which would result in an invalid procedure call.
3016 </p>
3017
3018
3019
3020
3021
3022 <a name="Program-structure"></a><hr size="1"><br/><br/><br/>
3023 <table cellpadding="1" cellspacing="1" border="0">
3024 <tr><td valign="middle" align="left"><a href="#Pattern-language" title="Previous section in reading order"><img src="button-left.png" border="0" alt="Back: 4.3.2 Pattern language" align="middle" width="32"></a></td>
3025 <td valign="middle" align="left"><a href="#Programs" title="Next section in reading order"><img src="button-right.png" border="0" alt="Forward: 5.1 Programs" align="middle" width="32"></a></td>
3026 <td valign="middle" align="left"> &nbsp; </td>
3027 <td valign="middle" align="left"><a href="#Expressions" title="Beginning of this chapter or previous chapter"><img src="button-left-left.png" border="0" alt="FastBack: 4. Expressions" align="middle" width="32"></a></td>
3028 <td valign="middle" align="left"><a href="#Top" title="Up section"><img src="button-up.png" border="0" alt="Up: Revised(5) Report on the Algorithmic Language Scheme" align="middle" width="32"></a></td>
3029 <td valign="middle" align="left"><a href="#Standard-procedures" title="Next chapter"><img src="button-right-right.png" border="0" alt="FastForward: 6. Standard procedures" align="middle" width="32"></a></td>
3030 <td valign="middle" align="left"><a href="#Top" title="Cover (top) of document"><img src="button-up-arrow.png" border="0" alt="Top: Revised(5) Report on the Algorithmic Language Scheme" align="middle" width="32"></a></td>
3031 <td valign="middle" align="left"><a href="#SEC_Contents" title="Table of contents"><img src="button-compass.png" border="0" alt="Contents: Table of Contents" align="middle" width="32"></a></td>
3032 <td valign="middle" align="left"><a href="#Index" title="Index"><img src="button-abc.png" border="0" alt="Index: Alphabetic index of definitions of concepts, keywords, and procedures" align="middle" width="32"></a></td>
3033 </tr></table>
3034 <a name="Program-structure-1"></a>
3035 <h1 class="chapter">5. Program structure</h1>
3036
3037 <table class="menu" border="0" cellspacing="0">
3038 <tr><td align="left" valign="top"><a href="#Programs">5.1 Programs</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
3039 </td></tr>
3040 <tr><td align="left" valign="top"><a href="#Definitions">5.2 Definitions</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
3041 </td></tr>
3042 <tr><td align="left" valign="top"><a href="#Syntax-definitions">5.3 Syntax definitions</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
3043 </td></tr>
3044 </table>
3045
3046
3047
3048 <a name="Programs"></a><hr size="1"><br/><br/><br/>
3049 <table cellpadding="1" cellspacing="1" border="0">
3050 <tr><td valign="middle" align="left"><a href="#Program-structure" title="Previous section in reading order"><img src="button-left.png" border="0" alt="Back: 5. Program structure" align="middle" width="32"></a></td>
3051 <td valign="middle" align="left"><a href="#Definitions" title="Next section in reading order"><img src="button-right.png" border="0" alt="Forward: 5.2 Definitions" align="middle" width="32"></a></td>
3052 <td valign="middle" align="left"> &nbsp; </td>
3053 <td valign="middle" align="left"><a href="#Program-structure" title="Beginning of this chapter or previous chapter"><img src="button-left-left.png" border="0" alt="FastBack: 5. Program structure" align="middle" width="32"></a></td>
3054 <td valign="middle" align="left"><a href="#Program-structure" title="Up section"><img src="button-up.png" border="0" alt="Up: 5. Program structure" align="middle" width="32"></a></td>
3055 <td valign="middle" align="left"><a href="#Standard-procedures" title="Next chapter"><img src="button-right-right.png" border="0" alt="FastForward: 6. Standard procedures" align="middle" width="32"></a></td>
3056 <td valign="middle" align="left"><a href="#Top" title="Cover (top) of document"><img src="button-up-arrow.png" border="0" alt="Top: Revised(5) Report on the Algorithmic Language Scheme" align="middle" width="32"></a></td>
3057 <td valign="middle" align="left"><a href="#SEC_Contents" title="Table of contents"><img src="button-compass.png" border="0" alt="Contents: Table of Contents" align="middle" width="32"></a></td>
3058 <td valign="middle" align="left"><a href="#Index" title="Index"><img src="button-abc.png" border="0" alt="Index: Alphabetic index of definitions of concepts, keywords, and procedures" align="middle" width="32"></a></td>
3059 </tr></table>
3060 <a name="Programs-1"></a>
3061 <h2 class="section">5.1 Programs</h2>
3062
3063
3064 <p>A Scheme program consists of a sequence of expressions, definitions,
3065 and syntax definitions.
3066 Expressions are described in chapter <a href="#Expressions">Expressions</a>;
3067 definitions and syntax definitions are the subject of the rest of the
3068 present chapter.
3069 </p>
3070 <p>Programs are typically stored in files or entered interactively to a
3071 running Scheme system, although other paradigms are possible;
3072 questions of user interface lie outside the scope of this report.
3073 (Indeed, Scheme would still be useful as a notation for expressing
3074 computational methods even in the absence of a mechanical
3075 implementation.)
3076 </p>
3077 <p>Definitions and syntax definitions occurring at the top level of a program
3078 can be interpreted
3079 declaratively.
3080 They cause bindings to be created in the top level
3081 environment or modify the value of existing top-level bindings.
3082 Expressions occurring at the top level of a program are
3083 interpreted imperatively; they are executed in order when the program is
3084 invoked or loaded, and typically perform some kind of initialization.
3085 </p>
3086 <p>At the top level of a program <tt>(begin <span class="roman">&lt;form1&gt;</span> &hellip;)</tt> is
3087 equivalent to the sequence of expressions, definitions, and syntax definitions
3088 that form the body of the <code>begin</code>.
3089 <a name="index-begin-1"></a>
3090 </p>
3091
3092
3093 <a name="Definitions"></a><hr size="1"><br/><br/><br/>
3094 <table cellpadding="1" cellspacing="1" border="0">
3095 <tr><td valign="middle" align="left"><a href="#Programs" title="Previous section in reading order"><img src="button-left.png" border="0" alt="Back: 5.1 Programs" align="middle" width="32"></a></td>
3096 <td valign="middle" align="left"><a href="#Top-level-definitions" title="Next section in reading order"><img src="button-right.png" border="0" alt="Forward: 5.2.1 Top level definitions" align="middle" width="32"></a></td>
3097 <td valign="middle" align="left"> &nbsp; </td>
3098 <td valign="middle" align="left"><a href="#Program-structure" title="Beginning of this chapter or previous chapter"><img src="button-left-left.png" border="0" alt="FastBack: 5. Program structure" align="middle" width="32"></a></td>
3099 <td valign="middle" align="left"><a href="#Program-structure" title="Up section"><img src="button-up.png" border="0" alt="Up: 5. Program structure" align="middle" width="32"></a></td>
3100 <td valign="middle" align="left"><a href="#Standard-procedures" title="Next chapter"><img src="button-right-right.png" border="0" alt="FastForward: 6. Standard procedures" align="middle" width="32"></a></td>
3101 <td valign="middle" align="left"><a href="#Top" title="Cover (top) of document"><img src="button-up-arrow.png" border="0" alt="Top: Revised(5) Report on the Algorithmic Language Scheme" align="middle" width="32"></a></td>
3102 <td valign="middle" align="left"><a href="#SEC_Contents" title="Table of contents"><img src="button-compass.png" border="0" alt="Contents: Table of Contents" align="middle" width="32"></a></td>
3103 <td valign="middle" align="left"><a href="#Index" title="Index"><img src="button-abc.png" border="0" alt="Index: Alphabetic index of definitions of concepts, keywords, and procedures" align="middle" width="32"></a></td>
3104 </tr></table>
3105 <a name="Definitions-1"></a>
3106 <h2 class="section">5.2 Definitions</h2>
3107
3108 <table class="menu" border="0" cellspacing="0">
3109 <tr><td align="left" valign="top"><a href="#Top-level-definitions">5.2.1 Top level definitions</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
3110 </td></tr>
3111 <tr><td align="left" valign="top"><a href="#Internal-definitions">5.2.2 Internal definitions</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
3112 </td></tr>
3113 </table>
3114
3115
3116
3117 <p>Definitions are valid in some, but not all, contexts where expressions
3118 are allowed. They are valid only at the top level of a <span class="roman">&lt;program&gt;</span>
3119 and at the beginning of a <span class="roman">&lt;body&gt;</span>.
3120 </p>
3121 <a name="index-definition"></a>
3122
3123 <p>A definition should have one of the following forms:
3124 <a name="index-define-1"></a>
3125 </p>
3126
3127
3128 <ul>
3129 <li> <tt>(define <span class="roman">&lt;variable&gt;</span> <span class="roman">&lt;expression&gt;</span>)</tt>
3130
3131 </li><li> <tt>(define (<span class="roman">&lt;variable&gt;</span> <span class="roman">&lt;formals&gt;</span>) <span class="roman">&lt;body&gt;</span>)</tt>
3132
3133 <p><span class="roman">&lt;Formals&gt;</span> should be either a
3134 sequence of zero or more variables, or a sequence of one or more
3135 variables followed by a space-delimited period and another variable (as
3136 in a lambda expression). This form is equivalent to
3137 </p>
3138 <table><tr><td>&nbsp;</td><td><pre class="example">
3139 (define <span class="roman">&lt;variable&gt;</span>
3140 (lambda (<span class="roman">&lt;formals&gt;</span>) <span class="roman">&lt;body&gt;</span>))<span class="roman">.</span>
3141 </pre></td></tr></table>
3142
3143
3144 </li><li> <tt>(define (<span class="roman">&lt;variable&gt;</span> . <span class="roman">&lt;formal&gt;</span>) <span class="roman">&lt;body&gt;</span>)</tt>
3145
3146 <p><span class="roman">&lt;Formal&gt;</span> should be a single
3147 variable. This form is equivalent to
3148 </p>
3149 <table><tr><td>&nbsp;</td><td><pre class="example">
3150 (define <span class="roman">&lt;variable&gt;</span>
3151 (lambda <span class="roman">&lt;formal&gt;</span> <span class="roman">&lt;body&gt;</span>))<span class="roman">.</span>
3152 </pre></td></tr></table>
3153
3154
3155
3156 </li></ul>
3157
3158
3159 <a name="Top-level-definitions"></a><hr size="1"><br/><br/><br/>
3160 <table cellpadding="1" cellspacing="1" border="0">
3161 <tr><td valign="middle" align="left"><a href="#Definitions" title="Previous section in reading order"><img src="button-left.png" border="0" alt="Back: 5.2 Definitions" align="middle" width="32"></a></td>
3162 <td valign="middle" align="left"><a href="#Internal-definitions" title="Next section in reading order"><img src="button-right.png" border="0" alt="Forward: 5.2.2 Internal definitions" align="middle" width="32"></a></td>
3163 <td valign="middle" align="left"> &nbsp; </td>
3164 <td valign="middle" align="left"><a href="#Program-structure" title="Beginning of this chapter or previous chapter"><img src="button-left-left.png" border="0" alt="FastBack: 5. Program structure" align="middle" width="32"></a></td>
3165 <td valign="middle" align="left"><a href="#Definitions" title="Up section"><img src="button-up.png" border="0" alt="Up: 5.2 Definitions" align="middle" width="32"></a></td>
3166 <td valign="middle" align="left"><a href="#Standard-procedures" title="Next chapter"><img src="button-right-right.png" border="0" alt="FastForward: 6. Standard procedures" align="middle" width="32"></a></td>
3167 <td valign="middle" align="left"><a href="#Top" title="Cover (top) of document"><img src="button-up-arrow.png" border="0" alt="Top: Revised(5) Report on the Algorithmic Language Scheme" align="middle" width="32"></a></td>
3168 <td valign="middle" align="left"><a href="#SEC_Contents" title="Table of contents"><img src="button-compass.png" border="0" alt="Contents: Table of Contents" align="middle" width="32"></a></td>
3169 <td valign="middle" align="left"><a href="#Index" title="Index"><img src="button-abc.png" border="0" alt="Index: Alphabetic index of definitions of concepts, keywords, and procedures" align="middle" width="32"></a></td>
3170 </tr></table>
3171 <a name="Top-level-definitions-1"></a>
3172 <h3 class="subsection">5.2.1 Top level definitions</h3>
3173
3174
3175 <p>At the top level of a program, a definition
3176 </p>
3177 <table><tr><td>&nbsp;</td><td><pre class="example">
3178 (define <span class="roman">&lt;variable&gt;</span> <span class="roman">&lt;expression&gt;</span>)
3179 </pre></td></tr></table>
3180
3181 <p>has essentially the same effect as the assignment expression
3182 </p>
3183 <table><tr><td>&nbsp;</td><td><pre class="example">
3184 (set! <span class="roman">&lt;variable&gt;</span> <span class="roman">&lt;expression&gt;</span>)
3185 </pre></td></tr></table>
3186
3187 <p>if <span class="roman">&lt;variable&gt;</span> is bound. If <span class="roman">&lt;variable&gt;</span> is not bound,
3188 however, then the definition will bind <span class="roman">&lt;variable&gt;</span> to a new
3189 location before performing the assignment, whereas it would be an error
3190 to perform a <samp>set!</samp> on an unbound variable.
3191 <a name="index-unbound-2"></a>
3192 </p>
3193
3194 <table><tr><td>&nbsp;</td><td><pre class="example">
3195 (define add3
3196 (lambda (x) (+ x 3)))
3197 (add3 3) ==&gt; 6
3198 (define first car)
3199 (first '(1 2)) ==&gt; 1
3200 </pre></td></tr></table>
3201
3202
3203 <p>Some implementations of Scheme use an initial environment in
3204 which all possible variables are bound to locations, most of
3205 which contain undefined values. Top level definitions in
3206 such an implementation are truly equivalent to assignments.
3207 </p>
3208
3209
3210
3211 <a name="Internal-definitions"></a><hr size="1"><br/><br/><br/>
3212 <table cellpadding="1" cellspacing="1" border="0">
3213 <tr><td valign="middle" align="left"><a href="#Top-level-definitions" title="Previous section in reading order"><img src="button-left.png" border="0" alt="Back: 5.2.1 Top level definitions" align="middle" width="32"></a></td>
3214 <td valign="middle" align="left"><a href="#Syntax-definitions" title="Next section in reading order"><img src="button-right.png" border="0" alt="Forward: 5.3 Syntax definitions" align="middle" width="32"></a></td>
3215 <td valign="middle" align="left"> &nbsp; </td>
3216 <td valign="middle" align="left"><a href="#Program-structure" title="Beginning of this chapter or previous chapter"><img src="button-left-left.png" border="0" alt="FastBack: 5. Program structure" align="middle" width="32"></a></td>
3217 <td valign="middle" align="left"><a href="#Definitions" title="Up section"><img src="button-up.png" border="0" alt="Up: 5.2 Definitions" align="middle" width="32"></a></td>
3218 <td valign="middle" align="left"><a href="#Standard-procedures" title="Next chapter"><img src="button-right-right.png" border="0" alt="FastForward: 6. Standard procedures" align="middle" width="32"></a></td>
3219 <td valign="middle" align="left"><a href="#Top" title="Cover (top) of document"><img src="button-up-arrow.png" border="0" alt="Top: Revised(5) Report on the Algorithmic Language Scheme" align="middle" width="32"></a></td>
3220 <td valign="middle" align="left"><a href="#SEC_Contents" title="Table of contents"><img src="button-compass.png" border="0" alt="Contents: Table of Contents" align="middle" width="32"></a></td>
3221 <td valign="middle" align="left"><a href="#Index" title="Index"><img src="button-abc.png" border="0" alt="Index: Alphabetic index of definitions of concepts, keywords, and procedures" align="middle" width="32"></a></td>
3222 </tr></table>
3223 <a name="Internal-definitions-1"></a>
3224 <h3 class="subsection">5.2.2 Internal definitions</h3>
3225
3226
3227
3228 <p>Definitions may occur at the
3229 beginning of a <span class="roman">&lt;body&gt;</span> (that is, the body of a <code>lambda</code>,
3230 <a name="index-lambda-1"></a>
3231 <code>let</code>, <code>let*</code>, <code>letrec</code>, <code>let-syntax</code>, or <code>letrec-syntax</code>
3232 <a name="index-letrec_002dsyntax-1"></a>
3233 <a name="index-let_002dsyntax-1"></a>
3234 <a name="index-letrec-1"></a>
3235 <a name="index-let_002a-1"></a>
3236 <a name="index-let-4"></a>
3237 expression or that of a definition of an appropriate form).
3238 Such definitions are known as <em>internal definitions</em> as opposed to the top level definitions described above.
3239 <a name="index-internal-definition"></a>
3240 The variable defined by an internal definition is local to the
3241 <span class="roman">&lt;body&gt;</span>. That is, <span class="roman">&lt;variable&gt;</span> is bound rather than assigned,
3242 and the region of the binding is the entire <span class="roman">&lt;body&gt;</span>. For example,
3243 </p>
3244
3245 <table><tr><td>&nbsp;</td><td><pre class="example">
3246 (let ((x 5))
3247 (define foo (lambda (y) (bar x y)))
3248 (define bar (lambda (a b) (+ (* a b) a)))
3249 (foo (+ x 3))) ==&gt; 45
3250 </pre></td></tr></table>
3251
3252
3253 <p>A <span class="roman">&lt;body&gt;</span> containing internal definitions can always be converted
3254 into a completely equivalent <samp>letrec</samp> expression. For example, the
3255 <samp>let</samp> expression in the above example is equivalent to
3256 </p>
3257
3258 <table><tr><td>&nbsp;</td><td><pre class="example">
3259 (let ((x 5))
3260 (letrec ((foo (lambda (y) (bar x y)))
3261 (bar (lambda (a b) (+ (* a b) a))))
3262 (foo (+ x 3))))
3263 </pre></td></tr></table>
3264
3265
3266 <p>Just as for the equivalent <samp>letrec</samp> expression, it must be
3267 possible to evaluate each <span class="roman">&lt;expression&gt;</span> of every internal
3268 definition in a <span class="roman">&lt;body&gt;</span> without assigning or referring to
3269 the value of any <span class="roman">&lt;variable&gt;</span> being defined.
3270 </p>
3271 <p>Wherever an internal definition may occur
3272 <tt>(begin <span class="roman">&lt;definition1&gt;</span> &hellip;)</tt>
3273 is equivalent to the sequence of definitions
3274 that form the body of the <code>begin</code>.
3275 <a name="index-begin-2"></a>
3276 </p>
3277 <a name="Syntax-definitions"></a><hr size="1"><br/><br/><br/>
3278 <table cellpadding="1" cellspacing="1" border="0">
3279 <tr><td valign="middle" align="left"><a href="#Internal-definitions" title="Previous section in reading order"><img src="button-left.png" border="0" alt="Back: 5.2.2 Internal definitions" align="middle" width="32"></a></td>
3280 <td valign="middle" align="left"><a href="#Standard-procedures" title="Next section in reading order"><img src="button-right.png" border="0" alt="Forward: 6. Standard procedures" align="middle" width="32"></a></td>
3281 <td valign="middle" align="left"> &nbsp; </td>
3282 <td valign="middle" align="left"><a href="#Program-structure" title="Beginning of this chapter or previous chapter"><img src="button-left-left.png" border="0" alt="FastBack: 5. Program structure" align="middle" width="32"></a></td>
3283 <td valign="middle" align="left"><a href="#Program-structure" title="Up section"><img src="button-up.png" border="0" alt="Up: 5. Program structure" align="middle" width="32"></a></td>
3284 <td valign="middle" align="left"><a href="#Standard-procedures" title="Next chapter"><img src="button-right-right.png" border="0" alt="FastForward: 6. Standard procedures" align="middle" width="32"></a></td>
3285 <td valign="middle" align="left"><a href="#Top" title="Cover (top) of document"><img src="button-up-arrow.png" border="0" alt="Top: Revised(5) Report on the Algorithmic Language Scheme" align="middle" width="32"></a></td>
3286 <td valign="middle" align="left"><a href="#SEC_Contents" title="Table of contents"><img src="button-compass.png" border="0" alt="Contents: Table of Contents" align="middle" width="32"></a></td>
3287 <td valign="middle" align="left"><a href="#Index" title="Index"><img src="button-abc.png" border="0" alt="Index: Alphabetic index of definitions of concepts, keywords, and procedures" align="middle" width="32"></a></td>
3288 </tr></table>
3289 <a name="Syntax-definitions-1"></a>
3290 <h2 class="section">5.3 Syntax definitions</h2>
3291
3292
3293 <p>Syntax definitions are valid only at the top level of a <span class="roman">&lt;program&gt;</span>.
3294 </p>
3295 <a name="index-syntax-definition"></a>
3296 <p>They have the following form:
3297 <a name="index-define_002dsyntax"></a>
3298 </p>
3299 <p><tt>(define-syntax <span class="roman">&lt;keyword&gt;</span> <span class="roman">&lt;transformer spec&gt;</span>)</tt>
3300 </p>
3301 <p><span class="roman">&lt;Keyword&gt;</span> is an identifier, and
3302 the <span class="roman">&lt;transformer spec&gt;</span> should be an instance of <code>syntax-rules</code>.
3303 <a name="index-syntax_002drules-1"></a>
3304 The top-level syntactic environment is extended by binding the
3305 <span class="roman">&lt;keyword&gt;</span> to the specified transformer.
3306 </p>
3307 <p>There is no <samp>define-syntax</samp> analogue of internal definitions.
3308 </p>
3309
3310
3311
3312 <p>Although macros may expand into definitions and syntax definitions in
3313 any context that permits them, it is an error for a definition or syntax
3314 definition to shadow a syntactic keyword whose meaning is needed to
3315 determine whether some form in the group of forms that contains the
3316 shadowing definition is in fact a definition, or, for internal definitions,
3317 is needed to determine the boundary between the group and the expressions
3318 that follow the group. For example, the following are errors:
3319 </p>
3320
3321 <table><tr><td>&nbsp;</td><td><pre class="example">
3322 (define define 3)
3323
3324 (begin (define begin list))
3325
3326 (let-syntax
3327 ((foo (syntax-rules ()
3328 ((foo (proc args ...) body ...)
3329 (define proc
3330 (lambda (args ...)
3331 body ...))))))
3332 (let ((x 3))
3333 (foo (plus x y) (+ x y))
3334 (define foo x)
3335 (plus foo x)))
3336 </pre></td></tr></table>
3337
3338
3339
3340
3341
3342
3343 <a name="Standard-procedures"></a><hr size="1"><br/><br/><br/>
3344 <table cellpadding="1" cellspacing="1" border="0">
3345 <tr><td valign="middle" align="left"><a href="#Syntax-definitions" title="Previous section in reading order"><img src="button-left.png" border="0" alt="Back: 5.3 Syntax definitions" align="middle" width="32"></a></td>
3346 <td valign="middle" align="left"><a href="#Equivalence-predicates" title="Next section in reading order"><img src="button-right.png" border="0" alt="Forward: 6.1 Equivalence predicates" align="middle" width="32"></a></td>
3347 <td valign="middle" align="left"> &nbsp; </td>
3348 <td valign="middle" align="left"><a href="#Program-structure" title="Beginning of this chapter or previous chapter"><img src="button-left-left.png" border="0" alt="FastBack: 5. Program structure" align="middle" width="32"></a></td>
3349 <td valign="middle" align="left"><a href="#Top" title="Up section"><img src="button-up.png" border="0" alt="Up: Revised(5) Report on the Algorithmic Language Scheme" align="middle" width="32"></a></td>
3350 <td valign="middle" align="left"><a href="#Formal-syntax-and-semantics" title="Next chapter"><img src="button-right-right.png" border="0" alt="FastForward: 7. Formal syntax and semantics" align="middle" width="32"></a></td>
3351 <td valign="middle" align="left"><a href="#Top" title="Cover (top) of document"><img src="button-up-arrow.png" border="0" alt="Top: Revised(5) Report on the Algorithmic Language Scheme" align="middle" width="32"></a></td>
3352 <td valign="middle" align="left"><a href="#SEC_Contents" title="Table of contents"><img src="button-compass.png" border="0" alt="Contents: Table of Contents" align="middle" width="32"></a></td>
3353 <td valign="middle" align="left"><a href="#Index" title="Index"><img src="button-abc.png" border="0" alt="Index: Alphabetic index of definitions of concepts, keywords, and procedures" align="middle" width="32"></a></td>
3354 </tr></table>
3355 <a name="Standard-procedures-1"></a>
3356 <h1 class="chapter">6. Standard procedures</h1>
3357
3358 <table class="menu" border="0" cellspacing="0">
3359 <tr><td align="left" valign="top"><a href="#Equivalence-predicates">6.1 Equivalence predicates</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
3360 </td></tr>
3361 <tr><td align="left" valign="top"><a href="#Numbers">6.2 Numbers</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
3362 </td></tr>
3363 <tr><td align="left" valign="top"><a href="#Other-data-types">6.3 Other data types</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
3364 </td></tr>
3365 <tr><td align="left" valign="top"><a href="#Control-features">6.4 Control features</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
3366 </td></tr>
3367 <tr><td align="left" valign="top"><a href="#Eval">6.5 Eval</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
3368 </td></tr>
3369 <tr><td align="left" valign="top"><a href="#Input-and-output">6.6 Input and output</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
3370 </td></tr>
3371 </table>
3372
3373
3374
3375
3376
3377 <a name="index-initial-environment"></a>
3378
3379 <a name="index-top-level-environment-1"></a>
3380
3381 <a name="index-library-procedure"></a>
3382
3383 <p>This chapter describes Scheme's built-in procedures. The initial (or
3384 &ldquo;top level&rdquo;) Scheme environment starts out with a number of variables
3385 bound to locations containing useful values, most of which are primitive
3386 procedures that manipulate data. For example, the variable <samp>abs</samp> is
3387 bound to (a location initially containing) a procedure of one argument
3388 that computes the absolute value of a number, and the variable <samp>+</samp>
3389 is bound to a procedure that computes sums. Built-in procedures that
3390 can easily be written in terms of other built-in procedures are identified as
3391 &ldquo;library procedures&rdquo;.
3392 </p>
3393 <p>A program may use a top-level definition to bind any variable. It may
3394 subsequently alter any such binding by an assignment (see see section <a href="#Assignments">Assignments</a>).
3395 These operations do not modify the behavior of Scheme's built-in
3396 procedures. Altering any top-level binding that has not been introduced by a
3397 definition has an unspecified effect on the behavior of the built-in procedures.
3398 </p>
3399 <a name="Equivalence-predicates"></a><hr size="1"><br/><br/><br/>
3400 <table cellpadding="1" cellspacing="1" border="0">
3401 <tr><td valign="middle" align="left"><a href="#Standard-procedures" title="Previous section in reading order"><img src="button-left.png" border="0" alt="Back: 6. Standard procedures" align="middle" width="32"></a></td>
3402 <td valign="middle" align="left"><a href="#Numbers" title="Next section in reading order"><img src="button-right.png" border="0" alt="Forward: 6.2 Numbers" align="middle" width="32"></a></td>
3403 <td valign="middle" align="left"> &nbsp; </td>
3404 <td valign="middle" align="left"><a href="#Standard-procedures" title="Beginning of this chapter or previous chapter"><img src="button-left-left.png" border="0" alt="FastBack: 6. Standard procedures" align="middle" width="32"></a></td>
3405 <td valign="middle" align="left"><a href="#Standard-procedures" title="Up section"><img src="button-up.png" border="0" alt="Up: 6. Standard procedures" align="middle" width="32"></a></td>
3406 <td valign="middle" align="left"><a href="#Formal-syntax-and-semantics" title="Next chapter"><img src="button-right-right.png" border="0" alt="FastForward: 7. Formal syntax and semantics" align="middle" width="32"></a></td>
3407 <td valign="middle" align="left"><a href="#Top" title="Cover (top) of document"><img src="button-up-arrow.png" border="0" alt="Top: Revised(5) Report on the Algorithmic Language Scheme" align="middle" width="32"></a></td>
3408 <td valign="middle" align="left"><a href="#SEC_Contents" title="Table of contents"><img src="button-compass.png" border="0" alt="Contents: Table of Contents" align="middle" width="32"></a></td>
3409 <td valign="middle" align="left"><a href="#Index" title="Index"><img src="button-abc.png" border="0" alt="Index: Alphabetic index of definitions of concepts, keywords, and procedures" align="middle" width="32"></a></td>
3410 </tr></table>
3411 <a name="Equivalence-predicates-1"></a>
3412 <h2 class="section">6.1 Equivalence predicates</h2>
3413
3414
3415
3416 <p>A <em>predicate</em> is a procedure that always returns a boolean
3417 <a name="index-predicate"></a>
3418 value (<tt>#t</tt> or <tt>#f</tt>). An <em>equivalence predicate</em> is
3419 <a name="index-equivalence-predicate"></a>
3420 the computational analogue of a mathematical equivalence relation (it is
3421 symmetric, reflexive, and transitive). Of the equivalence predicates
3422 described in this section, <samp>eq?</samp> is the finest or most
3423 discriminating, and <samp>equal?</samp> is the coarsest. <samp>Eqv?</samp> is
3424 slightly less discriminating than <samp>eq?</samp>.
3425 </p>
3426
3427
3428
3429 <a name="Definition_of_eqv?"></a><a name="Procedure_eqv?"></a><a name="index-eqv_003f-2"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Procedure_eqv?">eqv?</a></b></code><i> obj1 obj2</i><code>)</code></td><td align="right">procedure</td></tr></table>
3430
3431 <p>The <samp>eqv?</samp> procedure defines a useful equivalence relation on objects.
3432 Briefly, it returns <tt>#t</tt> if <var>obj1</var> and <var>obj2</var> should
3433 normally be regarded as the same object. This relation is left slightly
3434 open to interpretation, but the following partial specification of
3435 <samp>eqv?</samp> holds for all implementations of Scheme.
3436 </p>
3437 <p>The <samp>eqv?</samp> procedure returns <tt>#t</tt> if:
3438 </p>
3439
3440
3441 <ul>
3442 <li>
3443 <var>obj1</var> and <var>obj2</var> are both <tt>#t</tt> or both <tt>#f</tt>.
3444
3445 </li><li>
3446 <var>obj1</var> and <var>obj2</var> are both symbols and
3447
3448
3449 <table><tr><td>&nbsp;</td><td><pre class="format">(string=? (symbol-&gt;string obj1)
3450 (symbol-&gt;string obj2))
3451 ==&gt; #t
3452 </pre></td></tr></table>
3453
3454
3455
3456 <blockquote><p><em>Note:</em>
3457 This assumes that neither <var>obj1</var> nor <var>obj2</var> is an &ldquo;uninterned
3458 symbol&rdquo; as alluded to in section <a href="#Symbols">Symbols</a>. This report does
3459 not presume to specify the behavior of <samp>eqv?</samp> on implementation-dependent
3460 extensions.
3461 </p></blockquote>
3462
3463
3464 </li><li>
3465 <var>obj1</var> and <var>obj2</var> are both numbers, are numerically
3466 equal (see <samp>=</samp>, section see section <a href="#Numbers">Numbers</a>), and are either both
3467 exact or both inexact.
3468
3469 </li><li>
3470 <var>obj1</var> and <var>obj2</var> are both characters and are the same
3471 character according to the <samp>char=?</samp> procedure
3472 (section see section <a href="#Characters">Characters</a>).
3473
3474 </li><li>
3475 both <var>obj1</var> and <var>obj2</var> are the empty list.
3476
3477 </li><li>
3478 <var>obj1</var> and <var>obj2</var> are pairs, vectors, or strings that denote the
3479 same locations in the store (section see section <a href="#Storage-model">Storage model</a>).
3480
3481 </li><li>
3482 <var>obj1</var> and <var>obj2</var> are procedures whose location tags are
3483 equal (section see section <a href="#Procedures">Procedures</a>).
3484
3485 </li></ul>
3486
3487 <a name="index-inexact"></a>
3488 <a name="index-exact"></a>
3489
3490 <p>The <samp>eqv?</samp> procedure returns <tt>#f</tt> if:
3491 </p>
3492
3493
3494 <ul>
3495 <li>
3496 <var>obj1</var> and <var>obj2</var> are of different types
3497 (section see section <a href="#Disjointness-of-types">Disjointness of types</a>).
3498
3499 </li><li>
3500 one of <var>obj1</var> and <var>obj2</var> is <tt>#t</tt> but the other is
3501 <tt>#f</tt>.
3502
3503 </li><li>
3504 <var>obj1</var> and <var>obj2</var> are symbols but
3505
3506
3507 <table><tr><td>&nbsp;</td><td><pre class="format">(string=? (symbol-&gt;string <var>obj1</var>)
3508 (symbol-&gt;string <var>obj2</var>))
3509 ==&gt; #f
3510 </pre></td></tr></table>
3511
3512
3513 </li><li>
3514 one of <var>obj1</var> and <var>obj2</var> is an exact number but the other
3515 is an inexact number.
3516
3517 </li><li>
3518 <var>obj1</var> and <var>obj2</var> are numbers for which the <samp>=</samp>
3519 procedure returns <tt>#f</tt>.
3520
3521 </li><li>
3522 <var>obj1</var> and <var>obj2</var> are characters for which the <samp>char=?</samp>
3523 procedure returns <tt>#f</tt>.
3524
3525 </li><li>
3526 one of <var>obj1</var> and <var>obj2</var> is the empty list but the other
3527 is not.
3528
3529 </li><li>
3530 <var>obj1</var> and <var>obj2</var> are pairs, vectors, or strings that denote
3531 distinct locations.
3532
3533 </li><li>
3534 <var>obj1</var> and <var>obj2</var> are procedures that would behave differently
3535 (return different value(s) or have different side effects) for some arguments.
3536
3537
3538 </li></ul>
3539
3540
3541
3542 <table><tr><td>&nbsp;</td><td><pre class="format">(eqv? 'a 'a) ==&gt; #t
3543 (eqv? 'a 'b) ==&gt; #f
3544 (eqv? 2 2) ==&gt; #t
3545 (eqv? '() '()) ==&gt; #t
3546 (eqv? 100000000 100000000) ==&gt; #t
3547 (eqv? (cons 1 2) (cons 1 2)) ==&gt; #f
3548 (eqv? (lambda () 1)
3549 (lambda () 2)) ==&gt; #f
3550 (eqv? #f 'nil) ==&gt; #f
3551 (let ((p (lambda (x) x)))
3552 (eqv? p p)) ==&gt; #t
3553 </pre></td></tr></table>
3554
3555
3556 <p>The following examples illustrate cases in which the above rules do
3557 not fully specify the behavior of <samp>eqv?</samp>. All that can be said
3558 about such cases is that the value returned by <samp>eqv?</samp> must be a
3559 boolean.
3560 </p>
3561
3562 <table><tr><td>&nbsp;</td><td><pre class="format">(eqv? &quot;&quot; &quot;&quot;) ==&gt; <em>unspecified</em>
3563 (eqv? '#() '#()) ==&gt; <em>unspecified</em>
3564 (eqv? (lambda (x) x)
3565 (lambda (x) x)) ==&gt; <em>unspecified</em>
3566 (eqv? (lambda (x) x)
3567 (lambda (y) y)) ==&gt; <em>unspecified</em>
3568 </pre></td></tr></table>
3569
3570
3571 <p>The next set of examples shows the use of <samp>eqv?</samp> with procedures
3572 that have local state. <samp>Gen-counter</samp> must return a distinct
3573 procedure every time, since each procedure has its own internal counter.
3574 <samp>Gen-loser</samp>, however, returns equivalent procedures each time, since
3575 the local state does not affect the value or side effects of the
3576 procedures.
3577 </p>
3578
3579 <table><tr><td>&nbsp;</td><td><pre class="format">(define gen-counter
3580 (lambda ()
3581 (let ((n 0))
3582 (lambda () (set! n (+ n 1)) n))))
3583 (let ((g (gen-counter)))
3584 (eqv? g g)) ==&gt; #t
3585 (eqv? (gen-counter) (gen-counter))
3586 ==&gt; #f
3587 (define gen-loser
3588 (lambda ()
3589 (let ((n 0))
3590 (lambda () (set! n (+ n 1)) 27))))
3591 (let ((g (gen-loser)))
3592 (eqv? g g)) ==&gt; #t
3593 (eqv? (gen-loser) (gen-loser))
3594 ==&gt; <em>unspecified</em>
3595
3596 (letrec ((f (lambda () (if (eqv? f g) 'both 'f)))
3597 (g (lambda () (if (eqv? f g) 'both 'g))))
3598 (eqv? f g))
3599 ==&gt; <em>unspecified</em>
3600
3601 (letrec ((f (lambda () (if (eqv? f g) 'f 'both)))
3602 (g (lambda () (if (eqv? f g) 'g 'both))))
3603 (eqv? f g))
3604 ==&gt; #f
3605 </pre></td></tr></table>
3606
3607
3608
3609
3610 <p>Since it is an error to modify constant objects (those returned by
3611 literal expressions), implementations are permitted, though not
3612 required, to share structure between constants where appropriate. Thus
3613 the value of <samp>eqv?</samp> on constants is sometimes
3614 implementation-dependent.
3615 </p>
3616
3617 <table><tr><td>&nbsp;</td><td><pre class="format">(eqv? '(a) '(a)) ==&gt; <em>unspecified</em>
3618 (eqv? &quot;a&quot; &quot;a&quot;) ==&gt; <em>unspecified</em>
3619 (eqv? '(b) (cdr '(a b))) ==&gt; <em>unspecified</em>
3620 (let ((x '(a)))
3621 (eqv? x x)) ==&gt; #t
3622 </pre></td></tr></table>
3623
3624
3625
3626 <blockquote><p><em>Rationale:</em>
3627 The above definition of <samp>eqv?</samp> allows implementations latitude in
3628 their treatment of procedures and literals: implementations are free
3629 either to detect or to fail to detect that two procedures or two literals
3630 are equivalent to each other, and can decide whether or not to
3631 merge representations of equivalent objects by using the same pointer or
3632 bit pattern to represent both.
3633 </p></blockquote>
3634
3635
3636
3637
3638
3639
3640 <a name="Definition_of_eq?"></a><a name="Procedure_eq?"></a><a name="index-eq_003f-1"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Procedure_eq?">eq?</a></b></code><i> obj1 obj2</i><code>)</code></td><td align="right">procedure</td></tr></table>
3641
3642 <p><samp>Eq?</samp> is similar to <samp>eqv?</samp> except that in some cases it is
3643 capable of discerning distinctions finer than those detectable by
3644 <samp>eqv?</samp>.
3645 </p>
3646 <p><samp>Eq?</samp> and <samp>eqv?</samp> are guaranteed to have the same
3647 behavior on symbols, booleans, the empty list, pairs, procedures,
3648 and non-empty
3649 strings and vectors. <samp>Eq?</samp>'s behavior on numbers and characters is
3650 implementation-dependent, but it will always return either true or
3651 false, and will return true only when <samp>eqv?</samp> would also return
3652 true. <samp>Eq?</samp> may also behave differently from <samp>eqv?</samp> on empty
3653 vectors and empty strings.
3654 </p>
3655
3656 <table><tr><td>&nbsp;</td><td><pre class="format">(eq? 'a 'a) ==&gt; #t
3657 (eq? '(a) '(a)) ==&gt; <em>unspecified</em>
3658 (eq? (list 'a) (list 'a)) ==&gt; #f
3659 (eq? &quot;a&quot; &quot;a&quot;) ==&gt; <em>unspecified</em>
3660 (eq? &quot;&quot; &quot;&quot;) ==&gt; <em>unspecified</em>
3661 (eq? '() '()) ==&gt; #t
3662 (eq? 2 2) ==&gt; <em>unspecified</em>
3663 (eq? #\A #\A) ==&gt; <em>unspecified</em>
3664 (eq? car car) ==&gt; #t
3665 (let ((n (+ 2 3)))
3666 (eq? n n)) ==&gt; <em>unspecified</em>
3667 (let ((x '(a)))
3668 (eq? x x)) ==&gt; #t
3669 (let ((x '#()))
3670 (eq? x x)) ==&gt; #t
3671 (let ((p (lambda (x) x)))
3672 (eq? p p)) ==&gt; #t
3673 </pre></td></tr></table>
3674
3675
3676
3677
3678
3679 <blockquote><p><em>Rationale:</em> It will usually be possible to implement <samp>eq?</samp> much
3680 more efficiently than <samp>eqv?</samp>, for example, as a simple pointer
3681 comparison instead of as some more complicated operation. One reason is
3682 that it may not be possible to compute <samp>eqv?</samp> of two numbers in
3683 constant time, whereas <samp>eq?</samp> implemented as pointer comparison will
3684 always finish in constant time. <samp>Eq?</samp> may be used like <samp>eqv?</samp>
3685 in applications using procedures to implement objects with state since
3686 it obeys the same constraints as <samp>eqv?</samp>.
3687 </p></blockquote>
3688
3689
3690
3691
3692
3693
3694 <a name="Definition_of_equal?"></a><a name="Library_procedure_equal?"></a><a name="index-equal_003f"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Library_procedure_equal?">equal?</a></b></code><i> obj1 obj2</i><code>)</code></td><td align="right">library procedure</td></tr></table>
3695
3696 <p><samp>Equal?</samp> recursively compares the contents of pairs, vectors, and
3697 strings, applying <samp>eqv?</samp> on other objects such as numbers and symbols.
3698 A rule of thumb is that objects are generally <samp>equal?</samp> if they print
3699 the same. <samp>Equal?</samp> may fail to terminate if its arguments are
3700 circular data structures.
3701 </p>
3702
3703 <table><tr><td>&nbsp;</td><td><pre class="format">(equal? 'a 'a) ==&gt; #t
3704 (equal? '(a) '(a)) ==&gt; #t
3705 (equal? '(a (b) c)
3706 '(a (b) c)) ==&gt; #t
3707 (equal? &quot;abc&quot; &quot;abc&quot;) ==&gt; #t
3708 (equal? 2 2) ==&gt; #t
3709 (equal? (make-vector 5 'a)
3710 (make-vector 5 'a)) ==&gt; #t
3711 (equal? (lambda (x) x)
3712 (lambda (y) y)) ==&gt; <em>unspecified</em>
3713 </pre></td></tr></table>
3714
3715
3716
3717
3718
3719 <a name="Numbers"></a><hr size="1"><br/><br/><br/>
3720 <table cellpadding="1" cellspacing="1" border="0">
3721 <tr><td valign="middle" align="left"><a href="#Equivalence-predicates" title="Previous section in reading order"><img src="button-left.png" border="0" alt="Back: 6.1 Equivalence predicates" align="middle" width="32"></a></td>
3722 <td valign="middle" align="left"><a href="#Numerical-types" title="Next section in reading order"><img src="button-right.png" border="0" alt="Forward: 6.2.1 Numerical types" align="middle" width="32"></a></td>
3723 <td valign="middle" align="left"> &nbsp; </td>
3724 <td valign="middle" align="left"><a href="#Standard-procedures" title="Beginning of this chapter or previous chapter"><img src="button-left-left.png" border="0" alt="FastBack: 6. Standard procedures" align="middle" width="32"></a></td>
3725 <td valign="middle" align="left"><a href="#Standard-procedures" title="Up section"><img src="button-up.png" border="0" alt="Up: 6. Standard procedures" align="middle" width="32"></a></td>
3726 <td valign="middle" align="left"><a href="#Formal-syntax-and-semantics" title="Next chapter"><img src="button-right-right.png" border="0" alt="FastForward: 7. Formal syntax and semantics" align="middle" width="32"></a></td>
3727 <td valign="middle" align="left"><a href="#Top" title="Cover (top) of document"><img src="button-up-arrow.png" border="0" alt="Top: Revised(5) Report on the Algorithmic Language Scheme" align="middle" width="32"></a></td>
3728 <td valign="middle" align="left"><a href="#SEC_Contents" title="Table of contents"><img src="button-compass.png" border="0" alt="Contents: Table of Contents" align="middle" width="32"></a></td>
3729 <td valign="middle" align="left"><a href="#Index" title="Index"><img src="button-abc.png" border="0" alt="Index: Alphabetic index of definitions of concepts, keywords, and procedures" align="middle" width="32"></a></td>
3730 </tr></table>
3731 <a name="Numbers-1"></a>
3732 <h2 class="section">6.2 Numbers</h2>
3733
3734 <table class="menu" border="0" cellspacing="0">
3735 <tr><td align="left" valign="top"><a href="#Numerical-types">6.2.1 Numerical types</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
3736 </td></tr>
3737 <tr><td align="left" valign="top"><a href="#Exactness">6.2.2 Exactness</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
3738 </td></tr>
3739 <tr><td align="left" valign="top"><a href="#Implementation-restrictions">6.2.3 Implementation restrictions</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
3740 </td></tr>
3741 <tr><td align="left" valign="top"><a href="#Syntax-of-numerical-constants">6.2.4 Syntax of numerical constants</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
3742 </td></tr>
3743 <tr><td align="left" valign="top"><a href="#Numerical-operations">6.2.5 Numerical operations</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
3744 </td></tr>
3745 <tr><td align="left" valign="top"><a href="#Numerical-input-and-output">6.2.6 Numerical input and output</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
3746 </td></tr>
3747 </table>
3748
3749
3750
3751 <a name="index-number"></a>
3752
3753
3754
3755 <p>Numerical computation has traditionally been neglected by the Lisp
3756 community. Until Common Lisp there was no carefully thought out
3757 strategy for organizing numerical computation, and with the exception of
3758 the MacLisp system [Pitman83] little effort was made to
3759 execute numerical code efficiently. This report recognizes the excellent work
3760 of the Common Lisp committee and accepts many of their recommendations.
3761 In some ways this report simplifies and generalizes their proposals in a manner
3762 consistent with the purposes of Scheme.
3763 </p>
3764 <p>It is important to distinguish between the mathematical numbers, the
3765 Scheme numbers that attempt to model them, the machine representations
3766 used to implement the Scheme numbers, and notations used to write numbers.
3767 This report uses the types <i>number</i>, <i>complex</i>, <i>real</i>,
3768 <i>rational</i>, and <i>integer</i> to refer to both mathematical numbers
3769 and Scheme numbers. Machine representations such as fixed point and
3770 floating point are referred to by names such as <i>fixnum</i> and
3771 <i>flonum</i>.
3772 </p>
3773
3774 <a name="Numerical-types"></a><hr size="1"><br/><br/><br/>
3775 <table cellpadding="1" cellspacing="1" border="0">
3776 <tr><td valign="middle" align="left"><a href="#Numbers" title="Previous section in reading order"><img src="button-left.png" border="0" alt="Back: 6.2 Numbers" align="middle" width="32"></a></td>
3777 <td valign="middle" align="left"><a href="#Exactness" title="Next section in reading order"><img src="button-right.png" border="0" alt="Forward: 6.2.2 Exactness" align="middle" width="32"></a></td>
3778 <td valign="middle" align="left"> &nbsp; </td>
3779 <td valign="middle" align="left"><a href="#Standard-procedures" title="Beginning of this chapter or previous chapter"><img src="button-left-left.png" border="0" alt="FastBack: 6. Standard procedures" align="middle" width="32"></a></td>
3780 <td valign="middle" align="left"><a href="#Numbers" title="Up section"><img src="button-up.png" border="0" alt="Up: 6.2 Numbers" align="middle" width="32"></a></td>
3781 <td valign="middle" align="left"><a href="#Formal-syntax-and-semantics" title="Next chapter"><img src="button-right-right.png" border="0" alt="FastForward: 7. Formal syntax and semantics" align="middle" width="32"></a></td>
3782 <td valign="middle" align="left"><a href="#Top" title="Cover (top) of document"><img src="button-up-arrow.png" border="0" alt="Top: Revised(5) Report on the Algorithmic Language Scheme" align="middle" width="32"></a></td>
3783 <td valign="middle" align="left"><a href="#SEC_Contents" title="Table of contents"><img src="button-compass.png" border="0" alt="Contents: Table of Contents" align="middle" width="32"></a></td>
3784 <td valign="middle" align="left"><a href="#Index" title="Index"><img src="button-abc.png" border="0" alt="Index: Alphabetic index of definitions of concepts, keywords, and procedures" align="middle" width="32"></a></td>
3785 </tr></table>
3786 <a name="Numerical-types-1"></a>
3787 <h3 class="subsection">6.2.1 Numerical types</h3>
3788
3789
3790
3791 <a name="index-numerical-types"></a>
3792
3793
3794
3795 <p>Mathematically, numbers may be arranged into a tower of subtypes
3796 in which each level is a subset of the level above it:
3797 </p>
3798 <table><tr><td>&nbsp;</td><td><pre class="format"> <span class="roman">number</span>
3799 <span class="roman">complex</span>
3800 <span class="roman">real</span>
3801 <span class="roman">rational</span>
3802 <span class="roman">integer</span>
3803 </pre></td></tr></table>
3804
3805
3806 <p>For example, 3 is an integer. Therefore 3 is also a rational,
3807 a real, and a complex. The same is true of the Scheme numbers
3808 that model 3. For Scheme numbers, these types are defined by the
3809 predicates <code>number?</code>, <code>complex?</code>, <code>real?</code>, <code>rational?</code>,
3810 <a name="index-rational_003f"></a>
3811 <a name="index-real_003f"></a>
3812 <a name="index-complex_003f"></a>
3813 <a name="index-number_003f-1"></a>
3814 and <code>integer?</code>.
3815 <a name="index-integer_003f"></a>
3816 </p>
3817 <p>There is no simple relationship between a number's type and its
3818 representation inside a computer. Although most implementations of
3819 Scheme will offer at least two different representations of 3, these
3820 different representations denote the same integer.
3821 </p>
3822
3823 <p>Scheme's numerical operations treat numbers as abstract data, as
3824 independent of their representation as possible. Although an implementation
3825 of Scheme may use fixnum, flonum, and perhaps other representations for
3826 numbers, this should not be apparent to a casual programmer writing
3827 simple programs.
3828 </p>
3829 <p>It is necessary, however, to distinguish between numbers that are
3830 represented exactly and those that may not be. For example, indexes
3831 into data structures must be known exactly, as must some polynomial
3832 coefficients in a symbolic algebra system. On the other hand, the
3833 results of measurements are inherently inexact, and irrational numbers
3834 may be approximated by rational and therefore inexact approximations.
3835 In order to catch uses of inexact numbers where exact numbers are
3836 required, Scheme explicitly distinguishes exact from inexact numbers.
3837 This distinction is orthogonal to the dimension of type.
3838 </p>
3839 <a name="Exactness"></a><hr size="1"><br/><br/><br/>
3840 <table cellpadding="1" cellspacing="1" border="0">
3841 <tr><td valign="middle" align="left"><a href="#Numerical-types" title="Previous section in reading order"><img src="button-left.png" border="0" alt="Back: 6.2.1 Numerical types" align="middle" width="32"></a></td>
3842 <td valign="middle" align="left"><a href="#Implementation-restrictions" title="Next section in reading order"><img src="button-right.png" border="0" alt="Forward: 6.2.3 Implementation restrictions" align="middle" width="32"></a></td>
3843 <td valign="middle" align="left"> &nbsp; </td>
3844 <td valign="middle" align="left"><a href="#Standard-procedures" title="Beginning of this chapter or previous chapter"><img src="button-left-left.png" border="0" alt="FastBack: 6. Standard procedures" align="middle" width="32"></a></td>
3845 <td valign="middle" align="left"><a href="#Numbers" title="Up section"><img src="button-up.png" border="0" alt="Up: 6.2 Numbers" align="middle" width="32"></a></td>
3846 <td valign="middle" align="left"><a href="#Formal-syntax-and-semantics" title="Next chapter"><img src="button-right-right.png" border="0" alt="FastForward: 7. Formal syntax and semantics" align="middle" width="32"></a></td>
3847 <td valign="middle" align="left"><a href="#Top" title="Cover (top) of document"><img src="button-up-arrow.png" border="0" alt="Top: Revised(5) Report on the Algorithmic Language Scheme" align="middle" width="32"></a></td>
3848 <td valign="middle" align="left"><a href="#SEC_Contents" title="Table of contents"><img src="button-compass.png" border="0" alt="Contents: Table of Contents" align="middle" width="32"></a></td>
3849 <td valign="middle" align="left"><a href="#Index" title="Index"><img src="button-abc.png" border="0" alt="Index: Alphabetic index of definitions of concepts, keywords, and procedures" align="middle" width="32"></a></td>
3850 </tr></table>
3851 <a name="Exactness-1"></a>
3852 <h3 class="subsection">6.2.2 Exactness</h3>
3853
3854
3855
3856
3857 <a name="index-exactness"></a>
3858 <p>Scheme numbers are either <i>exact</i> or <i>inexact</i>. A number is
3859 <span class="roman">exact</span> if it was written as an exact constant or was derived from
3860 <span class="roman">exact</span> numbers using only <span class="roman">exact</span> operations. A number is
3861 <span class="roman">inexact</span> if it was written as an inexact constant,
3862 if it was
3863 derived using <span class="roman">inexact</span> ingredients, or if it was derived using
3864 <span class="roman">inexact</span> operations. Thus <span class="roman">inexact</span>ness is a contagious
3865 property of a number.
3866 </p>
3867 <p>If two implementations produce <span class="roman">exact</span> results for a
3868 computation that did not involve <span class="roman">inexact</span> intermediate results,
3869 the two ultimate results will be mathematically equivalent. This is
3870 generally not true of computations involving <span class="roman">inexact</span> numbers
3871 since approximate methods such as floating point arithmetic may be used,
3872 but it is the duty of each implementation to make the result as close as
3873 practical to the mathematically ideal result.
3874 </p>
3875 <p>Rational operations such as <samp>+</samp> should always produce
3876 <span class="roman">exact</span> results when given <span class="roman">exact</span> arguments.
3877 If the operation is unable to produce an <span class="roman">exact</span> result,
3878 then it may either report the violation of an implementation restriction
3879 or it may silently coerce its
3880 result to an <span class="roman">inexact</span> value.
3881 See section <a href="#Implementation-restrictions">Implementation restrictions</a>.
3882 </p>
3883 <p>With the exception of <code>inexact-&gt;exact</code>, the operations described in
3884 <a name="index-inexact_002d_003eexact"></a>
3885 this section must generally return inexact results when given any inexact
3886 arguments. An operation may, however, return an <span class="roman">exact</span> result if it can
3887 prove that the value of the result is unaffected by the inexactness of its
3888 arguments. For example, multiplication of any number by an <span class="roman">exact</span> zero
3889 may produce an <span class="roman">exact</span> zero result, even if the other argument is
3890 <span class="roman">inexact</span>.
3891 </p>
3892 <a name="Implementation-restrictions"></a><hr size="1"><br/><br/><br/>
3893 <table cellpadding="1" cellspacing="1" border="0">
3894 <tr><td valign="middle" align="left"><a href="#Exactness" title="Previous section in reading order"><img src="button-left.png" border="0" alt="Back: 6.2.2 Exactness" align="middle" width="32"></a></td>
3895 <td valign="middle" align="left"><a href="#Syntax-of-numerical-constants" title="Next section in reading order"><img src="button-right.png" border="0" alt="Forward: 6.2.4 Syntax of numerical constants" align="middle" width="32"></a></td>
3896 <td valign="middle" align="left"> &nbsp; </td>
3897 <td valign="middle" align="left"><a href="#Standard-procedures" title="Beginning of this chapter or previous chapter"><img src="button-left-left.png" border="0" alt="FastBack: 6. Standard procedures" align="middle" width="32"></a></td>
3898 <td valign="middle" align="left"><a href="#Numbers" title="Up section"><img src="button-up.png" border="0" alt="Up: 6.2 Numbers" align="middle" width="32"></a></td>
3899 <td valign="middle" align="left"><a href="#Formal-syntax-and-semantics" title="Next chapter"><img src="button-right-right.png" border="0" alt="FastForward: 7. Formal syntax and semantics" align="middle" width="32"></a></td>
3900 <td valign="middle" align="left"><a href="#Top" title="Cover (top) of document"><img src="button-up-arrow.png" border="0" alt="Top: Revised(5) Report on the Algorithmic Language Scheme" align="middle" width="32"></a></td>
3901 <td valign="middle" align="left"><a href="#SEC_Contents" title="Table of contents"><img src="button-compass.png" border="0" alt="Contents: Table of Contents" align="middle" width="32"></a></td>
3902 <td valign="middle" align="left"><a href="#Index" title="Index"><img src="button-abc.png" border="0" alt="Index: Alphabetic index of definitions of concepts, keywords, and procedures" align="middle" width="32"></a></td>
3903 </tr></table>
3904 <a name="Implementation-restrictions-1"></a>
3905 <h3 class="subsection">6.2.3 Implementation restrictions</h3>
3906
3907
3908
3909 <a name="index-implementation-restriction-1"></a>
3910
3911 <p>Implementations of Scheme are not required to implement the whole
3912 tower of subtypes given in section <a href="#Numerical-types">Numerical types</a>,
3913 but they must implement a coherent subset consistent with both the
3914 purposes of the implementation and the spirit of the Scheme language.
3915 For example, an implementation in which all numbers are <span class="roman">real</span>
3916 may still be quite useful.
3917 </p>
3918 <p>Implementations may also support only a limited range of numbers of
3919 any type, subject to the requirements of this section. The supported
3920 range for <span class="roman">exact</span> numbers of any type may be different from the
3921 supported range for <span class="roman">inexact</span> numbers of that type. For example,
3922 an implementation that uses flonums to represent all its
3923 <span class="roman">inexact</span> <span class="roman">real</span> numbers may
3924 support a practically unbounded range of <span class="roman">exact</span> <span class="roman">integer</span>s
3925 and <span class="roman">rational</span>s
3926 while limiting the range of <span class="roman">inexact</span> <span class="roman">real</span>s (and therefore
3927 the range of <span class="roman">inexact</span> <span class="roman">integer</span>s and <span class="roman">rational</span>s)
3928 to the dynamic range of the flonum format.
3929 Furthermore
3930 the gaps between the representable <span class="roman">inexact</span> <span class="roman">integer</span>s and
3931 <span class="roman">rational</span>s are
3932 likely to be very large in such an implementation as the limits of this
3933 range are approached.
3934 </p>
3935 <p>An implementation of Scheme must support exact integers
3936 throughout the range of numbers that may be used for indexes of
3937 lists, vectors, and strings or that may result from computing the length of a
3938 list, vector, or string. The <code>length</code>, <code>vector-length</code>,
3939 <a name="index-vector_002dlength"></a>
3940 <a name="index-length"></a>
3941 and <code>string-length</code> procedures must return an exact
3942 <a name="index-string_002dlength"></a>
3943 integer, and it is an error to use anything but an exact integer as an
3944 index. Furthermore any integer constant within the index range, if
3945 expressed by an exact integer syntax, will indeed be read as an exact
3946 integer, regardless of any implementation restrictions that may apply
3947 outside this range. Finally, the procedures listed below will always
3948 return an exact integer result provided all their arguments are exact integers
3949 and the mathematically expected result is representable as an exact integer
3950 within the implementation:
3951 </p>
3952
3953 <table><tr><td>&nbsp;</td><td><pre class="example">
3954 + - *
3955 quotient remainder modulo
3956 max min abs
3957 numerator denominator gcd
3958 lcm floor ceiling
3959 truncate round rationalize
3960 expt
3961 </pre></td></tr></table>
3962
3963
3964 <p>Implementations are encouraged, but not required, to support
3965 <span class="roman">exact</span> <span class="roman">integer</span>s and <span class="roman">exact</span> <span class="roman">rational</span>s of
3966 practically unlimited size and precision, and to implement the
3967 above procedures and the <samp>/</samp> procedure in
3968 such a way that they always return <span class="roman">exact</span> results when given <span class="roman">exact</span>
3969 arguments. If one of these procedures is unable to deliver an <span class="roman">exact</span>
3970 result when given <span class="roman">exact</span> arguments, then it may either report a
3971 violation of an
3972 implementation restriction or it may silently coerce its result to an
3973 <span class="roman">inexact</span> number. Such a coercion may cause an error later.
3974 </p>
3975
3976
3977 <p>An implementation may use floating point and other approximate
3978 representation strategies for <span class="roman">inexact</span> numbers.
3979 </p>
3980
3981 <p>This report recommends, but does not require, that the IEEE 32-bit
3982 and 64-bit floating point standards be followed by implementations that use
3983 flonum representations, and that implementations using
3984 other representations should match or exceed the precision achievable
3985 using these floating point standards [IEEE].
3986 </p>
3987 <p>In particular, implementations that use flonum representations
3988 must follow these rules: A <span class="roman">flonum</span> result
3989 must be represented with at least as much precision as is used to express any of
3990 the inexact arguments to that operation. It is desirable (but not required) for
3991 potentially inexact operations such as <samp>sqrt</samp>, when applied to <span class="roman">exact</span>
3992 arguments, to produce <span class="roman">exact</span> answers whenever possible (for example the
3993 square root of an <span class="roman">exact</span> 4 ought to be an <span class="roman">exact</span> 2).
3994 If, however, an
3995 <span class="roman">exact</span> number is operated upon so as to produce an <span class="roman">inexact</span> result
3996 (as by <samp>sqrt</samp>), and if the result is represented as a <span class="roman">flonum</span>, then
3997 the most precise <span class="roman">flonum</span> format available must be used; but if the result
3998 is represented in some other way then the representation must have at least as
3999 much precision as the most precise <span class="roman">flonum</span> format available.
4000 </p>
4001 <p>Although Scheme allows a variety of written
4002 notations for
4003 numbers, any particular implementation may support only some of them.
4004 For example, an implementation in which all numbers are <span class="roman">real</span>
4005 need not support the rectangular and polar notations for complex
4006 numbers. If an implementation encounters an <span class="roman">exact</span> numerical constant that
4007 it cannot represent as an <span class="roman">exact</span> number, then it may either report a
4008 violation of an implementation restriction or it may silently represent the
4009 constant by an <span class="roman">inexact</span> number.
4010 </p>
4011
4012 <a name="Syntax-of-numerical-constants"></a><hr size="1"><br/><br/><br/>
4013 <table cellpadding="1" cellspacing="1" border="0">
4014 <tr><td valign="middle" align="left"><a href="#Implementation-restrictions" title="Previous section in reading order"><img src="button-left.png" border="0" alt="Back: 6.2.3 Implementation restrictions" align="middle" width="32"></a></td>
4015 <td valign="middle" align="left"><a href="#Numerical-operations" title="Next section in reading order"><img src="button-right.png" border="0" alt="Forward: 6.2.5 Numerical operations" align="middle" width="32"></a></td>
4016 <td valign="middle" align="left"> &nbsp; </td>
4017 <td valign="middle" align="left"><a href="#Standard-procedures" title="Beginning of this chapter or previous chapter"><img src="button-left-left.png" border="0" alt="FastBack: 6. Standard procedures" align="middle" width="32"></a></td>
4018 <td valign="middle" align="left"><a href="#Numbers" title="Up section"><img src="button-up.png" border="0" alt="Up: 6.2 Numbers" align="middle" width="32"></a></td>
4019 <td valign="middle" align="left"><a href="#Formal-syntax-and-semantics" title="Next chapter"><img src="button-right-right.png" border="0" alt="FastForward: 7. Formal syntax and semantics" align="middle" width="32"></a></td>
4020 <td valign="middle" align="left"><a href="#Top" title="Cover (top) of document"><img src="button-up-arrow.png" border="0" alt="Top: Revised(5) Report on the Algorithmic Language Scheme" align="middle" width="32"></a></td>
4021 <td valign="middle" align="left"><a href="#SEC_Contents" title="Table of contents"><img src="button-compass.png" border="0" alt="Contents: Table of Contents" align="middle" width="32"></a></td>
4022 <td valign="middle" align="left"><a href="#Index" title="Index"><img src="button-abc.png" border="0" alt="Index: Alphabetic index of definitions of concepts, keywords, and procedures" align="middle" width="32"></a></td>
4023 </tr></table>
4024 <a name="Syntax-of-numerical-constants-1"></a>
4025 <h3 class="subsection">6.2.4 Syntax of numerical constants</h3>
4026
4027
4028
4029
4030
4031
4032 <p>The syntax of the written representations for numbers is described formally in
4033 section <a href="#Lexical-structure">Lexical structure</a>. Note that case is not significant in numerical
4034 constants.
4035 </p>
4036
4037 <p>A number may be written in binary, octal, decimal, or
4038 hexadecimal by the use of a radix prefix. The radix prefixes are <samp>#b</samp> (binary), <samp>#o</samp> (octal), <samp>#d</samp> (decimal), and <samp>#x</samp> (hexadecimal). With
4039 <a name="index-_0023x"></a>
4040 <a name="index-_0023d"></a>
4041 <a name="index-_0023o"></a>
4042 <a name="index-_0023b"></a>
4043 no radix prefix, a number is assumed to be expressed in decimal.
4044 </p>
4045 <p>A
4046 numerical constant may be specified to be either <span class="roman">exact</span> or
4047 <span class="roman">inexact</span> by a prefix. The prefixes are <samp>#e</samp>
4048 <a name="index-_0023e"></a>
4049 for <span class="roman">exact</span>, and <samp>#i</samp> for <span class="roman">inexact</span>. An exactness
4050 <a name="index-_0023i"></a>
4051 prefix may appear before or after any radix prefix that is used. If
4052 the written representation of a number has no exactness prefix, the
4053 constant may be either <span class="roman">inexact</span> or <span class="roman">exact</span>. It is
4054 <span class="roman">inexact</span> if it contains a decimal point, an
4055 exponent, or a &ldquo;#&rdquo; character in the place of a digit,
4056 otherwise it is <span class="roman">exact</span>.
4057 </p>
4058
4059 <p>In systems with <span class="roman">inexact</span> numbers
4060 of varying precisions it may be useful to specify
4061 the precision of a constant. For this purpose, numerical constants
4062 may be written with an exponent marker that indicates the
4063 desired precision of the <span class="roman">inexact</span>
4064 representation. The letters <samp>s</samp>, <samp>f</samp>,
4065 <samp>d</samp>, and <samp>l</samp> specify the use of <var>short</var>, <var>single</var>,
4066 <var>double</var>, and <var>long</var> precision, respectively. (When fewer
4067 than four internal
4068 <span class="roman">inexact</span>
4069 representations exist, the four size
4070 specifications are mapped onto those available. For example, an
4071 implementation with two internal representations may map short and
4072 single together and long and double together.) In addition, the
4073 exponent marker <samp>e</samp> specifies the default precision for the
4074 implementation. The default precision has at least as much precision
4075 as <var>double</var>, but
4076 implementations may wish to allow this default to be set by the user.
4077 </p>
4078
4079 <table><tr><td>&nbsp;</td><td><pre class="example">
4080 3.14159265358979F0
4081 <span class="roman">Round to single ---</span> 3.141593
4082 0.6L0
4083 <span class="roman">Extend to long ---</span> .600000000000000
4084 </pre></td></tr></table>
4085
4086
4087
4088 <a name="Numerical-operations"></a><hr size="1"><br/><br/><br/>
4089 <table cellpadding="1" cellspacing="1" border="0">
4090 <tr><td valign="middle" align="left"><a href="#Syntax-of-numerical-constants" title="Previous section in reading order"><img src="button-left.png" border="0" alt="Back: 6.2.4 Syntax of numerical constants" align="middle" width="32"></a></td>
4091 <td valign="middle" align="left"><a href="#Numerical-input-and-output" title="Next section in reading order"><img src="button-right.png" border="0" alt="Forward: 6.2.6 Numerical input and output" align="middle" width="32"></a></td>
4092 <td valign="middle" align="left"> &nbsp; </td>
4093 <td valign="middle" align="left"><a href="#Standard-procedures" title="Beginning of this chapter or previous chapter"><img src="button-left-left.png" border="0" alt="FastBack: 6. Standard procedures" align="middle" width="32"></a></td>
4094 <td valign="middle" align="left"><a href="#Numbers" title="Up section"><img src="button-up.png" border="0" alt="Up: 6.2 Numbers" align="middle" width="32"></a></td>
4095 <td valign="middle" align="left"><a href="#Formal-syntax-and-semantics" title="Next chapter"><img src="button-right-right.png" border="0" alt="FastForward: 7. Formal syntax and semantics" align="middle" width="32"></a></td>
4096 <td valign="middle" align="left"><a href="#Top" title="Cover (top) of document"><img src="button-up-arrow.png" border="0" alt="Top: Revised(5) Report on the Algorithmic Language Scheme" align="middle" width="32"></a></td>
4097 <td valign="middle" align="left"><a href="#SEC_Contents" title="Table of contents"><img src="button-compass.png" border="0" alt="Contents: Table of Contents" align="middle" width="32"></a></td>
4098 <td valign="middle" align="left"><a href="#Index" title="Index"><img src="button-abc.png" border="0" alt="Index: Alphabetic index of definitions of concepts, keywords, and procedures" align="middle" width="32"></a></td>
4099 </tr></table>
4100 <a name="Numerical-operations-1"></a>
4101 <h3 class="subsection">6.2.5 Numerical operations</h3>
4102
4103
4104 <p>The reader is referred to section <a href="#Entry-format">Entry format</a> for a summary
4105 of the naming conventions used to specify restrictions on the types of
4106 arguments to numerical routines.
4107 </p>
4108 <p>The examples used in this section assume that any numerical constant written
4109 using an <span class="roman">exact</span> notation is indeed represented as an <span class="roman">exact</span>
4110 number. Some examples also assume that certain numerical constants written
4111 using an <span class="roman">inexact</span> notation can be represented without loss of
4112 accuracy; the <span class="roman">inexact</span> constants were chosen so that this is
4113 likely to be true in implementations that use flonums to represent
4114 inexact numbers.
4115 </p>
4116
4117
4118
4119 <a name="Definition_of_number?"></a><a name="Procedure_number?"></a><a name="index-number_003f-2"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Procedure_number?">number?</a></b></code><i> obj</i><code>)</code></td><td align="right">procedure</td></tr></table>
4120 <a name="Definition_of_complex?"></a><a name="Procedure_complex?"></a><a name="index-complex_003f-1"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Procedure_complex?">complex?</a></b></code><i> obj</i><code>)</code></td><td align="right">procedure</td></tr></table>
4121 <a name="Definition_of_real?"></a><a name="Procedure_real?"></a><a name="index-real_003f-1"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Procedure_real?">real?</a></b></code><i> obj</i><code>)</code></td><td align="right">procedure</td></tr></table>
4122 <a name="Definition_of_rational?"></a><a name="Procedure_rational?"></a><a name="index-rational_003f-1"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Procedure_rational?">rational?</a></b></code><i> obj</i><code>)</code></td><td align="right">procedure</td></tr></table>
4123 <a name="Definition_of_integer?"></a><a name="Procedure_integer?"></a><a name="index-integer_003f-1"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Procedure_integer?">integer?</a></b></code><i> obj</i><code>)</code></td><td align="right">procedure</td></tr></table>
4124
4125 <p>These numerical type predicates can be applied to any kind of
4126 argument, including non-numbers. They return <tt>#t</tt> if the object is
4127 of the named type, and otherwise they return <tt>#f</tt>.
4128 In general, if a type predicate is true of a number then all higher
4129 type predicates are also true of that number. Consequently, if a type
4130 predicate is false of a number, then all lower type predicates are
4131 also false of that number.
4132 </p>
4133 <p>If <var>z</var> is an inexact complex number, then <samp>(real? <var>z</var>)</samp> is true if
4134 and only if <samp>(zero? (imag-part <var>z</var>))</samp> is true. If <var>x</var> is an inexact
4135 real number, then <samp>(integer? <var>x</var>)</samp> is true if and only if
4136 <samp>(= <var>x</var> (round <var>x</var>))</samp>.
4137 </p>
4138
4139 <table><tr><td>&nbsp;</td><td><pre class="format">(complex? 3+4i) ==&gt; #t
4140 (complex? 3) ==&gt; #t
4141 (real? 3) ==&gt; #t
4142 (real? -2.5+0.0i) ==&gt; #t
4143 (real? #e1e10) ==&gt; #t
4144 (rational? 6/10) ==&gt; #t
4145 (rational? 6/3) ==&gt; #t
4146 (integer? 3+0i) ==&gt; #t
4147 (integer? 3.0) ==&gt; #t
4148 (integer? 8/4) ==&gt; #t
4149 </pre></td></tr></table>
4150
4151
4152
4153 <blockquote><p><em>Note:</em>
4154 The behavior of these type predicates on <span class="roman">inexact</span> numbers
4155 is unreliable, since any inaccuracy may affect the result.
4156 </p></blockquote>
4157
4158
4159
4160 <blockquote><p><em>Note:</em>
4161 In many implementations the <code>rational?</code> procedure will be the same
4162 <a name="index-rational_003f-2"></a>
4163 as <code>real?</code>, and the <code>complex?</code> procedure will be the same as
4164 <a name="index-complex_003f-2"></a>
4165 <a name="index-real_003f-2"></a>
4166 <code>number?</code>, but unusual implementations may be able to represent
4167 <a name="index-number_003f-3"></a>
4168 some irrational numbers exactly or may extend the number system to
4169 support some kind of non-complex numbers.
4170 </p></blockquote>
4171
4172
4173
4174
4175
4176 <a name="Definition_of_exact?"></a><a name="Procedure_exact?"></a><a name="index-exact_003f"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Procedure_exact?">exact?</a></b></code><i> <var>z</var></i><code>)</code></td><td align="right">procedure</td></tr></table>
4177 <a name="Definition_of_inexact?"></a><a name="Procedure_inexact?"></a><a name="index-inexact_003f"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Procedure_inexact?">inexact?</a></b></code><i> <var>z</var></i><code>)</code></td><td align="right">procedure</td></tr></table>
4178
4179 <p>These numerical predicates provide tests for the exactness of a
4180 quantity. For any Scheme number, precisely one of these predicates
4181 is true.
4182 </p>
4183
4184
4185
4186
4187 <a name="Definition_of_="></a><a name="Procedure_="></a><a name="index-_003d"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Procedure_=">=</a></b></code><i> z1 z2 z3 &hellip;</i><code>)</code></td><td align="right">procedure</td></tr></table>
4188 <a name="Definition_of_%3C"></a><a name="Procedure_%3C"></a><a name="index-_003c"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Procedure_%3C">&lt;</a></b></code><i> x1 x2 x3 &hellip;</i><code>)</code></td><td align="right">procedure</td></tr></table>
4189 <a name="Definition_of_%3E"></a><a name="Procedure_%3E"></a><a name="index-_003e"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Procedure_%3E">&gt;</a></b></code><i> x1 x2 x3 &hellip;</i><code>)</code></td><td align="right">procedure</td></tr></table>
4190 <a name="Definition_of_%3C="></a><a name="Procedure_%3C="></a><a name="index-_003c_003d"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Procedure_%3C=">&lt;=</a></b></code><i> x1 x2 x3 &hellip;</i><code>)</code></td><td align="right">procedure</td></tr></table>
4191 <a name="Definition_of_%3E="></a><a name="Procedure_%3E="></a><a name="index-_003e_003d"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Procedure_%3E=">&gt;=</a></b></code><i> x1 x2 x3 &hellip;</i><code>)</code></td><td align="right">procedure</td></tr></table>
4192
4193 <p>These procedures return <tt>#t</tt> if their arguments are (respectively):
4194 equal, monotonically increasing, monotonically decreasing,
4195 monotonically nondecreasing, or monotonically nonincreasing.
4196 </p>
4197 <p>These predicates are required to be transitive.
4198 </p>
4199
4200 <blockquote><p><em>Note:</em>
4201 The traditional implementations of these predicates in Lisp-like
4202 languages are not transitive.
4203 </p></blockquote>
4204
4205
4206
4207 <blockquote><p><em>Note:</em>
4208 While it is not an error to compare <span class="roman">inexact</span> numbers using these
4209 predicates, the results may be unreliable because a small inaccuracy
4210 may affect the result; this is especially true of <code>=</code> and <code>zero?</code>.
4211 <a name="index-zero_003f"></a>
4212 <a name="index-_003d-1"></a>
4213 When in doubt, consult a numerical analyst.
4214 </p></blockquote>
4215
4216
4217
4218
4219
4220 <a name="Definition_of_zero?"></a><a name="Library_procedure_zero?"></a><a name="index-zero_003f-1"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Library_procedure_zero?">zero?</a></b></code><i> <var>z</var></i><code>)</code></td><td align="right">library procedure</td></tr></table>
4221 <a name="Definition_of_positive?"></a><a name="Library_procedure_positive?"></a><a name="index-positive_003f"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Library_procedure_positive?">positive?</a></b></code><i> <var>x</var></i><code>)</code></td><td align="right">library procedure</td></tr></table>
4222 <a name="Definition_of_negative?"></a><a name="Library_procedure_negative?"></a><a name="index-negative_003f"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Library_procedure_negative?">negative?</a></b></code><i> <var>x</var></i><code>)</code></td><td align="right">library procedure</td></tr></table>
4223 <a name="Definition_of_odd?"></a><a name="Library_procedure_odd?"></a><a name="index-odd_003f"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Library_procedure_odd?">odd?</a></b></code><i> <var>n</var></i><code>)</code></td><td align="right">library procedure</td></tr></table>
4224 <a name="Definition_of_even?"></a><a name="Library_procedure_even?"></a><a name="index-even_003f"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Library_procedure_even?">even?</a></b></code><i> <var>n</var></i><code>)</code></td><td align="right">library procedure</td></tr></table>
4225
4226 <p>These numerical predicates test a number for a particular property,
4227 returning <tt>#t</tt> or <tt>#f</tt>. See note above.
4228 </p>
4229
4230
4231
4232 <a name="Definition_of_max"></a><a name="Library_procedure_max"></a><a name="index-max"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Library_procedure_max">max</a></b></code><i> x1 x2 &hellip;</i><code>)</code></td><td align="right">library procedure</td></tr></table>
4233 <a name="Definition_of_min"></a><a name="Library_procedure_min"></a><a name="index-min"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Library_procedure_min">min</a></b></code><i> x1 x2 &hellip;</i><code>)</code></td><td align="right">library procedure</td></tr></table>
4234
4235 <p>These procedures return the maximum or minimum of their arguments.
4236 </p>
4237
4238 <table><tr><td>&nbsp;</td><td><pre class="format">(max 3 4) ==&gt; 4 ; exact
4239 (max 3.9 4) ==&gt; 4.0 ; inexact
4240 </pre></td></tr></table>
4241
4242
4243
4244 <blockquote><p><em>Note:</em>
4245 If any argument is inexact, then the result will also be inexact (unless
4246 the procedure can prove that the inaccuracy is not large enough to affect the
4247 result, which is possible only in unusual implementations). If <samp>min</samp> or
4248 <samp>max</samp> is used to compare numbers of mixed exactness, and the numerical
4249 value of the result cannot be represented as an inexact number without loss of
4250 accuracy, then the procedure may report a violation of an implementation
4251 restriction.
4252 </p></blockquote>
4253
4254
4255
4256
4257
4258
4259 <a name="Definition_of_%2B"></a><a name="Procedure_%2B"></a><a name="index-_002b-1"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Procedure_%2B">+</a></b></code><i> z1 &hellip;</i><code>)</code></td><td align="right">procedure</td></tr></table>
4260 <a name="Definition_of_%2A"></a><a name="Procedure_%2A"></a><a name="index-_002a"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Procedure_%2A">*</a></b></code><i> z1 &hellip;</i><code>)</code></td><td align="right">procedure</td></tr></table>
4261
4262 <p>These procedures return the sum or product of their arguments.
4263 </p>
4264
4265 <table><tr><td>&nbsp;</td><td><pre class="format">(+ 3 4) ==&gt; 7
4266 (+ 3) ==&gt; 3
4267 (+) ==&gt; 0
4268 (* 4) ==&gt; 4
4269 (*) ==&gt; 1
4270 </pre></td></tr></table>
4271
4272
4273
4274
4275
4276
4277 <a name="Definition_of_-"></a><a name="Procedure_-"></a><a name="index-_002d-1"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Procedure_-">-</a></b></code><i> z1 z2</i><code>)</code></td><td align="right">procedure</td></tr></table>
4278 <a name="Definition_of_-"></a><a name="Procedure_-"></a><a name="index-_002d-2"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Procedure_-">-</a></b></code><i> <var>z</var></i><code>)</code></td><td align="right">procedure</td></tr></table>
4279 <a name="Definition_of_-"></a><a name="Optional_procedure_-"></a><a name="index-_002d-3"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Optional_procedure_-">-</a></b></code><i> z1 z2 &hellip;</i><code>)</code></td><td align="right">optional procedure</td></tr></table>
4280 <a name="Definition_of_/"></a><a name="Procedure_/"></a><a name="index-_002f"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Procedure_/">/</a></b></code><i> z1 z2</i><code>)</code></td><td align="right">procedure</td></tr></table>
4281 <a name="Definition_of_/"></a><a name="Procedure_/"></a><a name="index-_002f-1"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Procedure_/">/</a></b></code><i> <var>z</var></i><code>)</code></td><td align="right">procedure</td></tr></table>
4282 <a name="Definition_of_/"></a><a name="Optional_procedure_/"></a><a name="index-_002f-2"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Optional_procedure_/">/</a></b></code><i> z1 z2 &hellip;</i><code>)</code></td><td align="right">optional procedure</td></tr></table>
4283
4284 <p>With two or more arguments, these procedures return the difference or
4285 quotient of their arguments, associating to the left. With one argument,
4286 however, they return the additive or multiplicative inverse of their argument.
4287 </p>
4288
4289 <table><tr><td>&nbsp;</td><td><pre class="format">(- 3 4) ==&gt; -1
4290 (- 3 4 5) ==&gt; -6
4291 (- 3) ==&gt; -3
4292 (/ 3 4 5) ==&gt; 3/20
4293 (/ 3) ==&gt; 1/3
4294 </pre></td></tr></table>
4295
4296
4297
4298
4299
4300
4301 <a name="Definition_of_abs"></a><a name="Library_procedure_abs"></a><a name="index-abs"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Library_procedure_abs">abs</a></b></code><i> x</i><code>)</code></td><td align="right">library procedure</td></tr></table>
4302
4303 <p><samp>Abs</samp> returns the absolute value of its argument.
4304 </p>
4305 <table><tr><td>&nbsp;</td><td><pre class="format">(abs -7) ==&gt; 7
4306 </pre></td></tr></table>
4307
4308
4309
4310
4311
4312 <a name="Definition_of_quotient"></a><a name="Procedure_quotient"></a><a name="index-quotient"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Procedure_quotient">quotient</a></b></code><i> n1 n2</i><code>)</code></td><td align="right">procedure</td></tr></table>
4313 <a name="Definition_of_remainder"></a><a name="Procedure_remainder"></a><a name="index-remainder"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Procedure_remainder">remainder</a></b></code><i> n1 n2</i><code>)</code></td><td align="right">procedure</td></tr></table>
4314 <a name="Definition_of_modulo"></a><a name="Procedure_modulo"></a><a name="index-modulo"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Procedure_modulo">modulo</a></b></code><i> n1 n2</i><code>)</code></td><td align="right">procedure</td></tr></table>
4315
4316 <p>These procedures implement number-theoretic (integer)
4317 division. <var>n2</var> should be non-zero. All three procedures
4318 return integers. If <var>n1</var>/<var>n2</var> is an integer:
4319 </p>
4320 <table><tr><td>&nbsp;</td><td><pre class="format"> (quotient <var>n1</var> <var>n2</var>) ==&gt; <var>n1</var>/<var>n2</var>
4321 (remainder <var>n1</var> <var>n2</var>) ==&gt; 0
4322 (modulo <var>n1</var> <var>n2</var>) ==&gt; 0
4323 </pre></td></tr></table>
4324
4325 <p>If <var>n1</var>/<var>n2</var> is not an integer:
4326 </p>
4327 <table><tr><td>&nbsp;</td><td><pre class="format"> (quotient <var>n1</var> <var>n2</var>) ==&gt; <var>n_q</var>
4328 (remainder <var>n1</var> <var>n2</var>) ==&gt; <var>n_r</var>
4329 (modulo <var>n1</var> <var>n2</var>) ==&gt; <var>n_m</var>
4330 </pre></td></tr></table>
4331
4332 <p>where <var>n_q</var> is <var>n1</var>/<var>n2</var> rounded towards zero,
4333 0 &lt; |<var>n_r</var>| &lt; |<var>n2</var>|, 0 &lt; |<var>n_m</var>| &lt; |<var>n2</var>|,
4334 <var>n_r</var> and <var>n_m</var> differ from <var>n1</var> by a multiple of <var>n2</var>,
4335 <var>n_r</var> has the same sign as <var>n1</var>, and
4336 <var>n_m</var> has the same sign as <var>n2</var>.
4337 </p>
4338 <p>From this we can conclude that for integers <var>n1</var> and <var>n2</var> with
4339 <var>n2</var> not equal to 0,
4340 </p>
4341 <table><tr><td>&nbsp;</td><td><pre class="format"> (= <var>n1</var> (+ (* <var>n2</var> (quotient <var>n1</var> <var>n2</var>))
4342 (remainder <var>n1</var> <var>n2</var>)))
4343 ==&gt; #t
4344 </pre></td></tr></table>
4345
4346 <p>provided all numbers involved in that computation are exact.
4347 </p>
4348
4349 <table><tr><td>&nbsp;</td><td><pre class="format">(modulo 13 4) ==&gt; 1
4350 (remainder 13 4) ==&gt; 1
4351
4352 (modulo -13 4) ==&gt; 3
4353 (remainder -13 4) ==&gt; -1
4354
4355 (modulo 13 -4) ==&gt; -3
4356 (remainder 13 -4) ==&gt; 1
4357
4358 (modulo -13 -4) ==&gt; -1
4359 (remainder -13 -4) ==&gt; -1
4360
4361 (remainder -13 -4.0) ==&gt; -1.0 ; inexact
4362 </pre></td></tr></table>
4363
4364
4365
4366
4367 <a name="Definition_of_gcd"></a><a name="Library_procedure_gcd"></a><a name="index-gcd"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Library_procedure_gcd">gcd</a></b></code><i> n1 &hellip;</i><code>)</code></td><td align="right">library procedure</td></tr></table>
4368 <a name="Definition_of_lcm"></a><a name="Library_procedure_lcm"></a><a name="index-lcm"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Library_procedure_lcm">lcm</a></b></code><i> n1 &hellip;</i><code>)</code></td><td align="right">library procedure</td></tr></table>
4369
4370 <p>These procedures return the greatest common divisor or least common
4371 multiple of their arguments. The result is always non-negative.
4372 </p>
4373
4374 <table><tr><td>&nbsp;</td><td><pre class="format">(gcd 32 -36) ==&gt; 4
4375 (gcd) ==&gt; 0
4376 (lcm 32 -36) ==&gt; 288
4377 (lcm 32.0 -36) ==&gt; 288.0 ; inexact
4378 (lcm) ==&gt; 1
4379 </pre></td></tr></table>
4380
4381
4382
4383
4384
4385
4386 <a name="Definition_of_numerator"></a><a name="Procedure_numerator"></a><a name="index-numerator"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Procedure_numerator">numerator</a></b></code><i> <var>q</var></i><code>)</code></td><td align="right">procedure</td></tr></table>
4387 <a name="Definition_of_denominator"></a><a name="Procedure_denominator"></a><a name="index-denominator"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Procedure_denominator">denominator</a></b></code><i> <var>q</var></i><code>)</code></td><td align="right">procedure</td></tr></table>
4388
4389 <p>These procedures return the numerator or denominator of their
4390 argument; the result is computed as if the argument was represented as
4391 a fraction in lowest terms. The denominator is always positive. The
4392 denominator of 0 is defined to be 1.
4393 </p>
4394
4395
4396 <table><tr><td>&nbsp;</td><td><pre class="format">(numerator (/ 6 4)) ==&gt; 3
4397 (denominator (/ 6 4)) ==&gt; 2
4398 (denominator
4399 (exact-&gt;inexact (/ 6 4))) ==&gt; 2.0
4400 </pre></td></tr></table>
4401
4402
4403
4404
4405
4406
4407 <a name="Definition_of_floor"></a><a name="Procedure_floor"></a><a name="index-floor"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Procedure_floor">floor</a></b></code><i> x</i><code>)</code></td><td align="right">procedure</td></tr></table>
4408 <a name="Definition_of_ceiling"></a><a name="Procedure_ceiling"></a><a name="index-ceiling"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Procedure_ceiling">ceiling</a></b></code><i> x</i><code>)</code></td><td align="right">procedure</td></tr></table>
4409 <a name="Definition_of_truncate"></a><a name="Procedure_truncate"></a><a name="index-truncate"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Procedure_truncate">truncate</a></b></code><i> x</i><code>)</code></td><td align="right">procedure</td></tr></table>
4410 <a name="Definition_of_round"></a><a name="Procedure_round"></a><a name="index-round"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Procedure_round">round</a></b></code><i> x</i><code>)</code></td><td align="right">procedure</td></tr></table>
4411
4412
4413 <p>These procedures return integers.
4414 <samp>Floor</samp> returns the largest integer not larger than <var>x</var>.
4415 <samp>Ceiling</samp> returns the smallest integer not smaller than <var>x</var>.
4416 <samp>Truncate</samp> returns the integer closest to <var>x</var> whose absolute
4417 value is not larger than the absolute value of <var>x</var>. <samp>Round</samp> returns the
4418 closest integer to <var>x</var>, rounding to even when <var>x</var> is halfway between two
4419 integers.
4420 </p>
4421
4422 <blockquote><p><em>Rationale:</em>
4423 <samp>Round</samp> rounds to even for consistency with the default rounding
4424 mode specified by the IEEE floating point standard.
4425 </p></blockquote>
4426
4427
4428
4429 <blockquote><p><em>Note:</em>
4430 If the argument to one of these procedures is inexact, then the result
4431 will also be inexact. If an exact value is needed, the
4432 result should be passed to the <samp>inexact-&gt;exact</samp> procedure.
4433 </p></blockquote>
4434
4435
4436
4437 <table><tr><td>&nbsp;</td><td><pre class="format">(floor -4.3) ==&gt; -5.0
4438 (ceiling -4.3) ==&gt; -4.0
4439 (truncate -4.3) ==&gt; -4.0
4440 (round -4.3) ==&gt; -4.0
4441
4442 (floor 3.5) ==&gt; 3.0
4443 (ceiling 3.5) ==&gt; 4.0
4444 (truncate 3.5) ==&gt; 3.0
4445 (round 3.5) ==&gt; 4.0 ; inexact
4446
4447 (round 7/2) ==&gt; 4 ; exact
4448 (round 7) ==&gt; 7
4449 </pre></td></tr></table>
4450
4451
4452
4453
4454
4455 <a name="Definition_of_rationalize"></a><a name="Library_procedure_rationalize"></a><a name="index-rationalize"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Library_procedure_rationalize">rationalize</a></b></code><i> x y</i><code>)</code></td><td align="right">library procedure</td></tr></table>
4456
4457
4458 <p><samp>Rationalize</samp> returns the <em>simplest</em> rational number
4459 differing from <var>x</var> by no more than <var>y</var>. A rational number r_1 is
4460 <em>simpler</em> than another rational number
4461 <a name="index-simplest-rational"></a>
4462 r_2 if r_1 = p_1/q_1 and r_2 = p_2/q_2 (in lowest terms) and |p_1|&lt;= |p_2| and |q_1| &lt;= |q_2|. Thus 3/5 is simpler than 4/7.
4463 Although not all rationals are comparable in this ordering (consider 2/7
4464 and 3/5) any interval contains a rational number that is simpler than
4465 every other rational number in that interval (the simpler 2/5 lies
4466 between 2/7 and 3/5). Note that 0 = 0/1 is the simplest rational of
4467 all.
4468 </p>
4469
4470 <table><tr><td>&nbsp;</td><td><pre class="format">(rationalize
4471 (inexact-&gt;exact .3) 1/10) ==&gt; 1/3 ; exact
4472 (rationalize .3 1/10) ==&gt; #i1/3 ; inexact
4473 </pre></td></tr></table>
4474
4475
4476
4477
4478
4479 <a name="Definition_of_exp"></a><a name="Procedure_exp"></a><a name="index-exp"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Procedure_exp">exp</a></b></code><i> <var>z</var></i><code>)</code></td><td align="right">procedure</td></tr></table>
4480 <a name="Definition_of_log"></a><a name="Procedure_log"></a><a name="index-log"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Procedure_log">log</a></b></code><i> <var>z</var></i><code>)</code></td><td align="right">procedure</td></tr></table>
4481 <a name="Definition_of_sin"></a><a name="Procedure_sin"></a><a name="index-sin"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Procedure_sin">sin</a></b></code><i> <var>z</var></i><code>)</code></td><td align="right">procedure</td></tr></table>
4482 <a name="Definition_of_cos"></a><a name="Procedure_cos"></a><a name="index-cos"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Procedure_cos">cos</a></b></code><i> <var>z</var></i><code>)</code></td><td align="right">procedure</td></tr></table>
4483 <a name="Definition_of_tan"></a><a name="Procedure_tan"></a><a name="index-tan"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Procedure_tan">tan</a></b></code><i> <var>z</var></i><code>)</code></td><td align="right">procedure</td></tr></table>
4484 <a name="Definition_of_asin"></a><a name="Procedure_asin"></a><a name="index-asin"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Procedure_asin">asin</a></b></code><i> <var>z</var></i><code>)</code></td><td align="right">procedure</td></tr></table>
4485 <a name="Definition_of_acos"></a><a name="Procedure_acos"></a><a name="index-acos"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Procedure_acos">acos</a></b></code><i> <var>z</var></i><code>)</code></td><td align="right">procedure</td></tr></table>
4486 <a name="Definition_of_atan"></a><a name="Procedure_atan"></a><a name="index-atan"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Procedure_atan">atan</a></b></code><i> <var>z</var></i><code>)</code></td><td align="right">procedure</td></tr></table>
4487 <a name="Definition_of_atan"></a><a name="Procedure_atan"></a><a name="index-atan-1"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Procedure_atan">atan</a></b></code><i> <var>y</var> <var>x</var></i><code>)</code></td><td align="right">procedure</td></tr></table>
4488
4489 <p>These procedures are part of every implementation that supports
4490 general
4491 real numbers; they compute the usual transcendental functions. <samp>log</samp>
4492 computes the natural logarithm of <var>z</var> (not the base ten logarithm).
4493 <samp>asin</samp>, <samp>acos</samp>, and <samp>atan</samp> compute arcsine (sin^-1),
4494 arccosine (cos^-1), and arctangent (tan^-1), respectively.
4495 The two-argument variant of <samp>atan</samp> computes <tt>(angle
4496 (make-rectangular <var>x</var> <var>y</var>))</tt> (see below), even in implementations
4497 that don't support general complex numbers.
4498 </p>
4499 <p>In general, the mathematical functions log, arcsine, arccosine, and
4500 arctangent are multiply defined.
4501 The value of log z is defined to be the one whose imaginary
4502 part lies in the range from -pi (exclusive) to pi (inclusive).
4503 log 0 is undefined.
4504 With log defined this way, the values of sin^-1 z, cos^-1 z,
4505 and tan^-1 z are according to the following formulae:
4506 </p>
4507
4508 <p align="center"> sin^-1 z = -i log (i z + sqrt(1 - z^2))
4509 </p>
4510
4511
4512 <p align="center"> cos^-1 z = pi / 2 - sin^-1 z
4513 </p>
4514
4515
4516 <p align="center"> tan^-1 z = (log (1 + i z) - log (1 - i z)) / (2 i)
4517 </p>
4518
4519 <p>The above specification follows [CLtL], which in turn
4520 cites [Penfield81]; refer to these sources for more detailed
4521 discussion of branch cuts, boundary conditions, and implementation of
4522 these functions. When it is possible these procedures produce a real
4523 result from a real argument.
4524 </p>
4525
4526
4527
4528
4529
4530
4531
4532 <a name="Definition_of_sqrt"></a><a name="Procedure_sqrt"></a><a name="index-sqrt"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Procedure_sqrt">sqrt</a></b></code><i> <var>z</var></i><code>)</code></td><td align="right">procedure</td></tr></table>
4533
4534 <p>Returns the principal square root of <var>z</var>. The result will have
4535 either positive real part, or zero real part and non-negative imaginary
4536 part.
4537 </p>
4538
4539
4540
4541 <a name="Definition_of_expt"></a><a name="Procedure_expt"></a><a name="index-expt"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Procedure_expt">expt</a></b></code><i> z1 z2</i><code>)</code></td><td align="right">procedure</td></tr></table>
4542
4543 <p>Returns <var>z1</var> raised to the power <var>z2</var>. For z_1 ~= 0
4544 </p>
4545
4546 <p align="center"> z_1^z_2 = e^z_2 log z_1
4547 </p>
4548 <p>0^z is 1 if z = 0 and 0 otherwise.
4549 </p>
4550
4551
4552
4553
4554
4555 <a name="Definition_of_make-rectangular"></a><a name="Procedure_make-rectangular"></a><a name="index-make_002drectangular"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Procedure_make-rectangular">make-rectangular</a></b></code><i> x1 x2</i><code>)</code></td><td align="right">procedure</td></tr></table>
4556 <a name="Definition_of_make-polar"></a><a name="Procedure_make-polar"></a><a name="index-make_002dpolar"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Procedure_make-polar">make-polar</a></b></code><i> x3 x4</i><code>)</code></td><td align="right">procedure</td></tr></table>
4557 <a name="Definition_of_real-part"></a><a name="Procedure_real-part"></a><a name="index-real_002dpart"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Procedure_real-part">real-part</a></b></code><i> <var>z</var></i><code>)</code></td><td align="right">procedure</td></tr></table>
4558 <a name="Definition_of_imag-part"></a><a name="Procedure_imag-part"></a><a name="index-imag_002dpart"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Procedure_imag-part">imag-part</a></b></code><i> <var>z</var></i><code>)</code></td><td align="right">procedure</td></tr></table>
4559 <a name="Definition_of_magnitude"></a><a name="Procedure_magnitude"></a><a name="index-magnitude"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Procedure_magnitude">magnitude</a></b></code><i> <var>z</var></i><code>)</code></td><td align="right">procedure</td></tr></table>
4560 <a name="Definition_of_angle"></a><a name="Procedure_angle"></a><a name="index-angle"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Procedure_angle">angle</a></b></code><i> <var>z</var></i><code>)</code></td><td align="right">procedure</td></tr></table>
4561
4562 <p>These procedures are part of every implementation that supports
4563 general
4564 complex numbers. Suppose <var>x1</var>, <var>x2</var>, <var>x3</var>, and <var>x4</var> are
4565 real numbers and <var>z</var> is a complex number such that
4566 </p>
4567
4568 <p align="center"> <var>z</var> = <var>x1</var> + <var>x2</var>i = <var>x3</var> . e^i <var>x4</var>
4569 </p>
4570 <p>Then
4571 </p>
4572 <table><tr><td>&nbsp;</td><td><pre class="format">(make-rectangular <var>x1</var> <var>x2</var>) ==&gt; <var>z</var>
4573 (make-polar <var>x3</var> <var>x4</var>) ==&gt; <var>z</var>
4574 (real-part <var>z</var>) ==&gt; <var>x1</var>
4575 (imag-part <var>z</var>) ==&gt; <var>x2</var>
4576 (magnitude <var>z</var>) ==&gt; |<var>x3</var>|
4577 (angle <var>z</var>) ==&gt; x_angle
4578 </pre></td></tr></table>
4579
4580 <p>where -pi &lt; x_angle &lt;= pi with x_angle = <var>x4</var> + 2pi n
4581 for some integer n.
4582 </p>
4583
4584 <blockquote><p><em>Rationale:</em>
4585 <samp>Magnitude</samp> is the same as <code>abs</code> for a real argument,
4586 <a name="index-abs-1"></a>
4587 but <samp>abs</samp> must be present in all implementations, whereas
4588 <samp>magnitude</samp> need only be present in implementations that support
4589 general complex numbers.
4590 </p></blockquote>
4591
4592
4593
4594
4595
4596
4597 <a name="Definition_of_exact-%3Einexact"></a><a name="Procedure_exact-%3Einexact"></a><a name="index-exact_002d_003einexact"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Procedure_exact-%3Einexact">exact-&gt;inexact</a></b></code><i> <var>z</var></i><code>)</code></td><td align="right">procedure</td></tr></table>
4598 <a name="Definition_of_inexact-%3Eexact"></a><a name="Procedure_inexact-%3Eexact"></a><a name="index-inexact_002d_003eexact-1"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Procedure_inexact-%3Eexact">inexact-&gt;exact</a></b></code><i> <var>z</var></i><code>)</code></td><td align="right">procedure</td></tr></table>
4599
4600 <p><samp>Exact-&gt;inexact</samp> returns an <span class="roman">inexact</span> representation of <var>z</var>.
4601 The value returned is the
4602 <span class="roman">inexact</span> number that is numerically closest to the argument.
4603 If an <span class="roman">exact</span> argument has no reasonably close <span class="roman">inexact</span> equivalent,
4604 then a violation of an implementation restriction may be reported.
4605 </p>
4606 <p><samp>Inexact-&gt;exact</samp> returns an <span class="roman">exact</span> representation of
4607 <var>z</var>. The value returned is the <span class="roman">exact</span> number that is numerically
4608 closest to the argument.
4609 If an <span class="roman">inexact</span> argument has no reasonably close <span class="roman">exact</span> equivalent,
4610 then a violation of an implementation restriction may be reported.
4611 </p>
4612
4613 <p>These procedures implement the natural one-to-one correspondence between
4614 <span class="roman">exact</span> and <span class="roman">inexact</span> integers throughout an
4615 implementation-dependent range. See section <a href="#Implementation-restrictions">Implementation restrictions</a>.
4616 </p>
4617
4618
4619 <br>
4620 <br>
4621 <br>
4622
4623 <a name="Numerical-input-and-output"></a><hr size="1"><br/><br/><br/>
4624 <table cellpadding="1" cellspacing="1" border="0">
4625 <tr><td valign="middle" align="left"><a href="#Numerical-operations" title="Previous section in reading order"><img src="button-left.png" border="0" alt="Back: 6.2.5 Numerical operations" align="middle" width="32"></a></td>
4626 <td valign="middle" align="left"><a href="#Other-data-types" title="Next section in reading order"><img src="button-right.png" border="0" alt="Forward: 6.3 Other data types" align="middle" width="32"></a></td>
4627 <td valign="middle" align="left"> &nbsp; </td>
4628 <td valign="middle" align="left"><a href="#Standard-procedures" title="Beginning of this chapter or previous chapter"><img src="button-left-left.png" border="0" alt="FastBack: 6. Standard procedures" align="middle" width="32"></a></td>
4629 <td valign="middle" align="left"><a href="#Numbers" title="Up section"><img src="button-up.png" border="0" alt="Up: 6.2 Numbers" align="middle" width="32"></a></td>
4630 <td valign="middle" align="left"><a href="#Formal-syntax-and-semantics" title="Next chapter"><img src="button-right-right.png" border="0" alt="FastForward: 7. Formal syntax and semantics" align="middle" width="32"></a></td>
4631 <td valign="middle" align="left"><a href="#Top" title="Cover (top) of document"><img src="button-up-arrow.png" border="0" alt="Top: Revised(5) Report on the Algorithmic Language Scheme" align="middle" width="32"></a></td>
4632 <td valign="middle" align="left"><a href="#SEC_Contents" title="Table of contents"><img src="button-compass.png" border="0" alt="Contents: Table of Contents" align="middle" width="32"></a></td>
4633 <td valign="middle" align="left"><a href="#Index" title="Index"><img src="button-abc.png" border="0" alt="Index: Alphabetic index of definitions of concepts, keywords, and procedures" align="middle" width="32"></a></td>
4634 </tr></table>
4635 <a name="Numerical-input-and-output-1"></a>
4636 <h3 class="subsection">6.2.6 Numerical input and output</h3>
4637
4638
4639
4640 <a name="Definition_of_number-%3Estring"></a><a name="Procedure_number-%3Estring"></a><a name="index-number_002d_003estring"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Procedure_number-%3Estring">number-&gt;string</a></b></code><i> z</i><code>)</code></td><td align="right">procedure</td></tr></table>
4641 <a name="Definition_of_number-%3Estring"></a><a name="Procedure_number-%3Estring"></a><a name="index-number_002d_003estring-1"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Procedure_number-%3Estring">number-&gt;string</a></b></code><i> z radix</i><code>)</code></td><td align="right">procedure</td></tr></table>
4642
4643 <p><var>Radix</var> must be an exact integer, either 2, 8, 10, or 16. If omitted,
4644 <var>radix</var> defaults to 10.
4645 The procedure <samp>number-&gt;string</samp> takes a
4646 number and a radix and returns as a string an external representation of
4647 the given number in the given radix such that
4648 </p>
4649 <table><tr><td>&nbsp;</td><td><pre class="format">(let ((number <var>number</var>)
4650 (radix <var>radix</var>))
4651 (eqv? number
4652 (string-&gt;number (number-&gt;string number
4653 radix)
4654 radix)))
4655 </pre></td></tr></table>
4656
4657 <p>is true. It is an error if no possible result makes this expression true.
4658 </p>
4659 <p>If <var>z</var> is inexact, the radix is 10, and the above expression
4660 can be satisfied by a result that contains a decimal point,
4661 then the result contains a decimal point and is expressed using the
4662 minimum number of digits (exclusive of exponent and trailing
4663 zeroes) needed to make the above expression
4664 true [howtoprint], [howtoread];
4665 otherwise the format of the result is unspecified.
4666 </p>
4667 <p>The result returned by <samp>number-&gt;string</samp>
4668 never contains an explicit radix prefix.
4669 </p>
4670
4671 <blockquote><p><em>Note:</em>
4672 The error case can occur only when <var>z</var> is not a complex number
4673 or is a complex number with a non-rational real or imaginary part.
4674 </p></blockquote>
4675
4676
4677
4678 <blockquote><p><em>Rationale:</em>
4679 If <var>z</var> is an inexact number represented using flonums, and
4680 the radix is 10, then the above expression is normally satisfied by
4681 a result containing a decimal point. The unspecified case
4682 allows for infinities, NaNs, and non-flonum representations.
4683 </p></blockquote>
4684
4685
4686
4687
4688
4689
4690 <a name="Definition_of_string-%3Enumber"></a><a name="Procedure_string-%3Enumber"></a><a name="index-string_002d_003enumber"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Procedure_string-%3Enumber">string-&gt;number</a></b></code><i> string</i><code>)</code></td><td align="right">procedure</td></tr></table>
4691 <a name="Definition_of_string-%3Enumber"></a><a name="Procedure_string-%3Enumber"></a><a name="index-string_002d_003enumber-1"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Procedure_string-%3Enumber">string-&gt;number</a></b></code><i> string radix</i><code>)</code></td><td align="right">procedure</td></tr></table>
4692
4693
4694 <p>Returns a number of the maximally precise representation expressed by the
4695 given <var>string</var>. <var>Radix</var> must be an exact integer, either 2, 8, 10,
4696 or 16. If supplied, <var>radix</var> is a default radix that may be overridden
4697 by an explicit radix prefix in <var>string</var> (e.g. <tt>&quot;#o177&quot;</tt>). If <var>radix</var>
4698 is not supplied, then the default radix is 10. If <var>string</var> is not
4699 a syntactically valid notation for a number, then <samp>string-&gt;number</samp>
4700 returns <tt>#f</tt>.
4701 </p>
4702
4703 <table><tr><td>&nbsp;</td><td><pre class="format">(string-&gt;number &quot;100&quot;) ==&gt; 100
4704 (string-&gt;number &quot;100&quot; 16) ==&gt; 256
4705 (string-&gt;number &quot;1e2&quot;) ==&gt; 100.0
4706 (string-&gt;number &quot;15##&quot;) ==&gt; 1500.0
4707 </pre></td></tr></table>
4708
4709
4710
4711 <blockquote><p><em>Note:</em>
4712 The domain of <samp>string-&gt;number</samp> may be restricted by implementations
4713 in the following ways. <samp>String-&gt;number</samp> is permitted to return
4714 <tt>#f</tt> whenever <var>string</var> contains an explicit radix prefix.
4715 If all numbers supported by an implementation are real, then
4716 <samp>string-&gt;number</samp> is permitted to return <tt>#f</tt> whenever
4717 <var>string</var> uses the polar or rectangular notations for complex
4718 numbers. If all numbers are integers, then
4719 <samp>string-&gt;number</samp> may return <tt>#f</tt> whenever
4720 the fractional notation is used. If all numbers are exact, then
4721 <samp>string-&gt;number</samp> may return <tt>#f</tt> whenever
4722 an exponent marker or explicit exactness prefix is used, or if
4723 a <tt>#</tt> appears in place of a digit. If all inexact
4724 numbers are integers, then
4725 <samp>string-&gt;number</samp> may return <tt>#f</tt> whenever
4726 a decimal point is used.
4727 </p></blockquote>
4728
4729
4730
4731
4732 <a name="Other-data-types"></a><hr size="1"><br/><br/><br/>
4733 <table cellpadding="1" cellspacing="1" border="0">
4734 <tr><td valign="middle" align="left"><a href="#Numerical-input-and-output" title="Previous section in reading order"><img src="button-left.png" border="0" alt="Back: 6.2.6 Numerical input and output" align="middle" width="32"></a></td>
4735 <td valign="middle" align="left"><a href="#Booleans" title="Next section in reading order"><img src="button-right.png" border="0" alt="Forward: 6.3.1 Booleans" align="middle" width="32"></a></td>
4736 <td valign="middle" align="left"> &nbsp; </td>
4737 <td valign="middle" align="left"><a href="#Standard-procedures" title="Beginning of this chapter or previous chapter"><img src="button-left-left.png" border="0" alt="FastBack: 6. Standard procedures" align="middle" width="32"></a></td>
4738 <td valign="middle" align="left"><a href="#Standard-procedures" title="Up section"><img src="button-up.png" border="0" alt="Up: 6. Standard procedures" align="middle" width="32"></a></td>
4739 <td valign="middle" align="left"><a href="#Formal-syntax-and-semantics" title="Next chapter"><img src="button-right-right.png" border="0" alt="FastForward: 7. Formal syntax and semantics" align="middle" width="32"></a></td>
4740 <td valign="middle" align="left"><a href="#Top" title="Cover (top) of document"><img src="button-up-arrow.png" border="0" alt="Top: Revised(5) Report on the Algorithmic Language Scheme" align="middle" width="32"></a></td>
4741 <td valign="middle" align="left"><a href="#SEC_Contents" title="Table of contents"><img src="button-compass.png" border="0" alt="Contents: Table of Contents" align="middle" width="32"></a></td>
4742 <td valign="middle" align="left"><a href="#Index" title="Index"><img src="button-abc.png" border="0" alt="Index: Alphabetic index of definitions of concepts, keywords, and procedures" align="middle" width="32"></a></td>
4743 </tr></table>
4744 <a name="Other-data-types-1"></a>
4745 <h2 class="section">6.3 Other data types</h2>
4746
4747 <table class="menu" border="0" cellspacing="0">
4748 <tr><td align="left" valign="top"><a href="#Booleans">6.3.1 Booleans</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
4749 </td></tr>
4750 <tr><td align="left" valign="top"><a href="#Pairs-and-lists">6.3.2 Pairs and lists</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
4751 </td></tr>
4752 <tr><td align="left" valign="top"><a href="#Symbols">6.3.3 Symbols</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
4753 </td></tr>
4754 <tr><td align="left" valign="top"><a href="#Characters">6.3.4 Characters</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
4755 </td></tr>
4756 <tr><td align="left" valign="top"><a href="#Strings">6.3.5 Strings</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
4757 </td></tr>
4758 <tr><td align="left" valign="top"><a href="#Vectors">6.3.6 Vectors</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
4759 </td></tr>
4760 </table>
4761
4762
4763 <p>This section describes operations on some of Scheme's non-numeric data types:
4764 booleans, pairs, lists, symbols, characters, strings and vectors.
4765 </p>
4766 <a name="Booleans"></a><hr size="1"><br/><br/><br/>
4767 <table cellpadding="1" cellspacing="1" border="0">
4768 <tr><td valign="middle" align="left"><a href="#Other-data-types" title="Previous section in reading order"><img src="button-left.png" border="0" alt="Back: 6.3 Other data types" align="middle" width="32"></a></td>
4769 <td valign="middle" align="left"><a href="#Pairs-and-lists" title="Next section in reading order"><img src="button-right.png" border="0" alt="Forward: 6.3.2 Pairs and lists" align="middle" width="32"></a></td>
4770 <td valign="middle" align="left"> &nbsp; </td>
4771 <td valign="middle" align="left"><a href="#Standard-procedures" title="Beginning of this chapter or previous chapter"><img src="button-left-left.png" border="0" alt="FastBack: 6. Standard procedures" align="middle" width="32"></a></td>
4772 <td valign="middle" align="left"><a href="#Other-data-types" title="Up section"><img src="button-up.png" border="0" alt="Up: 6.3 Other data types" align="middle" width="32"></a></td>
4773 <td valign="middle" align="left"><a href="#Formal-syntax-and-semantics" title="Next chapter"><img src="button-right-right.png" border="0" alt="FastForward: 7. Formal syntax and semantics" align="middle" width="32"></a></td>
4774 <td valign="middle" align="left"><a href="#Top" title="Cover (top) of document"><img src="button-up-arrow.png" border="0" alt="Top: Revised(5) Report on the Algorithmic Language Scheme" align="middle" width="32"></a></td>
4775 <td valign="middle" align="left"><a href="#SEC_Contents" title="Table of contents"><img src="button-compass.png" border="0" alt="Contents: Table of Contents" align="middle" width="32"></a></td>
4776 <td valign="middle" align="left"><a href="#Index" title="Index"><img src="button-abc.png" border="0" alt="Index: Alphabetic index of definitions of concepts, keywords, and procedures" align="middle" width="32"></a></td>
4777 </tr></table>
4778 <a name="Booleans-1"></a>
4779 <h3 class="subsection">6.3.1 Booleans</h3>
4780
4781
4782
4783 <p>The standard boolean objects for true and false are written as
4784 <tt>#t</tt> and <tt>#f</tt>. What really
4785 <a name="index-_0023f"></a>
4786 <a name="index-_0023t"></a>
4787 matters, though, are the objects that the Scheme conditional expressions
4788 (<samp>if</samp>, <samp>cond</samp>, <samp>and</samp>, <samp>or</samp>, <samp>do</samp>) treat as
4789 true or false. The phrase &ldquo;a true value&rdquo;
4790 <a name="index-false-1"></a>
4791 <a name="index-true-3"></a>
4792 (or sometimes just &ldquo;true&rdquo;) means any object treated as true by the
4793 conditional expressions, and the phrase &ldquo;a false value&rdquo; (or
4794 <a name="index-false-2"></a>
4795 &ldquo;false&rdquo;) means any object treated as false by the conditional expressions.
4796 </p>
4797 <p>Of all the standard Scheme values, only <tt>#f</tt>
4798 counts as false in conditional expressions.
4799 Except for <tt>#f</tt>,
4800 all standard Scheme values, including <tt>#t</tt>,
4801 pairs, the empty list, symbols, numbers, strings, vectors, and procedures,
4802 count as true.
4803 </p>
4804
4805
4806
4807 <blockquote><p><em>Note:</em>
4808 Programmers accustomed to other dialects of Lisp should be aware that
4809 Scheme distinguishes both <tt>#f</tt> and the empty list
4810 <a name="index-empty-list-1"></a>
4811 from the symbol <code>nil</code>.
4812 <a name="index-nil"></a>
4813 </p></blockquote>
4814
4815
4816 <p>Boolean constants evaluate to themselves, so they do not need to be quoted
4817 in programs.
4818 </p>
4819
4820 <table><tr><td>&nbsp;</td><td><pre class="example">
4821 #t ==&gt; #t
4822 #f ==&gt; #f
4823 '#f ==&gt; #f
4824 </pre></td></tr></table>
4825
4826
4827
4828
4829 <a name="Definition_of_not"></a><a name="Library_procedure_not"></a><a name="index-not"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Library_procedure_not">not</a></b></code><i> obj</i><code>)</code></td><td align="right">library procedure</td></tr></table>
4830
4831 <p><samp>Not</samp> returns <tt>#t</tt> if <var>obj</var> is false, and returns
4832 <tt>#f</tt> otherwise.
4833 </p>
4834
4835 <table><tr><td>&nbsp;</td><td><pre class="format">(not #t) ==&gt; #f
4836 (not 3) ==&gt; #f
4837 (not (list 3)) ==&gt; #f
4838 (not #f) ==&gt; #t
4839 (not '()) ==&gt; #f
4840 (not (list)) ==&gt; #f
4841 (not 'nil) ==&gt; #f
4842 </pre></td></tr></table>
4843
4844
4845
4846
4847
4848
4849 <a name="Definition_of_boolean?"></a><a name="Library_procedure_boolean?"></a><a name="index-boolean_003f-1"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Library_procedure_boolean?">boolean?</a></b></code><i> obj</i><code>)</code></td><td align="right">library procedure</td></tr></table>
4850
4851 <p><samp>Boolean?</samp> returns <tt>#t</tt> if <var>obj</var> is either <tt>#t</tt> or
4852 <tt>#f</tt> and returns <tt>#f</tt> otherwise.
4853 </p>
4854
4855 <table><tr><td>&nbsp;</td><td><pre class="format">(boolean? #f) ==&gt; #t
4856 (boolean? 0) ==&gt; #f
4857 (boolean? '()) ==&gt; #f
4858 </pre></td></tr></table>
4859
4860
4861
4862
4863
4864 <a name="Pairs-and-lists"></a><hr size="1"><br/><br/><br/>
4865 <table cellpadding="1" cellspacing="1" border="0">
4866 <tr><td valign="middle" align="left"><a href="#Booleans" title="Previous section in reading order"><img src="button-left.png" border="0" alt="Back: 6.3.1 Booleans" align="middle" width="32"></a></td>
4867 <td valign="middle" align="left"><a href="#Symbols" title="Next section in reading order"><img src="button-right.png" border="0" alt="Forward: 6.3.3 Symbols" align="middle" width="32"></a></td>
4868 <td valign="middle" align="left"> &nbsp; </td>
4869 <td valign="middle" align="left"><a href="#Standard-procedures" title="Beginning of this chapter or previous chapter"><img src="button-left-left.png" border="0" alt="FastBack: 6. Standard procedures" align="middle" width="32"></a></td>
4870 <td valign="middle" align="left"><a href="#Other-data-types" title="Up section"><img src="button-up.png" border="0" alt="Up: 6.3 Other data types" align="middle" width="32"></a></td>
4871 <td valign="middle" align="left"><a href="#Formal-syntax-and-semantics" title="Next chapter"><img src="button-right-right.png" border="0" alt="FastForward: 7. Formal syntax and semantics" align="middle" width="32"></a></td>
4872 <td valign="middle" align="left"><a href="#Top" title="Cover (top) of document"><img src="button-up-arrow.png" border="0" alt="Top: Revised(5) Report on the Algorithmic Language Scheme" align="middle" width="32"></a></td>
4873 <td valign="middle" align="left"><a href="#SEC_Contents" title="Table of contents"><img src="button-compass.png" border="0" alt="Contents: Table of Contents" align="middle" width="32"></a></td>
4874 <td valign="middle" align="left"><a href="#Index" title="Index"><img src="button-abc.png" border="0" alt="Index: Alphabetic index of definitions of concepts, keywords, and procedures" align="middle" width="32"></a></td>
4875 </tr></table>
4876 <a name="Pairs-and-lists-1"></a>
4877 <h3 class="subsection">6.3.2 Pairs and lists</h3>
4878
4879
4880
4881 <p>A <em>pair</em> (sometimes called a <em>dotted pair</em>) is a
4882 <a name="index-dotted-pair"></a>
4883 <a name="index-pair"></a>
4884 record structure with two fields called the car and cdr fields (for
4885 historical reasons). Pairs are created by the procedure <samp>cons</samp>.
4886 The car and cdr fields are accessed by the procedures <samp>car</samp> and
4887 <samp>cdr</samp>. The car and cdr fields are assigned by the procedures
4888 <samp>set-car!</samp> and <samp>set-cdr!</samp>.
4889 </p>
4890 <p>Pairs are used primarily to represent lists. A list can
4891 be defined recursively as either the empty list or a pair whose
4892 <a name="index-empty-list-2"></a>
4893 cdr is a list. More precisely, the set of lists is defined as the smallest
4894 set <var>X</var> such that
4895 </p>
4896
4897
4898 <ul>
4899 <li>
4900 The empty list is in <var>X</var>.
4901 </li><li>
4902 If <var>list</var> is in <var>X</var>, then any pair whose cdr field contains
4903 <var>list</var> is also in <var>X</var>.
4904
4905 </li></ul>
4906
4907
4908 <p>The objects in the car fields of successive pairs of a list are the
4909 elements of the list. For example, a two-element list is a pair whose car
4910 is the first element and whose cdr is a pair whose car is the second element
4911 and whose cdr is the empty list. The length of a list is the number of
4912 elements, which is the same as the number of pairs.
4913 </p>
4914 <p>The empty list is a special object of its own type
4915 <a name="index-empty-list-3"></a>
4916 (it is not a pair); it has no elements and its length is zero.
4917 </p>
4918
4919 <blockquote><p><em>Note:</em>
4920 The above definitions imply that all lists have finite length and are
4921 terminated by the empty list.
4922 </p></blockquote>
4923
4924
4925 <p>The most general notation (external representation) for Scheme pairs is
4926 the &ldquo;dotted&rdquo; notation <samp>(<var>c1</var> . <var>c2</var>)</samp> where
4927 <var>c1</var> is the value of the car field and <var>c2</var> is the value of the
4928 cdr field. For example <samp>(4 . 5)</samp> is a pair whose car is 4 and whose
4929 cdr is 5. Note that <samp>(4 . 5)</samp> is the external representation of a
4930 pair, not an expression that evaluates to a pair.
4931 </p>
4932 <p>A more streamlined notation can be used for lists: the elements of the
4933 list are simply enclosed in parentheses and separated by spaces. The
4934 empty list is written <tt>()</tt> . For example,
4935 <a name="index-empty-list-4"></a>
4936 </p>
4937
4938 <table><tr><td>&nbsp;</td><td><pre class="example">
4939 (a b c d e)
4940 </pre></td></tr></table>
4941
4942
4943 <p>and
4944 </p>
4945
4946 <table><tr><td>&nbsp;</td><td><pre class="example">
4947 (a . (b . (c . (d . (e . ())))))
4948 </pre></td></tr></table>
4949
4950
4951 <p>are equivalent notations for a list of symbols.
4952 </p>
4953 <p>A chain of pairs not ending in the empty list is called an
4954 <em>improper list</em>. Note that an improper list is not a list.
4955 <a name="index-improper-list"></a>
4956 The list and dotted notations can be combined to represent
4957 improper lists:
4958 </p>
4959
4960 <table><tr><td>&nbsp;</td><td><pre class="example">
4961 (a b c . d)
4962 </pre></td></tr></table>
4963
4964
4965 <p>is equivalent to
4966 </p>
4967
4968 <table><tr><td>&nbsp;</td><td><pre class="example">
4969 (a . (b . (c . d)))
4970 </pre></td></tr></table>
4971
4972
4973 <p>Whether a given pair is a list depends upon what is stored in the cdr
4974 field. When the <code>set-cdr!</code> procedure is used, an object can be a
4975 <a name="index-set_002dcdr_0021"></a>
4976 list one moment and not the next:
4977 </p>
4978
4979 <table><tr><td>&nbsp;</td><td><pre class="example">
4980 (define x (list 'a 'b 'c))
4981 (define y x)
4982 y ==&gt; (a b c)
4983 (list? y) ==&gt; #t
4984 (set-cdr! x 4) ==&gt; <em>unspecified</em>
4985 x ==&gt; (a . 4)
4986 (eqv? x y) ==&gt; #t
4987 y ==&gt; (a . 4)
4988 (list? y) ==&gt; #f
4989 (set-cdr! x x) ==&gt; <em>unspecified</em>
4990 (list? x) ==&gt; #f
4991 </pre></td></tr></table>
4992
4993
4994
4995
4996 <p>Within literal expressions and representations of objects read by the
4997 <code>read</code> procedure, the forms <tt>'</tt><span class="roman">&lt;datum&gt;</span>,
4998 <a name="index-_0027-2"></a>
4999 <a name="index-read"></a>
5000 <tt>&lsquo;</tt><span class="roman">&lt;datum&gt;</span>, <tt>,</tt><span class="roman">&lt;datum&gt;</span>, and
5001 <a name="index-_002c-1"></a>
5002 <tt>,@</tt><span class="roman">&lt;datum&gt;</span> denote two-element lists whose first elements are
5003 the symbols <code>quote</code>, <code>quasiquote</code>, <code>unquote</code>, and
5004 <a name="index-unquote-1"></a>
5005 <a name="index-quasiquote-2"></a>
5006 <a name="index-quote-1"></a>
5007 <code>unquote-splicing</code>, respectively. The second element in each case
5008 <a name="index-unquote_002dsplicing-1"></a>
5009 is <span class="roman">&lt;datum&gt;</span>. This convention is supported so that arbitrary Scheme
5010 programs may be represented as lists.
5011 That is, according to Scheme's grammar, every
5012 &lt;expression&gt; is also a &lt;datum&gt; (see section see section <a href="#External-representation">External representations</a>).
5013 Among other things, this permits the use of the <samp>read</samp> procedure to
5014 parse Scheme programs. See section <a href="#External-representations">External representations</a>.
5015 </p>
5016
5017
5018 <a name="Definition_of_pair?"></a><a name="Procedure_pair?"></a><a name="index-pair_003f-1"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Procedure_pair?">pair?</a></b></code><i> obj</i><code>)</code></td><td align="right">procedure</td></tr></table>
5019
5020 <p><samp>Pair?</samp> returns <tt>#t</tt> if <var>obj</var> is a pair, and otherwise
5021 returns <tt>#f</tt>.
5022 </p>
5023
5024 <table><tr><td>&nbsp;</td><td><pre class="format">(pair? '(a . b)) ==&gt; #t
5025 (pair? '(a b c)) ==&gt; #t
5026 (pair? '()) ==&gt; #f
5027 (pair? '#(a b)) ==&gt; #f
5028 </pre></td></tr></table>
5029
5030
5031
5032
5033
5034 <a name="Definition_of_cons"></a><a name="Procedure_cons"></a><a name="index-cons"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Procedure_cons">cons</a></b></code><i> obj1 obj2</i><code>)</code></td><td align="right">procedure</td></tr></table>
5035
5036 <p>Returns a newly allocated pair whose car is <var>obj1</var> and whose cdr is
5037 <var>obj2</var>. The pair is guaranteed to be different (in the sense of
5038 <samp>eqv?</samp>) from every existing object.
5039 </p>
5040
5041 <table><tr><td>&nbsp;</td><td><pre class="format">(cons 'a '()) ==&gt; (a)
5042 (cons '(a) '(b c d)) ==&gt; ((a) b c d)
5043 (cons &quot;a&quot; '(b c)) ==&gt; (&quot;a&quot; b c)
5044 (cons 'a 3) ==&gt; (a . 3)
5045 (cons '(a b) 'c) ==&gt; ((a b) . c)
5046 </pre></td></tr></table>
5047
5048
5049
5050
5051
5052 <a name="Definition_of_car"></a><a name="Procedure_car"></a><a name="index-car"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Procedure_car">car</a></b></code><i> pair</i><code>)</code></td><td align="right">procedure</td></tr></table>
5053
5054
5055 <p>Returns the contents of the car field of <var>pair</var>. Note that it is an
5056 error to take the car of the empty list.
5057 <a name="index-empty-list-5"></a>
5058 </p>
5059
5060 <table><tr><td>&nbsp;</td><td><pre class="format">(car '(a b c)) ==&gt; a
5061 (car '((a) b c d)) ==&gt; (a)
5062 (car '(1 . 2)) ==&gt; 1
5063 (car '()) ==&gt; <em>error</em>
5064 </pre></td></tr></table>
5065
5066
5067
5068
5069
5070
5071 <a name="Definition_of_cdr"></a><a name="Procedure_cdr"></a><a name="index-cdr"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Procedure_cdr">cdr</a></b></code><i> pair</i><code>)</code></td><td align="right">procedure</td></tr></table>
5072
5073
5074 <p>Returns the contents of the cdr field of <var>pair</var>.
5075 Note that it is an error to take the cdr of the empty list.
5076 </p>
5077
5078 <table><tr><td>&nbsp;</td><td><pre class="format">(cdr '((a) b c d)) ==&gt; (b c d)
5079 (cdr '(1 . 2)) ==&gt; 2
5080 (cdr '()) ==&gt; <em>error</em>
5081 </pre></td></tr></table>
5082
5083
5084
5085
5086
5087
5088 <a name="Definition_of_set-car!"></a><a name="Procedure_set-car!"></a><a name="index-set_002dcar_0021"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Procedure_set-car!">set-car!</a></b></code><i> pair obj</i><code>)</code></td><td align="right">procedure</td></tr></table>
5089
5090
5091 <p>Stores <var>obj</var> in the car field of <var>pair</var>.
5092 The value returned by <samp>set-car!</samp> is unspecified.
5093 </p>
5094
5095 <table><tr><td>&nbsp;</td><td><pre class="format">(define (f) (list 'not-a-constant-list))
5096 (define (g) '(constant-list))
5097 (set-car! (f) 3) ==&gt; <em>unspecified</em>
5098 (set-car! (g) 3) ==&gt; <em>error</em>
5099 </pre></td></tr></table>
5100
5101
5102
5103
5104
5105
5106 <a name="Definition_of_set-cdr!"></a><a name="Procedure_set-cdr!"></a><a name="index-set_002dcdr_0021-1"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Procedure_set-cdr!">set-cdr!</a></b></code><i> pair obj</i><code>)</code></td><td align="right">procedure</td></tr></table>
5107
5108
5109 <p>Stores <var>obj</var> in the cdr field of <var>pair</var>.
5110 The value returned by <samp>set-cdr!</samp> is unspecified.
5111 </p>
5112
5113
5114
5115
5116
5117
5118
5119 <a name="Definition_of_caar"></a><a name="Library_procedure_caar"></a><a name="index-caar"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Library_procedure_caar">caar</a></b></code><i> pair</i><code>)</code></td><td align="right">library procedure</td></tr></table>
5120 <a name="Definition_of_cadr"></a><a name="Library_procedure_cadr"></a><a name="index-cadr"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Library_procedure_cadr">cadr</a></b></code><i> pair</i><code>)</code></td><td align="right">library procedure</td></tr></table>
5121 <table width="100%"><tr><td align="left"> <code><b>&hellip;</b></code></td><td align="right">&hellip;</td></tr></table>
5122 <a name="Definition_of_cdddar"></a><a name="Library_procedure_cdddar"></a><a name="index-cdddar"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Library_procedure_cdddar">cdddar</a></b></code><i> pair</i><code>)</code></td><td align="right">library procedure</td></tr></table>
5123 <a name="Definition_of_cddddr"></a><a name="Library_procedure_cddddr"></a><a name="index-cddddr"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Library_procedure_cddddr">cddddr</a></b></code><i> pair</i><code>)</code></td><td align="right">library procedure</td></tr></table>
5124
5125 <p>These procedures are compositions of <samp>car</samp> and <samp>cdr</samp>, where
5126 for example <samp>caddr</samp> could be defined by
5127 </p>
5128
5129 <table><tr><td>&nbsp;</td><td><pre class="format">(define caddr (lambda (x) (car (cdr (cdr x)))))<span class="roman">.</span>
5130 </pre></td></tr></table>
5131
5132
5133 <p>Arbitrary compositions, up to four deep, are provided. There are
5134 twenty-eight of these procedures in all.
5135 </p>
5136
5137
5138
5139
5140 <a name="Definition_of_null?"></a><a name="Library_procedure_null?"></a><a name="index-null_003f"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Library_procedure_null?">null?</a></b></code><i> obj</i><code>)</code></td><td align="right">library procedure</td></tr></table>
5141
5142 <p>Returns <tt>#t</tt> if <var>obj</var> is the empty list,
5143 <a name="index-empty-list-6"></a>
5144 otherwise returns <tt>#f</tt>.
5145 </p>
5146
5147
5148
5149
5150 <a name="Definition_of_list?"></a><a name="Library_procedure_list?"></a><a name="index-list_003f"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Library_procedure_list?">list?</a></b></code><i> obj</i><code>)</code></td><td align="right">library procedure</td></tr></table>
5151
5152 <p>Returns <tt>#t</tt> if <var>obj</var> is a list, otherwise returns <tt>#f</tt>.
5153 By definition, all lists have finite length and are terminated by
5154 the empty list.
5155 </p>
5156
5157 <table><tr><td>&nbsp;</td><td><pre class="format"> (list? '(a b c)) ==&gt; #t
5158 (list? '()) ==&gt; #t
5159 (list? '(a . b)) ==&gt; #f
5160 (let ((x (list 'a)))
5161 (set-cdr! x x)
5162 (list? x)) ==&gt; #f
5163 </pre></td></tr></table>
5164
5165
5166
5167
5168
5169 <a name="Definition_of_list"></a><a name="Library_procedure_list"></a><a name="index-list"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Library_procedure_list">list</a></b></code><i> <var>obj</var> &hellip;</i><code>)</code></td><td align="right">library procedure</td></tr></table>
5170
5171 <p>Returns a newly allocated list of its arguments.
5172 </p>
5173
5174 <table><tr><td>&nbsp;</td><td><pre class="format">(list 'a (+ 3 4) 'c) ==&gt; (a 7 c)
5175 (list) ==&gt; ()
5176 </pre></td></tr></table>
5177
5178
5179
5180
5181
5182 <a name="Definition_of_length"></a><a name="Library_procedure_length"></a><a name="index-length-1"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Library_procedure_length">length</a></b></code><i> list</i><code>)</code></td><td align="right">library procedure</td></tr></table>
5183
5184
5185 <p>Returns the length of <var>list</var>.
5186 </p>
5187
5188 <table><tr><td>&nbsp;</td><td><pre class="format">(length '(a b c)) ==&gt; 3
5189 (length '(a (b) (c d e))) ==&gt; 3
5190 (length '()) ==&gt; 0
5191 </pre></td></tr></table>
5192
5193
5194
5195
5196
5197 <a name="Definition_of_append"></a><a name="Library_procedure_append"></a><a name="index-append"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Library_procedure_append">append</a></b></code><i> list &hellip;</i><code>)</code></td><td align="right">library procedure</td></tr></table>
5198
5199
5200 <p>Returns a list consisting of the elements of the first <var>list</var>
5201 followed by the elements of the other <var>list</var>s.
5202 </p>
5203
5204 <table><tr><td>&nbsp;</td><td><pre class="format">(append '(x) '(y)) ==&gt; (x y)
5205 (append '(a) '(b c d)) ==&gt; (a b c d)
5206 (append '(a (b)) '((c))) ==&gt; (a (b) (c))
5207 </pre></td></tr></table>
5208
5209
5210 <p>The resulting list is always newly allocated, except that it shares
5211 structure with the last <var>list</var> argument. The last argument may
5212 actually be any object; an improper list results if the last argument is not a
5213 proper list.
5214 </p>
5215
5216
5217 <table><tr><td>&nbsp;</td><td><pre class="format">(append '(a b) '(c . d)) ==&gt; (a b c . d)
5218 (append '() 'a) ==&gt; a
5219 </pre></td></tr></table>
5220
5221
5222
5223
5224
5225 <a name="Definition_of_reverse"></a><a name="Library_procedure_reverse"></a><a name="index-reverse"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Library_procedure_reverse">reverse</a></b></code><i> list</i><code>)</code></td><td align="right">library procedure</td></tr></table>
5226
5227
5228 <p>Returns a newly allocated list consisting of the elements of <var>list</var>
5229 in reverse order.
5230 </p>
5231
5232 <table><tr><td>&nbsp;</td><td><pre class="format">(reverse '(a b c)) ==&gt; (c b a)
5233 (reverse '(a (b c) d (e (f))))
5234 ==&gt; ((e (f)) d (b c) a)
5235 </pre></td></tr></table>
5236
5237
5238
5239
5240
5241 <a name="Definition_of_list-tail"></a><a name="Library_procedure_list-tail"></a><a name="index-list_002dtail"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Library_procedure_list-tail">list-tail</a></b></code><i> list <var>k</var></i><code>)</code></td><td align="right">library procedure</td></tr></table>
5242
5243 <p>Returns the sublist of <var>list</var> obtained by omitting the first <var>k</var>
5244 elements. It is an error if <var>list</var> has fewer than <var>k</var> elements.
5245 <samp>List-tail</samp> could be defined by
5246 </p>
5247
5248 <table><tr><td>&nbsp;</td><td><pre class="format">(define list-tail
5249 (lambda (x k)
5250 (if (zero? k)
5251 x
5252 (list-tail (cdr x) (- k 1)))))
5253 </pre></td></tr></table>
5254
5255
5256
5257
5258
5259 <a name="Definition_of_list-ref"></a><a name="Library_procedure_list-ref"></a><a name="index-list_002dref"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Library_procedure_list-ref">list-ref</a></b></code><i> list <var>k</var></i><code>)</code></td><td align="right">library procedure</td></tr></table>
5260
5261 <p>Returns the <var>k</var>th element of <var>list</var>. (This is the same
5262 as the car of <tt>(list-tail <var>list</var> <var>k</var>)</tt>.)
5263 It is an error if <var>list</var> has fewer than <var>k</var> elements.
5264 </p>
5265
5266 <table><tr><td>&nbsp;</td><td><pre class="format">(list-ref '(a b c d) 2) ==&gt; c
5267 (list-ref '(a b c d)
5268 (inexact-&gt;exact (round 1.8)))
5269 ==&gt; c
5270 </pre></td></tr></table>
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280
5281 <a name="Definition_of_memq"></a><a name="Library_procedure_memq"></a><a name="index-memq"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Library_procedure_memq">memq</a></b></code><i> obj list</i><code>)</code></td><td align="right">library procedure</td></tr></table>
5282 <a name="Definition_of_memv"></a><a name="Library_procedure_memv"></a><a name="index-memv"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Library_procedure_memv">memv</a></b></code><i> obj list</i><code>)</code></td><td align="right">library procedure</td></tr></table>
5283 <a name="Definition_of_member"></a><a name="Library_procedure_member"></a><a name="index-member"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Library_procedure_member">member</a></b></code><i> obj list</i><code>)</code></td><td align="right">library procedure</td></tr></table>
5284
5285 <p>These procedures return the first sublist of <var>list</var> whose car is
5286 <var>obj</var>, where the sublists of <var>list</var> are the non-empty lists
5287 returned by <tt>(list-tail <var>list</var> <var>k</var>)</tt> for <var>k</var> less
5288 than the length of <var>list</var>. If
5289 <var>obj</var> does not occur in <var>list</var>, then <tt>#f</tt> (not the empty list) is
5290 returned. <samp>Memq</samp> uses <samp>eq?</samp> to compare <var>obj</var> with the elements of
5291 <var>list</var>, while <samp>memv</samp> uses <samp>eqv?</samp> and <samp>member</samp> uses <samp>equal?</samp>.
5292 </p>
5293
5294 <table><tr><td>&nbsp;</td><td><pre class="format">(memq 'a '(a b c)) ==&gt; (a b c)
5295 (memq 'b '(a b c)) ==&gt; (b c)
5296 (memq 'a '(b c d)) ==&gt; #f
5297 (memq (list 'a) '(b (a) c)) ==&gt; #f
5298 (member (list 'a)
5299 '(b (a) c)) ==&gt; ((a) c)
5300 (memq 101 '(100 101 102)) ==&gt; <em>unspecified</em>
5301 (memv 101 '(100 101 102)) ==&gt; (101 102)
5302 </pre></td></tr></table>
5303
5304
5305
5306
5307
5308
5309 <a name="Definition_of_assq"></a><a name="Library_procedure_assq"></a><a name="index-assq"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Library_procedure_assq">assq</a></b></code><i> obj alist</i><code>)</code></td><td align="right">library procedure</td></tr></table>
5310 <a name="Definition_of_assv"></a><a name="Library_procedure_assv"></a><a name="index-assv"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Library_procedure_assv">assv</a></b></code><i> obj alist</i><code>)</code></td><td align="right">library procedure</td></tr></table>
5311 <a name="Definition_of_assoc"></a><a name="Library_procedure_assoc"></a><a name="index-assoc"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Library_procedure_assoc">assoc</a></b></code><i> obj alist</i><code>)</code></td><td align="right">library procedure</td></tr></table>
5312
5313 <p><var>Alist</var> (for &ldquo;association list&rdquo;) must be a list of
5314 pairs. These procedures find the first pair in <var>alist</var> whose car field is <var>obj</var>,
5315 and returns that pair. If no pair in <var>alist</var> has <var>obj</var> as its
5316 car, then <tt>#f</tt> (not the empty list) is returned. <samp>Assq</samp> uses
5317 <samp>eq?</samp> to compare <var>obj</var> with the car fields of the pairs in <var>alist</var>,
5318 while <samp>assv</samp> uses <samp>eqv?</samp> and <samp>assoc</samp> uses <samp>equal?</samp>.
5319 </p>
5320
5321 <table><tr><td>&nbsp;</td><td><pre class="format">(define e '((a 1) (b 2) (c 3)))
5322 (assq 'a e) ==&gt; (a 1)
5323 (assq 'b e) ==&gt; (b 2)
5324 (assq 'd e) ==&gt; #f
5325 (assq (list 'a) '(((a)) ((b)) ((c))))
5326 ==&gt; #f
5327 (assoc (list 'a) '(((a)) ((b)) ((c))))
5328 ==&gt; ((a))
5329 (assq 5 '((2 3) (5 7) (11 13)))
5330 ==&gt; <em>unspecified</em>
5331 (assv 5 '((2 3) (5 7) (11 13)))
5332 ==&gt; (5 7)
5333 </pre></td></tr></table>
5334
5335
5336
5337
5338 <blockquote><p><em>Rationale:</em>
5339 Although they are ordinarily used as predicates,
5340 <samp>memq</samp>, <samp>memv</samp>, <samp>member</samp>, <samp>assq</samp>, <samp>assv</samp>, and <samp>assoc</samp> do not
5341 have question marks in their names because they return useful values rather
5342 than just <tt>#t</tt> or <tt>#f</tt>.
5343 </p></blockquote>
5344
5345
5346
5347
5348 <a name="Symbols"></a><hr size="1"><br/><br/><br/>
5349 <table cellpadding="1" cellspacing="1" border="0">
5350 <tr><td valign="middle" align="left"><a href="#Pairs-and-lists" title="Previous section in reading order"><img src="button-left.png" border="0" alt="Back: 6.3.2 Pairs and lists" align="middle" width="32"></a></td>
5351 <td valign="middle" align="left"><a href="#Characters" title="Next section in reading order"><img src="button-right.png" border="0" alt="Forward: 6.3.4 Characters" align="middle" width="32"></a></td>
5352 <td valign="middle" align="left"> &nbsp; </td>
5353 <td valign="middle" align="left"><a href="#Standard-procedures" title="Beginning of this chapter or previous chapter"><img src="button-left-left.png" border="0" alt="FastBack: 6. Standard procedures" align="middle" width="32"></a></td>
5354 <td valign="middle" align="left"><a href="#Other-data-types" title="Up section"><img src="button-up.png" border="0" alt="Up: 6.3 Other data types" align="middle" width="32"></a></td>
5355 <td valign="middle" align="left"><a href="#Formal-syntax-and-semantics" title="Next chapter"><img src="button-right-right.png" border="0" alt="FastForward: 7. Formal syntax and semantics" align="middle" width="32"></a></td>
5356 <td valign="middle" align="left"><a href="#Top" title="Cover (top) of document"><img src="button-up-arrow.png" border="0" alt="Top: Revised(5) Report on the Algorithmic Language Scheme" align="middle" width="32"></a></td>
5357 <td valign="middle" align="left"><a href="#SEC_Contents" title="Table of contents"><img src="button-compass.png" border="0" alt="Contents: Table of Contents" align="middle" width="32"></a></td>
5358 <td valign="middle" align="left"><a href="#Index" title="Index"><img src="button-abc.png" border="0" alt="Index: Alphabetic index of definitions of concepts, keywords, and procedures" align="middle" width="32"></a></td>
5359 </tr></table>
5360 <a name="Symbols-1"></a>
5361 <h3 class="subsection">6.3.3 Symbols</h3>
5362
5363
5364
5365 <p>Symbols are objects whose usefulness rests on the fact that two
5366 symbols are identical (in the sense of <samp>eqv?</samp>) if and only if their
5367 names are spelled the same way. This is exactly the property needed to
5368 represent identifiers in programs, and so most
5369 <a name="index-identifier-2"></a>
5370 implementations of Scheme use them internally for that purpose. Symbols
5371 are useful for many other applications; for instance, they may be used
5372 the way enumerated values are used in Pascal.
5373 </p>
5374 <p>The rules for writing a symbol are exactly the same as the rules for
5375 writing an identifier; see sections <a href="#Identifiers">Identifiers</a>
5376 and <a href="#Lexical-structure">Lexical structure</a>.
5377 </p>
5378 <p>It is guaranteed that any symbol that has been returned as part of
5379 a literal expression, or read using the <samp>read</samp> procedure, and
5380 subsequently written out using the <samp>write</samp> procedure, will read back
5381 in as the identical symbol (in the sense of <samp>eqv?</samp>). The
5382 <samp>string-&gt;symbol</samp> procedure, however, can create symbols for
5383 which this write/read invariance may not hold because their names
5384 contain special characters or letters in the non-standard case.
5385 </p>
5386
5387 <blockquote><p><em>Note:</em>
5388 Some implementations of Scheme have a feature known as &ldquo;slashification&rdquo;
5389 in order to guarantee write/read invariance for all symbols, but
5390 historically the most important use of this feature has been to
5391 compensate for the lack of a string data type.
5392 </p>
5393 <p>Some implementations also have &ldquo;uninterned symbols&rdquo;, which
5394 defeat write/read invariance even in implementations with slashification,
5395 and also generate exceptions to the rule that two symbols are the same
5396 if and only if their names are spelled the same.
5397 </p></blockquote>
5398
5399
5400
5401
5402 <a name="Definition_of_symbol?"></a><a name="Procedure_symbol?"></a><a name="index-symbol_003f-1"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Procedure_symbol?">symbol?</a></b></code><i> obj</i><code>)</code></td><td align="right">procedure</td></tr></table>
5403
5404 <p>Returns <tt>#t</tt> if <var>obj</var> is a symbol, otherwise returns <tt>#f</tt>.
5405 </p>
5406
5407 <table><tr><td>&nbsp;</td><td><pre class="format">(symbol? 'foo) ==&gt; #t
5408 (symbol? (car '(a b))) ==&gt; #t
5409 (symbol? &quot;bar&quot;) ==&gt; #f
5410 (symbol? 'nil) ==&gt; #t
5411 (symbol? '()) ==&gt; #f
5412 (symbol? #f) ==&gt; #f
5413 </pre></td></tr></table>
5414
5415
5416
5417
5418
5419 <a name="Definition_of_symbol-%3Estring"></a><a name="Procedure_symbol-%3Estring"></a><a name="index-symbol_002d_003estring-1"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Procedure_symbol-%3Estring">symbol-&gt;string</a></b></code><i> symbol</i><code>)</code></td><td align="right">procedure</td></tr></table>
5420
5421 <p>Returns the name of <var>symbol</var> as a string. If the symbol was part of
5422 an object returned as the value of a literal expression
5423 (section see section <a href="#Literal-expressions">Literal expressions</a>) or by a call to the <samp>read</samp> procedure,
5424 and its name contains alphabetic characters, then the string returned
5425 will contain characters in the implementation's preferred standard
5426 case&mdash;some implementations will prefer upper case, others lower case.
5427 If the symbol was returned by <samp>string-&gt;symbol</samp>, the case of
5428 characters in the string returned will be the same as the case in the
5429 string that was passed to <samp>string-&gt;symbol</samp>. It is an error
5430 to apply mutation procedures like <code>string-set!</code> to strings returned
5431 <a name="index-string_002dset_0021"></a>
5432 by this procedure.
5433 </p>
5434 <p>The following examples assume that the implementation's standard case is
5435 lower case:
5436 </p>
5437
5438 <table><tr><td>&nbsp;</td><td><pre class="format">(symbol-&gt;string 'flying-fish)
5439 ==&gt; &quot;flying-fish&quot;
5440 (symbol-&gt;string 'Martin) ==&gt; &quot;martin&quot;
5441 (symbol-&gt;string
5442 (string-&gt;symbol &quot;Malvina&quot;))
5443 ==&gt; &quot;Malvina&quot;
5444 </pre></td></tr></table>
5445
5446
5447
5448
5449
5450 <a name="Definition_of_string-%3Esymbol"></a><a name="Procedure_string-%3Esymbol"></a><a name="index-string_002d_003esymbol"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Procedure_string-%3Esymbol">string-&gt;symbol</a></b></code><i> string</i><code>)</code></td><td align="right">procedure</td></tr></table>
5451
5452 <p>Returns the symbol whose name is <var>string</var>. This procedure can
5453 create symbols with names containing special characters or letters in
5454 the non-standard case, but it is usually a bad idea to create such
5455 symbols because in some implementations of Scheme they cannot be read as
5456 themselves. See <samp>symbol-&gt;string</samp>.
5457 </p>
5458 <p>The following examples assume that the implementation's standard case is
5459 lower case:
5460 </p>
5461
5462 <table><tr><td>&nbsp;</td><td><pre class="format">(eq? 'mISSISSIppi 'mississippi)
5463 ==&gt; #t
5464 (string-&gt;symbol &quot;mISSISSIppi&quot;)
5465 ==&gt;
5466 <span class="roman"></span>the symbol with name &quot;mISSISSIppi&quot;
5467 (eq? 'bitBlt (string-&gt;symbol &quot;bitBlt&quot;))
5468 ==&gt; #f
5469 (eq? 'JollyWog
5470 (string-&gt;symbol
5471 (symbol-&gt;string 'JollyWog)))
5472 ==&gt; #t
5473 (string=? &quot;K. Harper, M.D.&quot;
5474 (symbol-&gt;string
5475 (string-&gt;symbol &quot;K. Harper, M.D.&quot;)))
5476 ==&gt; #t
5477 </pre></td></tr></table>
5478
5479
5480
5481
5482
5483 <a name="Characters"></a><hr size="1"><br/><br/><br/>
5484 <table cellpadding="1" cellspacing="1" border="0">
5485 <tr><td valign="middle" align="left"><a href="#Symbols" title="Previous section in reading order"><img src="button-left.png" border="0" alt="Back: 6.3.3 Symbols" align="middle" width="32"></a></td>
5486 <td valign="middle" align="left"><a href="#Strings" title="Next section in reading order"><img src="button-right.png" border="0" alt="Forward: 6.3.5 Strings" align="middle" width="32"></a></td>
5487 <td valign="middle" align="left"> &nbsp; </td>
5488 <td valign="middle" align="left"><a href="#Standard-procedures" title="Beginning of this chapter or previous chapter"><img src="button-left-left.png" border="0" alt="FastBack: 6. Standard procedures" align="middle" width="32"></a></td>
5489 <td valign="middle" align="left"><a href="#Other-data-types" title="Up section"><img src="button-up.png" border="0" alt="Up: 6.3 Other data types" align="middle" width="32"></a></td>
5490 <td valign="middle" align="left"><a href="#Formal-syntax-and-semantics" title="Next chapter"><img src="button-right-right.png" border="0" alt="FastForward: 7. Formal syntax and semantics" align="middle" width="32"></a></td>
5491 <td valign="middle" align="left"><a href="#Top" title="Cover (top) of document"><img src="button-up-arrow.png" border="0" alt="Top: Revised(5) Report on the Algorithmic Language Scheme" align="middle" width="32"></a></td>
5492 <td valign="middle" align="left"><a href="#SEC_Contents" title="Table of contents"><img src="button-compass.png" border="0" alt="Contents: Table of Contents" align="middle" width="32"></a></td>
5493 <td valign="middle" align="left"><a href="#Index" title="Index"><img src="button-abc.png" border="0" alt="Index: Alphabetic index of definitions of concepts, keywords, and procedures" align="middle" width="32"></a></td>
5494 </tr></table>
5495 <a name="Characters-1"></a>
5496 <h3 class="subsection">6.3.4 Characters</h3>
5497
5498
5499
5500 <p>Characters are objects that represent printed characters such as
5501 letters and digits.
5502 Characters are written using the notation #\<span class="roman">&lt;character&gt;</span>
5503 or #\<span class="roman">&lt;character name&gt;</span>.
5504 For example:
5505 </p>
5506
5507
5508 <blockquote><dl compact="compact">
5509 <dt> <tt>#\a</tt></dt>
5510 </dl>
5511 </blockquote>
5512 <p>; lower case letter
5513 </p> <tt>#\A</tt>
5514 <p>; upper case letter
5515 </p> <tt>#\(</tt>
5516 <p>; left parenthesis
5517 </p> <tt>#\ </tt>
5518 <p>; the space character
5519 </p> <tt>#\space</tt>
5520 <p>; the preferred way to write a space
5521 </p> <tt>#\newline</tt>
5522 <p>; the newline character
5523 </p>
5524
5525
5526
5527
5528 <p>Case is significant in #\<span class="roman">&lt;character&gt;</span>, but not in
5529 #\<span class="roman">&lt;character name&gt;</span>.
5530 </p>
5531 <p>If <span class="roman">&lt;character&gt;</span> in
5532 #\<span class="roman">&lt;character&gt;</span> is alphabetic, then the character
5533 following <span class="roman">&lt;character&gt;</span> must be a delimiter character such as a
5534 space or parenthesis. This rule resolves the ambiguous case where, for
5535 example, the sequence of characters &ldquo;<tt>#\ space</tt>&rdquo;
5536 could be taken to be either a representation of the space character or a
5537 representation of the character &ldquo;<tt>#\ s</tt>&rdquo; followed
5538 by a representation of the symbol &ldquo;<tt>pace</tt>.&rdquo;
5539 </p>
5540
5541 <p>Characters written in the #\ notation are self-evaluating.
5542 That is, they do not have to be quoted in programs.
5543 </p>
5544 <p>Some of the procedures that operate on characters ignore the
5545 difference between upper case and lower case. The procedures that
5546 ignore case have &ldquo;<tt>-ci</tt>&rdquo; (for &ldquo;case
5547 insensitive&rdquo;) embedded in their names.
5548 </p>
5549
5550
5551 <a name="Definition_of_char?"></a><a name="Procedure_char?"></a><a name="index-char_003f-1"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Procedure_char?">char?</a></b></code><i> obj</i><code>)</code></td><td align="right">procedure</td></tr></table>
5552
5553 <p>Returns <tt>#t</tt> if <var>obj</var> is a character, otherwise returns <tt>#f</tt>.
5554 </p>
5555
5556
5557
5558
5559 <a name="Definition_of_char=?"></a><a name="Procedure_char=?"></a><a name="index-char_003d_003f"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Procedure_char=?">char=?</a></b></code><i> char1 char2</i><code>)</code></td><td align="right">procedure</td></tr></table>
5560 <a name="Definition_of_char%3C?"></a><a name="Procedure_char%3C?"></a><a name="index-char_003c_003f"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Procedure_char%3C?">char&lt;?</a></b></code><i> char1 char2</i><code>)</code></td><td align="right">procedure</td></tr></table>
5561 <a name="Definition_of_char%3E?"></a><a name="Procedure_char%3E?"></a><a name="index-char_003e_003f"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Procedure_char%3E?">char&gt;?</a></b></code><i> char1 char2</i><code>)</code></td><td align="right">procedure</td></tr></table>
5562 <a name="Definition_of_char%3C=?"></a><a name="Procedure_char%3C=?"></a><a name="index-char_003c_003d_003f"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Procedure_char%3C=?">char&lt;=?</a></b></code><i> char1 char2</i><code>)</code></td><td align="right">procedure</td></tr></table>
5563 <a name="Definition_of_char%3E=?"></a><a name="Procedure_char%3E=?"></a><a name="index-char_003e_003d_003f"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Procedure_char%3E=?">char&gt;=?</a></b></code><i> char1 char2</i><code>)</code></td><td align="right">procedure</td></tr></table>
5564
5565
5566
5567 <p>These procedures impose a total ordering on the set of characters. It
5568 is guaranteed that under this ordering:
5569 </p>
5570
5571
5572 <ul>
5573 <li>
5574 The upper case characters are in order. For example, <samp>(char&lt;? #\A #\B)</samp> returns <tt>#t</tt>.
5575 </li><li>
5576 The lower case characters are in order. For example, <samp>(char&lt;? #\a #\b)</samp> returns <tt>#t</tt>.
5577 </li><li>
5578 The digits are in order. For example, <samp>(char&lt;? #\0 #\9)</samp> returns <tt>#t</tt>.
5579 </li><li>
5580 Either all the digits precede all the upper case letters, or vice versa.
5581 </li><li>
5582 Either all the digits precede all the lower case letters, or vice versa.
5583
5584 </li></ul>
5585
5586
5587 <p>Some implementations may generalize these procedures to take more than
5588 two arguments, as with the corresponding numerical predicates.
5589 </p>
5590
5591
5592
5593
5594 <a name="Definition_of_char-ci=?"></a><a name="Library_procedure_char-ci=?"></a><a name="index-char_002dci_003d_003f"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Library_procedure_char-ci=?">char-ci=?</a></b></code><i> char1 char2</i><code>)</code></td><td align="right">library procedure</td></tr></table>
5595 <a name="Definition_of_char-ci%3C?"></a><a name="Library_procedure_char-ci%3C?"></a><a name="index-char_002dci_003c_003f"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Library_procedure_char-ci%3C?">char-ci&lt;?</a></b></code><i> char1 char2</i><code>)</code></td><td align="right">library procedure</td></tr></table>
5596 <a name="Definition_of_char-ci%3E?"></a><a name="Library_procedure_char-ci%3E?"></a><a name="index-char_002dci_003e_003f"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Library_procedure_char-ci%3E?">char-ci&gt;?</a></b></code><i> char1 char2</i><code>)</code></td><td align="right">library procedure</td></tr></table>
5597 <a name="Definition_of_char-ci%3C=?"></a><a name="Library_procedure_char-ci%3C=?"></a><a name="index-char_002dci_003c_003d_003f"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Library_procedure_char-ci%3C=?">char-ci&lt;=?</a></b></code><i> char1 char2</i><code>)</code></td><td align="right">library procedure</td></tr></table>
5598 <a name="Definition_of_char-ci%3E=?"></a><a name="Library_procedure_char-ci%3E=?"></a><a name="index-char_002dci_003e_003d_003f"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Library_procedure_char-ci%3E=?">char-ci&gt;=?</a></b></code><i> char1 char2</i><code>)</code></td><td align="right">library procedure</td></tr></table>
5599
5600
5601 <p>These procedures are similar to <samp>char=?</samp> et cetera, but they treat
5602 upper case and lower case letters as the same. For example, <samp>(char-ci=? #\A #\a)</samp> returns <tt>#t</tt>. Some
5603 implementations may generalize these procedures to take more than two
5604 arguments, as with the corresponding numerical predicates.
5605 </p>
5606
5607
5608
5609
5610 <a name="Definition_of_char-alphabetic?"></a><a name="Library_procedure_char-alphabetic?"></a><a name="index-char_002dalphabetic_003f"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Library_procedure_char-alphabetic?">char-alphabetic?</a></b></code><i> char</i><code>)</code></td><td align="right">library procedure</td></tr></table>
5611 <a name="Definition_of_char-numeric?"></a><a name="Library_procedure_char-numeric?"></a><a name="index-char_002dnumeric_003f"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Library_procedure_char-numeric?">char-numeric?</a></b></code><i> char</i><code>)</code></td><td align="right">library procedure</td></tr></table>
5612 <a name="Definition_of_char-whitespace?"></a><a name="Library_procedure_char-whitespace?"></a><a name="index-char_002dwhitespace_003f"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Library_procedure_char-whitespace?">char-whitespace?</a></b></code><i> char</i><code>)</code></td><td align="right">library procedure</td></tr></table>
5613 <a name="Definition_of_char-upper-case?"></a><a name="Library_procedure_char-upper-case?"></a><a name="index-char_002dupper_002dcase_003f"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Library_procedure_char-upper-case?">char-upper-case?</a></b></code><i> letter</i><code>)</code></td><td align="right">library procedure</td></tr></table>
5614 <a name="Definition_of_char-lower-case?"></a><a name="Library_procedure_char-lower-case?"></a><a name="index-char_002dlower_002dcase_003f"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Library_procedure_char-lower-case?">char-lower-case?</a></b></code><i> letter</i><code>)</code></td><td align="right">library procedure</td></tr></table>
5615
5616 <p>These procedures return <tt>#t</tt> if their arguments are alphabetic,
5617 numeric, whitespace, upper case, or lower case characters, respectively,
5618 otherwise they return <tt>#f</tt>. The following remarks, which are specific to
5619 the ASCII character set, are intended only as a guide: The alphabetic characters
5620 are the 52 upper and lower case letters. The numeric characters are the
5621 ten decimal digits. The whitespace characters are space, tab, line
5622 feed, form feed, and carriage return.
5623 </p>
5624
5625
5626
5627
5628
5629
5630 <a name="Definition_of_char-%3Einteger"></a><a name="Procedure_char-%3Einteger"></a><a name="index-char_002d_003einteger"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Procedure_char-%3Einteger">char-&gt;integer</a></b></code><i> char</i><code>)</code></td><td align="right">procedure</td></tr></table>
5631 <a name="Definition_of_integer-%3Echar"></a><a name="Procedure_integer-%3Echar"></a><a name="index-integer_002d_003echar"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Procedure_integer-%3Echar">integer-&gt;char</a></b></code><i> <var>n</var></i><code>)</code></td><td align="right">procedure</td></tr></table>
5632
5633 <p>Given a character, <samp>char-&gt;integer</samp> returns an exact integer
5634 representation of the character. Given an exact integer that is the image of
5635 a character under <samp>char-&gt;integer</samp>, <samp>integer-&gt;char</samp>
5636 returns that character. These procedures implement order-preserving isomorphisms
5637 between the set of characters under the <code>char&lt;=?</code> ordering and some
5638 <a name="index-char_003c_003d_003f-1"></a>
5639 subset of the integers under the <samp>&lt;=</samp> ordering. That is, if
5640 </p>
5641
5642 <table><tr><td>&nbsp;</td><td><pre class="format">(char&lt;=? <var>a</var> <var>b</var>) &rArr; #t <span class="roman"></span>and (&lt;= <var>x</var> <var>y</var>) &rArr; #t
5643 </pre></td></tr></table>
5644
5645
5646
5647 <p> and <var>x</var> and <var>y</var> are in the domain of
5648 <samp>integer-&gt;char</samp>, then
5649 </p>
5650
5651 <table><tr><td>&nbsp;</td><td><pre class="format">(&lt;= (char-&gt;integer <var>a</var>)
5652 (char-&gt;integer <var>b</var>)) ==&gt; #t
5653
5654 (char&lt;=? (integer-&gt;char <var>x</var>)
5655 (integer-&gt;char <var>y</var>)) ==&gt; #t
5656 </pre></td></tr></table>
5657
5658
5659
5660
5661
5662
5663 <a name="Definition_of_char-upcase"></a><a name="Library_procedure_char-upcase"></a><a name="index-char_002dupcase"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Library_procedure_char-upcase">char-upcase</a></b></code><i> char</i><code>)</code></td><td align="right">library procedure</td></tr></table>
5664 <a name="Definition_of_char-downcase"></a><a name="Library_procedure_char-downcase"></a><a name="index-char_002ddowncase"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Library_procedure_char-downcase">char-downcase</a></b></code><i> char</i><code>)</code></td><td align="right">library procedure</td></tr></table>
5665
5666
5667 <p>These procedures return a character <var>char2</var> such that <samp>(char-ci=? <var>char</var> <var>char2</var>)</samp>. In addition, if <var>char</var> is
5668 alphabetic, then the result of <samp>char-upcase</samp> is upper case and the
5669 result of <samp>char-downcase</samp> is lower case.
5670 </p>
5671
5672
5673
5674 <a name="Strings"></a><hr size="1"><br/><br/><br/>
5675 <table cellpadding="1" cellspacing="1" border="0">
5676 <tr><td valign="middle" align="left"><a href="#Characters" title="Previous section in reading order"><img src="button-left.png" border="0" alt="Back: 6.3.4 Characters" align="middle" width="32"></a></td>
5677 <td valign="middle" align="left"><a href="#Vectors" title="Next section in reading order"><img src="button-right.png" border="0" alt="Forward: 6.3.6 Vectors" align="middle" width="32"></a></td>
5678 <td valign="middle" align="left"> &nbsp; </td>
5679 <td valign="middle" align="left"><a href="#Standard-procedures" title="Beginning of this chapter or previous chapter"><img src="button-left-left.png" border="0" alt="FastBack: 6. Standard procedures" align="middle" width="32"></a></td>
5680 <td valign="middle" align="left"><a href="#Other-data-types" title="Up section"><img src="button-up.png" border="0" alt="Up: 6.3 Other data types" align="middle" width="32"></a></td>
5681 <td valign="middle" align="left"><a href="#Formal-syntax-and-semantics" title="Next chapter"><img src="button-right-right.png" border="0" alt="FastForward: 7. Formal syntax and semantics" align="middle" width="32"></a></td>
5682 <td valign="middle" align="left"><a href="#Top" title="Cover (top) of document"><img src="button-up-arrow.png" border="0" alt="Top: Revised(5) Report on the Algorithmic Language Scheme" align="middle" width="32"></a></td>
5683 <td valign="middle" align="left"><a href="#SEC_Contents" title="Table of contents"><img src="button-compass.png" border="0" alt="Contents: Table of Contents" align="middle" width="32"></a></td>
5684 <td valign="middle" align="left"><a href="#Index" title="Index"><img src="button-abc.png" border="0" alt="Index: Alphabetic index of definitions of concepts, keywords, and procedures" align="middle" width="32"></a></td>
5685 </tr></table>
5686 <a name="Strings-1"></a>
5687 <h3 class="subsection">6.3.5 Strings</h3>
5688
5689
5690
5691 <p>Strings are sequences of characters.
5692 Strings are written as sequences of characters enclosed within doublequotes
5693 (<samp>&quot;</samp>). A doublequote can be written inside a string only by escaping
5694 it with a backslash (\), as in
5695 </p>
5696
5697 <table><tr><td>&nbsp;</td><td><pre class="example">
5698 &quot;The word \&quot;recursion\&quot; has many meanings.&quot;
5699 </pre></td></tr></table>
5700
5701
5702 <p>A backslash can be written inside a string only by escaping it with another
5703 backslash. Scheme does not specify the effect of a backslash within a
5704 string that is not followed by a doublequote or backslash.
5705 </p>
5706 <p>A string constant may continue from one line to the next, but
5707 the exact contents of such a string are unspecified.
5708 </p>
5709 <p>The <em>length</em> of a string is the number of characters that it
5710 contains. This number is an exact, non-negative integer that is fixed when the
5711 string is created. The <em>valid indexes</em> of a string are the
5712 <a name="index-valid-indexes"></a>
5713 exact non-negative integers less than the length of the string. The first
5714 character of a string has index 0, the second has index 1, and so on.
5715 </p>
5716 <p>In phrases such as &ldquo;the characters of <var>string</var> beginning with
5717 index <var>start</var> and ending with index <var>end</var>,&rdquo; it is understood
5718 that the index <var>start</var> is inclusive and the index <var>end</var> is
5719 exclusive. Thus if <var>start</var> and <var>end</var> are the same index, a null
5720 substring is referred to, and if <var>start</var> is zero and <var>end</var> is
5721 the length of <var>string</var>, then the entire string is referred to.
5722 </p>
5723 <p>Some of the procedures that operate on strings ignore the
5724 difference between upper and lower case. The versions that ignore case
5725 have &ldquo;<samp>-ci</samp>&rdquo; (for &ldquo;case insensitive&rdquo;) embedded in their
5726 names.
5727 </p>
5728
5729
5730 <a name="Definition_of_string?"></a><a name="Procedure_string?"></a><a name="index-string_003f-1"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Procedure_string?">string?</a></b></code><i> obj</i><code>)</code></td><td align="right">procedure</td></tr></table>
5731
5732 <p>Returns <tt>#t</tt> if <var>obj</var> is a string, otherwise returns <tt>#f</tt>.
5733 </p>
5734
5735
5736
5737 <a name="Definition_of_make-string"></a><a name="Procedure_make-string"></a><a name="index-make_002dstring"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Procedure_make-string">make-string</a></b></code><i> <var>k</var></i><code>)</code></td><td align="right">procedure</td></tr></table>
5738 <a name="Definition_of_make-string"></a><a name="Procedure_make-string"></a><a name="index-make_002dstring-1"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Procedure_make-string">make-string</a></b></code><i> <var>k</var> char</i><code>)</code></td><td align="right">procedure</td></tr></table>
5739
5740 <p><samp>Make-string</samp> returns a newly allocated string of
5741 length <var>k</var>. If <var>char</var> is given, then all elements of the string
5742 are initialized to <var>char</var>, otherwise the contents of the
5743 <var>string</var> are unspecified.
5744 </p>
5745
5746
5747
5748 <a name="Definition_of_string"></a><a name="Library_procedure_string"></a><a name="index-string"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Library_procedure_string">string</a></b></code><i> char &hellip;</i><code>)</code></td><td align="right">library procedure</td></tr></table>
5749
5750 <p>Returns a newly allocated string composed of the arguments.
5751 </p>
5752
5753
5754
5755 <a name="Definition_of_string-length"></a><a name="Procedure_string-length"></a><a name="index-string_002dlength-1"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Procedure_string-length">string-length</a></b></code><i> string</i><code>)</code></td><td align="right">procedure</td></tr></table>
5756
5757 <p>Returns the number of characters in the given <var>string</var>.
5758 </p>
5759
5760
5761
5762 <a name="Definition_of_string-ref"></a><a name="Procedure_string-ref"></a><a name="index-string_002dref"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Procedure_string-ref">string-ref</a></b></code><i> string <var>k</var></i><code>)</code></td><td align="right">procedure</td></tr></table>
5763
5764 <p><var>k</var> must be a valid index of <var>string</var>.
5765 <samp>String-ref</samp> returns character <var>k</var> of <var>string</var> using zero-origin indexing.
5766 </p>
5767
5768
5769
5770 <a name="Definition_of_string-set!"></a><a name="Procedure_string-set!"></a><a name="index-string_002dset_0021-1"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Procedure_string-set!">string-set!</a></b></code><i> string k char</i><code>)</code></td><td align="right">procedure</td></tr></table>
5771
5772
5773 <p><var>k</var> must be a valid index of <var>string</var>
5774 .
5775 <samp>String-set!</samp> stores <var>char</var> in element <var>k</var> of <var>string</var>
5776 and returns an unspecified value.
5777 </p>
5778
5779 <table><tr><td>&nbsp;</td><td><pre class="format">(define (f) (make-string 3 #\*))
5780 (define (g) &quot;***&quot;)
5781 (string-set! (f) 0 #\?) ==&gt; <em>unspecified</em>
5782 (string-set! (g) 0 #\?) ==&gt; <em>error</em>
5783 (string-set! (symbol-&gt;string 'immutable)
5784 0
5785 #\?) ==&gt; <em>error</em>
5786 </pre></td></tr></table>
5787
5788
5789
5790
5791
5792
5793 <a name="Definition_of_string=?"></a><a name="Library_procedure_string=?"></a><a name="index-string_003d_003f"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Library_procedure_string=?">string=?</a></b></code><i> string1 string2</i><code>)</code></td><td align="right">library procedure</td></tr></table>
5794 <a name="Definition_of_string-ci=?"></a><a name="Library_procedure_string-ci=?"></a><a name="index-string_002dci_003d_003f"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Library_procedure_string-ci=?">string-ci=?</a></b></code><i> string1 string2</i><code>)</code></td><td align="right">library procedure</td></tr></table>
5795
5796 <p>Returns <tt>#t</tt> if the two strings are the same length and contain the same
5797 characters in the same positions, otherwise returns <tt>#f</tt>.
5798 <samp>String-ci=?</samp> treats
5799 upper and lower case letters as though they were the same character, but
5800 <samp>string=?</samp> treats upper and lower case as distinct characters.
5801 </p>
5802
5803
5804
5805
5806 <a name="Definition_of_string%3C?"></a><a name="Library_procedure_string%3C?"></a><a name="index-string_003c_003f"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Library_procedure_string%3C?">string&lt;?</a></b></code><i> string1 string2</i><code>)</code></td><td align="right">library procedure</td></tr></table>
5807 <a name="Definition_of_string%3E?"></a><a name="Library_procedure_string%3E?"></a><a name="index-string_003e_003f"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Library_procedure_string%3E?">string&gt;?</a></b></code><i> string1 string2</i><code>)</code></td><td align="right">library procedure</td></tr></table>
5808 <a name="Definition_of_string%3C=?"></a><a name="Library_procedure_string%3C=?"></a><a name="index-string_003c_003d_003f"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Library_procedure_string%3C=?">string&lt;=?</a></b></code><i> string1 string2</i><code>)</code></td><td align="right">library procedure</td></tr></table>
5809 <a name="Definition_of_string%3E=?"></a><a name="Library_procedure_string%3E=?"></a><a name="index-string_003e_003d_003f"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Library_procedure_string%3E=?">string&gt;=?</a></b></code><i> string1 string2</i><code>)</code></td><td align="right">library procedure</td></tr></table>
5810 <a name="Definition_of_string-ci%3C?"></a><a name="Library_procedure_string-ci%3C?"></a><a name="index-string_002dci_003c_003f"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Library_procedure_string-ci%3C?">string-ci&lt;?</a></b></code><i> string1 string2</i><code>)</code></td><td align="right">library procedure</td></tr></table>
5811 <a name="Definition_of_string-ci%3E?"></a><a name="Library_procedure_string-ci%3E?"></a><a name="index-string_002dci_003e_003f"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Library_procedure_string-ci%3E?">string-ci&gt;?</a></b></code><i> string1 string2</i><code>)</code></td><td align="right">library procedure</td></tr></table>
5812 <a name="Definition_of_string-ci%3C=?"></a><a name="Library_procedure_string-ci%3C=?"></a><a name="index-string_002dci_003c_003d_003f"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Library_procedure_string-ci%3C=?">string-ci&lt;=?</a></b></code><i> string1 string2</i><code>)</code></td><td align="right">library procedure</td></tr></table>
5813 <a name="Definition_of_string-ci%3E=?"></a><a name="Library_procedure_string-ci%3E=?"></a><a name="index-string_002dci_003e_003d_003f"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Library_procedure_string-ci%3E=?">string-ci&gt;=?</a></b></code><i> string1 string2</i><code>)</code></td><td align="right">library procedure</td></tr></table>
5814
5815 <p>These procedures are the lexicographic extensions to strings of the
5816 corresponding orderings on characters. For example, <samp>string&lt;?</samp> is
5817 the lexicographic ordering on strings induced by the ordering
5818 <samp>char&lt;?</samp> on characters. If two strings differ in length but
5819 are the same up to the length of the shorter string, the shorter string
5820 is considered to be lexicographically less than the longer string.
5821 </p>
5822 <p>Implementations may generalize these and the <samp>string=?</samp> and
5823 <samp>string-ci=?</samp> procedures to take more than two arguments, as with
5824 the corresponding numerical predicates.
5825 </p>
5826
5827
5828
5829
5830 <a name="Definition_of_substring"></a><a name="Library_procedure_substring"></a><a name="index-substring"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Library_procedure_substring">substring</a></b></code><i> string start end</i><code>)</code></td><td align="right">library procedure</td></tr></table>
5831
5832 <p><var>String</var> must be a string, and <var>start</var> and <var>end</var>
5833 must be exact integers satisfying
5834 </p>
5835
5836 <p align="center"> 0 &lt;= <var>start</var> &lt;= <var>end</var> &lt;= <tt>(string-length <var>string</var>)<span class="roman">.</span></tt>
5837 </p>
5838 <p><samp>Substring</samp> returns a newly allocated string formed from the characters of
5839 <var>string</var> beginning with index <var>start</var> (inclusive) and ending with index
5840 <var>end</var> (exclusive).
5841 </p>
5842
5843
5844
5845 <a name="Definition_of_string-append"></a><a name="Library_procedure_string-append"></a><a name="index-string_002dappend"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Library_procedure_string-append">string-append</a></b></code><i> <var>string</var> &hellip;</i><code>)</code></td><td align="right">library procedure</td></tr></table>
5846
5847 <p>Returns a newly allocated string whose characters form the concatenation of the
5848 given strings.
5849 </p>
5850
5851
5852
5853
5854 <a name="Definition_of_string-%3Elist"></a><a name="Library_procedure_string-%3Elist"></a><a name="index-string_002d_003elist"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Library_procedure_string-%3Elist">string-&gt;list</a></b></code><i> string</i><code>)</code></td><td align="right">library procedure</td></tr></table>
5855 <a name="Definition_of_list-%3Estring"></a><a name="Library_procedure_list-%3Estring"></a><a name="index-list_002d_003estring"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Library_procedure_list-%3Estring">list-&gt;string</a></b></code><i> list</i><code>)</code></td><td align="right">library procedure</td></tr></table>
5856
5857 <p><samp>String-&gt;list</samp> returns a newly allocated list of the
5858 characters that make up the given string. <samp>List-&gt;string</samp>
5859 returns a newly allocated string formed from the characters in the list
5860 <var>list</var>, which must be a list of characters. <samp>String-&gt;list</samp>
5861 and <samp>list-&gt;string</samp> are
5862 inverses so far as <samp>equal?</samp> is concerned.
5863 </p>
5864
5865
5866
5867
5868 <a name="Definition_of_string-copy"></a><a name="Library_procedure_string-copy"></a><a name="index-string_002dcopy"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Library_procedure_string-copy">string-copy</a></b></code><i> string</i><code>)</code></td><td align="right">library procedure</td></tr></table>
5869
5870 <p>Returns a newly allocated copy of the given <var>string</var>.
5871 </p>
5872
5873
5874
5875
5876 <a name="Definition_of_string-fill!"></a><a name="Library_procedure_string-fill!"></a><a name="index-string_002dfill_0021"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Library_procedure_string-fill!">string-fill!</a></b></code><i> string char</i><code>)</code></td><td align="right">library procedure</td></tr></table>
5877
5878 <p>Stores <var>char</var> in every element of the given <var>string</var> and returns an
5879 unspecified value.
5880 </p>
5881
5882
5883
5884 <a name="Vectors"></a><hr size="1"><br/><br/><br/>
5885 <table cellpadding="1" cellspacing="1" border="0">
5886 <tr><td valign="middle" align="left"><a href="#Strings" title="Previous section in reading order"><img src="button-left.png" border="0" alt="Back: 6.3.5 Strings" align="middle" width="32"></a></td>
5887 <td valign="middle" align="left"><a href="#Control-features" title="Next section in reading order"><img src="button-right.png" border="0" alt="Forward: 6.4 Control features" align="middle" width="32"></a></td>
5888 <td valign="middle" align="left"> &nbsp; </td>
5889 <td valign="middle" align="left"><a href="#Standard-procedures" title="Beginning of this chapter or previous chapter"><img src="button-left-left.png" border="0" alt="FastBack: 6. Standard procedures" align="middle" width="32"></a></td>
5890 <td valign="middle" align="left"><a href="#Other-data-types" title="Up section"><img src="button-up.png" border="0" alt="Up: 6.3 Other data types" align="middle" width="32"></a></td>
5891 <td valign="middle" align="left"><a href="#Formal-syntax-and-semantics" title="Next chapter"><img src="button-right-right.png" border="0" alt="FastForward: 7. Formal syntax and semantics" align="middle" width="32"></a></td>
5892 <td valign="middle" align="left"><a href="#Top" title="Cover (top) of document"><img src="button-up-arrow.png" border="0" alt="Top: Revised(5) Report on the Algorithmic Language Scheme" align="middle" width="32"></a></td>
5893 <td valign="middle" align="left"><a href="#SEC_Contents" title="Table of contents"><img src="button-compass.png" border="0" alt="Contents: Table of Contents" align="middle" width="32"></a></td>
5894 <td valign="middle" align="left"><a href="#Index" title="Index"><img src="button-abc.png" border="0" alt="Index: Alphabetic index of definitions of concepts, keywords, and procedures" align="middle" width="32"></a></td>
5895 </tr></table>
5896 <a name="Vectors-1"></a>
5897 <h3 class="subsection">6.3.6 Vectors</h3>
5898
5899
5900
5901 <p>Vectors are heterogeneous structures whose elements are indexed
5902 by integers. A vector typically occupies less space than a list
5903 of the same length, and the average time required to access a randomly
5904 chosen element is typically less for the vector than for the list.
5905 </p>
5906 <p>The <em>length</em> of a vector is the number of elements that it
5907 contains. This number is a non-negative integer that is fixed when the
5908 vector is created. The <em>valid indexes</em> of a
5909 <a name="index-valid-indexes-1"></a>
5910 vector are the exact non-negative integers less than the length of the
5911 vector. The first element in a vector is indexed by zero, and the last
5912 element is indexed by one less than the length of the vector.
5913 </p>
5914 <p>Vectors are written using the notation <tt>#(<var>obj</var> &hellip;)</tt>.
5915 For example, a vector of length 3 containing the number zero in element
5916 0, the list <samp>(2 2 2 2)</samp> in element 1, and the string <samp>&quot;Anna&quot;</samp> in
5917 element 2 can be written as following:
5918 </p>
5919
5920 <table><tr><td>&nbsp;</td><td><pre class="example">
5921 #(0 (2 2 2 2) &quot;Anna&quot;)
5922 </pre></td></tr></table>
5923
5924
5925 <p>Note that this is the external representation of a vector, not an
5926 expression evaluating to a vector. Like list constants, vector
5927 constants must be quoted:
5928 </p>
5929
5930 <table><tr><td>&nbsp;</td><td><pre class="example">
5931 '#(0 (2 2 2 2) &quot;Anna&quot;)
5932 ==&gt; #(0 (2 2 2 2) &quot;Anna&quot;)
5933
5934 </pre></td></tr></table>
5935
5936
5937
5938
5939
5940
5941 <a name="Definition_of_vector?"></a><a name="Procedure_vector?"></a><a name="index-vector_003f-1"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Procedure_vector?">vector?</a></b></code><i> obj</i><code>)</code></td><td align="right">procedure</td></tr></table>
5942
5943 <p>Returns <tt>#t</tt> if <var>obj</var> is a vector, otherwise returns <tt>#f</tt>.
5944 </p>
5945
5946
5947
5948 <a name="Definition_of_make-vector"></a><a name="Procedure_make-vector"></a><a name="index-make_002dvector-1"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Procedure_make-vector">make-vector</a></b></code><i> k</i><code>)</code></td><td align="right">procedure</td></tr></table>
5949 <a name="Definition_of_make-vector"></a><a name="Procedure_make-vector"></a><a name="index-make_002dvector-2"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Procedure_make-vector">make-vector</a></b></code><i> k fill</i><code>)</code></td><td align="right">procedure</td></tr></table>
5950
5951 <p>Returns a newly allocated vector of <var>k</var> elements. If a second
5952 argument is given, then each element is initialized to <var>fill</var>.
5953 Otherwise the initial contents of each element is unspecified.
5954 </p>
5955
5956
5957
5958
5959 <a name="Definition_of_vector"></a><a name="Library_procedure_vector"></a><a name="index-vector"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Library_procedure_vector">vector</a></b></code><i> obj &hellip;</i><code>)</code></td><td align="right">library procedure</td></tr></table>
5960
5961 <p>Returns a newly allocated vector whose elements contain the given
5962 arguments. Analogous to <samp>list</samp>.
5963 </p>
5964
5965 <table><tr><td>&nbsp;</td><td><pre class="format">(vector 'a 'b 'c) ==&gt; #(a b c)
5966 </pre></td></tr></table>
5967
5968
5969
5970
5971
5972 <a name="Definition_of_vector-length"></a><a name="Procedure_vector-length"></a><a name="index-vector_002dlength-1"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Procedure_vector-length">vector-length</a></b></code><i> vector</i><code>)</code></td><td align="right">procedure</td></tr></table>
5973
5974 <p>Returns the number of elements in <var>vector</var> as an exact integer.
5975 </p>
5976
5977
5978
5979 <a name="Definition_of_vector-ref"></a><a name="Procedure_vector-ref"></a><a name="index-vector_002dref-1"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Procedure_vector-ref">vector-ref</a></b></code><i> vector k</i><code>)</code></td><td align="right">procedure</td></tr></table>
5980
5981 <p><var>k</var> must be a valid index of <var>vector</var>.
5982 <samp>Vector-ref</samp> returns the contents of element <var>k</var> of
5983 <var>vector</var>.
5984 </p>
5985
5986 <table><tr><td>&nbsp;</td><td><pre class="format">(vector-ref '#(1 1 2 3 5 8 13 21)
5987 5)
5988 ==&gt; 8
5989 (vector-ref '#(1 1 2 3 5 8 13 21)
5990 (let ((i (round (* 2 (acos -1)))))
5991 (if (inexact? i)
5992 (inexact-&gt;exact i)
5993 i)))
5994 ==&gt; 13
5995 </pre></td></tr></table>
5996
5997
5998
5999
6000
6001 <a name="Definition_of_vector-set!"></a><a name="Procedure_vector-set!"></a><a name="index-vector_002dset_0021"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Procedure_vector-set!">vector-set!</a></b></code><i> vector k obj</i><code>)</code></td><td align="right">procedure</td></tr></table>
6002
6003 <p><var>k</var> must be a valid index of <var>vector</var>.
6004 <samp>Vector-set!</samp> stores <var>obj</var> in element <var>k</var> of <var>vector</var>.
6005 The value returned by <samp>vector-set!</samp> is unspecified.
6006 </p>
6007
6008 <table><tr><td>&nbsp;</td><td><pre class="format">(let ((vec (vector 0 '(2 2 2 2) &quot;Anna&quot;)))
6009 (vector-set! vec 1 '(&quot;Sue&quot; &quot;Sue&quot;))
6010 vec)
6011 ==&gt; #(0 (&quot;Sue&quot; &quot;Sue&quot;) &quot;Anna&quot;)
6012
6013 (vector-set! '#(0 1 2) 1 &quot;doe&quot;)
6014 ==&gt; <em>error</em> ; constant vector
6015 </pre></td></tr></table>
6016
6017
6018
6019
6020
6021 <a name="Definition_of_vector-%3Elist"></a><a name="Library_procedure_vector-%3Elist"></a><a name="index-vector_002d_003elist"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Library_procedure_vector-%3Elist">vector-&gt;list</a></b></code><i> vector</i><code>)</code></td><td align="right">library procedure</td></tr></table>
6022 <a name="Definition_of_list-%3Evector"></a><a name="Library_procedure_list-%3Evector"></a><a name="index-list_002d_003evector"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Library_procedure_list-%3Evector">list-&gt;vector</a></b></code><i> list</i><code>)</code></td><td align="right">library procedure</td></tr></table>
6023
6024 <p><samp>Vector-&gt;list</samp> returns a newly allocated list of the objects contained
6025 in the elements of <var>vector</var>. <samp>List-&gt;vector</samp> returns a newly
6026 created vector initialized to the elements of the list <var>list</var>.
6027 </p>
6028
6029 <table><tr><td>&nbsp;</td><td><pre class="format">(vector-&gt;list '#(dah dah didah))
6030 ==&gt; (dah dah didah)
6031 (list-&gt;vector '(dididit dah))
6032 ==&gt; #(dididit dah)
6033 </pre></td></tr></table>
6034
6035
6036
6037
6038
6039 <a name="Definition_of_vector-fill!"></a><a name="Library_procedure_vector-fill!"></a><a name="index-vector_002dfill_0021"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Library_procedure_vector-fill!">vector-fill!</a></b></code><i> vector fill</i><code>)</code></td><td align="right">library procedure</td></tr></table>
6040
6041 <p>Stores <var>fill</var> in every element of <var>vector</var>.
6042 The value returned by <samp>vector-fill!</samp> is unspecified.
6043 </p>
6044
6045
6046
6047 <a name="Control-features"></a><hr size="1"><br/><br/><br/>
6048 <table cellpadding="1" cellspacing="1" border="0">
6049 <tr><td valign="middle" align="left"><a href="#Vectors" title="Previous section in reading order"><img src="button-left.png" border="0" alt="Back: 6.3.6 Vectors" align="middle" width="32"></a></td>
6050 <td valign="middle" align="left"><a href="#Eval" title="Next section in reading order"><img src="button-right.png" border="0" alt="Forward: 6.5 Eval" align="middle" width="32"></a></td>
6051 <td valign="middle" align="left"> &nbsp; </td>
6052 <td valign="middle" align="left"><a href="#Standard-procedures" title="Beginning of this chapter or previous chapter"><img src="button-left-left.png" border="0" alt="FastBack: 6. Standard procedures" align="middle" width="32"></a></td>
6053 <td valign="middle" align="left"><a href="#Standard-procedures" title="Up section"><img src="button-up.png" border="0" alt="Up: 6. Standard procedures" align="middle" width="32"></a></td>
6054 <td valign="middle" align="left"><a href="#Formal-syntax-and-semantics" title="Next chapter"><img src="button-right-right.png" border="0" alt="FastForward: 7. Formal syntax and semantics" align="middle" width="32"></a></td>
6055 <td valign="middle" align="left"><a href="#Top" title="Cover (top) of document"><img src="button-up-arrow.png" border="0" alt="Top: Revised(5) Report on the Algorithmic Language Scheme" align="middle" width="32"></a></td>
6056 <td valign="middle" align="left"><a href="#SEC_Contents" title="Table of contents"><img src="button-compass.png" border="0" alt="Contents: Table of Contents" align="middle" width="32"></a></td>
6057 <td valign="middle" align="left"><a href="#Index" title="Index"><img src="button-abc.png" border="0" alt="Index: Alphabetic index of definitions of concepts, keywords, and procedures" align="middle" width="32"></a></td>
6058 </tr></table>
6059 <a name="Control-features-1"></a>
6060 <h2 class="section">6.4 Control features</h2>
6061
6062
6063
6064
6065 <p>This chapter describes various primitive procedures which control the
6066 flow of program execution in special ways.
6067 The <samp>procedure?</samp> predicate is also described here.
6068 </p>
6069
6070
6071
6072 <a name="Definition_of_procedure?"></a><a name="Procedure_procedure?"></a><a name="index-procedure_003f-1"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Procedure_procedure?">procedure?</a></b></code><i> obj</i><code>)</code></td><td align="right">procedure</td></tr></table>
6073
6074 <p>Returns <tt>#t</tt> if <var>obj</var> is a procedure, otherwise returns <tt>#f</tt>.
6075 </p>
6076
6077 <table><tr><td>&nbsp;</td><td><pre class="format">(procedure? car) ==&gt; #t
6078 (procedure? 'car) ==&gt; #f
6079 (procedure? (lambda (x) (* x x)))
6080 ==&gt; #t
6081 (procedure? '(lambda (x) (* x x)))
6082 ==&gt; #f
6083 (call-with-current-continuation procedure?)
6084 ==&gt; #t
6085 </pre></td></tr></table>
6086
6087
6088
6089
6090
6091
6092 <a name="Definition_of_apply"></a><a name="Procedure_apply"></a><a name="index-apply-1"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Procedure_apply">apply</a></b></code><i> proc arg1 &hellip; args</i><code>)</code></td><td align="right">procedure</td></tr></table>
6093
6094 <p><var>Proc</var> must be a procedure and <var>args</var> must be a list.
6095 Calls <var>proc</var> with the elements of the list
6096 <samp>(append (list <var>arg1</var> &hellip;) <var>args</var>)</samp> as the actual
6097 arguments.
6098 </p>
6099
6100 <table><tr><td>&nbsp;</td><td><pre class="format">(apply + (list 3 4)) ==&gt; 7
6101
6102 (define compose
6103 (lambda (f g)
6104 (lambda args
6105 (f (apply g args)))))
6106
6107 ((compose sqrt *) 12 75) ==&gt; 30
6108 </pre></td></tr></table>
6109
6110
6111
6112
6113
6114 <a name="Definition_of_map"></a><a name="Library_procedure_map"></a><a name="index-map"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Library_procedure_map">map</a></b></code><i> proc list1 list2 &hellip;</i><code>)</code></td><td align="right">library procedure</td></tr></table>
6115
6116 <p>The <var>list</var>s must be lists, and <var>proc</var> must be a
6117 procedure taking as many arguments as there are <i>list</i>s
6118 and returning a single value. If more
6119 than one <var>list</var> is given, then they must all be the same length.
6120 <samp>Map</samp> applies <var>proc</var> element-wise to the elements of the
6121 <var>list</var>s and returns a list of the results, in order.
6122 The dynamic order in which <var>proc</var> is applied to the elements of the
6123 <var>list</var>s is unspecified.
6124 </p>
6125
6126 <table><tr><td>&nbsp;</td><td><pre class="format">(map cadr '((a b) (d e) (g h)))
6127 ==&gt; (b e h)
6128
6129 (map (lambda (n) (expt n n))
6130 '(1 2 3 4 5))
6131 ==&gt; (1 4 27 256 3125)
6132
6133 (map + '(1 2 3) '(4 5 6)) ==&gt; (5 7 9)
6134
6135 (let ((count 0))
6136 (map (lambda (ignored)
6137 (set! count (+ count 1))
6138 count)
6139 '(a b))) ==&gt; (1 2) <var>or</var> (2 1)
6140 </pre></td></tr></table>
6141
6142
6143
6144
6145
6146
6147 <a name="Definition_of_for-each"></a><a name="Library_procedure_for-each"></a><a name="index-for_002deach"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Library_procedure_for-each">for-each</a></b></code><i> proc list1 list2 &hellip;</i><code>)</code></td><td align="right">library procedure</td></tr></table>
6148
6149 <p>The arguments to <samp>for-each</samp> are like the arguments to <samp>map</samp>, but
6150 <samp>for-each</samp> calls <var>proc</var> for its side effects rather than for its
6151 values. Unlike <samp>map</samp>, <samp>for-each</samp> is guaranteed to call <var>proc</var> on
6152 the elements of the <var>list</var>s in order from the first element(s) to the
6153 last, and the value returned by <samp>for-each</samp> is unspecified.
6154 </p>
6155
6156 <table><tr><td>&nbsp;</td><td><pre class="format">(let ((v (make-vector 5)))
6157 (for-each (lambda (i)
6158 (vector-set! v i (* i i)))
6159 '(0 1 2 3 4))
6160 v) ==&gt; #(0 1 4 9 16)
6161 </pre></td></tr></table>
6162
6163
6164
6165
6166
6167
6168 <a name="Definition_of_force"></a><a name="Library_procedure_force"></a><a name="index-force-1"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Library_procedure_force">force</a></b></code><i> promise</i><code>)</code></td><td align="right">library procedure</td></tr></table>
6169
6170 <p>Forces the value of <var>promise</var> (see <code>delay</code>,
6171 <a name="index-delay-1"></a>
6172 section see section <a href="#Delayed-evaluation">Delayed evaluation</a>). If no value has been computed for
6173 <a name="index-promise-1"></a>
6174 the promise, then a value is computed and returned. The value of the
6175 promise is cached (or &ldquo;memoized&rdquo;) so that if it is forced a second
6176 time, the previously computed value is returned.
6177 </p>
6178
6179 <table><tr><td>&nbsp;</td><td><pre class="format">(force (delay (+ 1 2))) ==&gt; 3
6180 (let ((p (delay (+ 1 2))))
6181 (list (force p) (force p)))
6182 ==&gt; (3 3)
6183
6184 (define a-stream
6185 (letrec ((next
6186 (lambda (n)
6187 (cons n (delay (next (+ n 1)))))))
6188 (next 0)))
6189 (define head car)
6190 (define tail
6191 (lambda (stream) (force (cdr stream))))
6192
6193 (head (tail (tail a-stream)))
6194 ==&gt; 2
6195 </pre></td></tr></table>
6196
6197
6198 <p><samp>Force</samp> and <samp>delay</samp> are mainly intended for programs written in
6199 functional style. The following examples should not be considered to
6200 illustrate good programming style, but they illustrate the property that
6201 only one value is computed for a promise, no matter how many times it is
6202 forced.
6203 </p>
6204
6205 <table><tr><td>&nbsp;</td><td><pre class="format">(define count 0)
6206 (define p
6207 (delay (begin (set! count (+ count 1))
6208 (if (&gt; count x)
6209 count
6210 (force p)))))
6211 (define x 5)
6212 p ==&gt; <i></i>a promise
6213 (force p) ==&gt; 6
6214 p ==&gt; <i></i>a promise, still
6215 (begin (set! x 10)
6216 (force p)) ==&gt; 6
6217 </pre></td></tr></table>
6218
6219
6220 <p>Here is a possible implementation of <samp>delay</samp> and <samp>force</samp>.
6221 Promises are implemented here as procedures of no arguments,
6222 and <samp>force</samp> simply calls its argument:
6223 </p>
6224
6225 <table><tr><td>&nbsp;</td><td><pre class="format">(define force
6226 (lambda (object)
6227 (object)))
6228 </pre></td></tr></table>
6229
6230
6231 <p>We define the expression
6232 </p>
6233
6234 <table><tr><td>&nbsp;</td><td><pre class="format">(delay <span class="roman">&lt;expression&gt;</span>)
6235 </pre></td></tr></table>
6236
6237
6238 <p>to have the same meaning as the procedure call
6239 </p>
6240
6241 <table><tr><td>&nbsp;</td><td><pre class="format">(make-promise (lambda () <span class="roman">&lt;expression&gt;</span>))<span class="roman"></span>
6242 </pre></td></tr></table>
6243
6244
6245 <p>as follows
6246 </p>
6247
6248 <table><tr><td>&nbsp;</td><td><pre class="format">(define-syntax delay
6249 (syntax-rules ()
6250 ((delay expression)
6251 (make-promise (lambda () expression))))),
6252 </pre></td></tr></table>
6253
6254
6255 <p>where <samp>make-promise</samp> is defined as follows:
6256 </p>
6257
6258
6259 <table><tr><td>&nbsp;</td><td><pre class="format">(define make-promise
6260 (lambda (proc)
6261 (let ((result-ready? #f)
6262 (result #f))
6263 (lambda ()
6264 (if result-ready?
6265 result
6266 (let ((x (proc)))
6267 (if result-ready?
6268 result
6269 (begin (set! result-ready? #t)
6270 (set! result x)
6271 result))))))))
6272 </pre></td></tr></table>
6273
6274
6275
6276 <blockquote><p><em>Rationale:</em>
6277 A promise may refer to its own value, as in the last example above.
6278 Forcing such a promise may cause the promise to be forced a second time
6279 before the value of the first force has been computed.
6280 This complicates the definition of <samp>make-promise</samp>.
6281 </p></blockquote>
6282
6283
6284 <p>Various extensions to this semantics of <samp>delay</samp> and <samp>force</samp>
6285 are supported in some implementations:
6286 </p>
6287
6288
6289 <ul>
6290 <li>
6291 Calling <samp>force</samp> on an object that is not a promise may simply
6292 return the object.
6293
6294 </li><li>
6295 It may be the case that there is no means by which a promise can be
6296 operationally distinguished from its forced value. That is, expressions
6297 like the following may evaluate to either <tt>#t</tt> or to <tt>#f</tt>,
6298 depending on the implementation:
6299
6300
6301 <table><tr><td>&nbsp;</td><td><pre class="format">(eqv? (delay 1) 1) ==&gt; <em>unspecified</em>
6302 (pair? (delay (cons 1 2))) ==&gt; <em>unspecified</em>
6303 </pre></td></tr></table>
6304
6305
6306 </li><li>
6307 Some implementations may implement &ldquo;implicit forcing,&rdquo; where
6308 the value of a promise is forced by primitive procedures like <samp>cdr</samp>
6309 and <samp>+</samp>:
6310
6311
6312 <table><tr><td>&nbsp;</td><td><pre class="format">(+ (delay (* 3 7)) 13) ==&gt; 34
6313 </pre></td></tr></table>
6314
6315
6316 </li></ul>
6317
6318
6319
6320
6321 <a name="Definition_of_call-with-current-continuation"></a><a name="Procedure_call-with-current-continuation"></a><a name="index-call_002dwith_002dcurrent_002dcontinuation-1"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Procedure_call-with-current-continuation">call-with-current-continuation</a></b></code><i> proc</i><code>)</code></td><td align="right">procedure</td></tr></table>
6322
6323 <p> <var>Proc</var> must be a procedure of one
6324 argument. The procedure <samp>call-with-current-continuation</samp> packages
6325 up the current continuation (see the rationale below) as an &ldquo;escape
6326 procedure&rdquo; and passes it as an argument to
6327 <a name="index-escape-procedure"></a>
6328 <var>proc</var>. The escape procedure is a Scheme procedure that, if it is
6329 later called, will abandon whatever continuation is in effect at that later
6330 time and will instead use the continuation that was in effect
6331 when the escape procedure was created. Calling the escape procedure
6332 may cause the invocation of <var>before</var> and <var>after</var> thunks installed using
6333 <code>dynamic-wind</code>.
6334 <a name="index-dynamic_002dwind"></a>
6335 </p>
6336 <p>The escape procedure accepts the same number of arguments as the continuation to
6337 the original call to <tt>call-with-current-continuation</tt>.
6338 Except for continuations created by the <samp>call-with-values</samp>
6339 procedure, all continuations take exactly one value. The
6340 effect of passing no value or more than one value to continuations
6341 that were not created by <tt>call-with-values</tt> is unspecified.
6342 </p>
6343 <p>The escape procedure that is passed to <var>proc</var> has
6344 unlimited extent just like any other procedure in Scheme. It may be stored
6345 in variables or data structures and may be called as many times as desired.
6346 </p>
6347 <p>The following examples show only the most common ways in which
6348 <samp>call-with-current-continuation</samp> is used. If all real uses were as
6349 simple as these examples, there would be no need for a procedure with
6350 the power of <samp>call-with-current-continuation</samp>.
6351 </p>
6352
6353 <table><tr><td>&nbsp;</td><td><pre class="format">(call-with-current-continuation
6354 (lambda (exit)
6355 (for-each (lambda (x)
6356 (if (negative? x)
6357 (exit x)))
6358 '(54 0 37 -3 245 19))
6359 #t)) ==&gt; -3
6360
6361 (define list-length
6362 (lambda (obj)
6363 (call-with-current-continuation
6364 (lambda (return)
6365 (letrec ((r
6366 (lambda (obj)
6367 (cond ((null? obj) 0)
6368 ((pair? obj)
6369 (+ (r (cdr obj)) 1))
6370 (else (return #f))))))
6371 (r obj))))))
6372
6373 (list-length '(1 2 3 4)) ==&gt; 4
6374
6375 (list-length '(a b . c)) ==&gt; #f
6376 </pre></td></tr></table>
6377
6378
6379
6380 <blockquote><p><em>Rationale:</em>
6381 </p>
6382 <p>A common use of <samp>call-with-current-continuation</samp> is for
6383 structured, non-local exits from loops or procedure bodies, but in fact
6384 <samp>call-with-current-continuation</samp> is extremely useful for implementing a
6385 wide variety of advanced control structures.
6386 </p>
6387 <p>Whenever a Scheme expression is evaluated there is a
6388 <em>continuation</em> wanting the result of the expression. The continuation
6389 <a name="index-continuation"></a>
6390 represents an entire (default) future for the computation. If the expression is
6391 evaluated at top level, for example, then the continuation might take the
6392 result, print it on the screen, prompt for the next input, evaluate it, and
6393 so on forever. Most of the time the continuation includes actions
6394 specified by user code, as in a continuation that will take the result,
6395 multiply it by the value stored in a local variable, add seven, and give
6396 the answer to the top level continuation to be printed. Normally these
6397 ubiquitous continuations are hidden behind the scenes and programmers do not
6398 think much about them. On rare occasions, however, a programmer may
6399 need to deal with continuations explicitly.
6400 <samp>Call-with-current-continuation</samp> allows Scheme programmers to do
6401 that by creating a procedure that acts just like the current
6402 continuation.
6403 </p>
6404 <p>Most programming languages incorporate one or more special-purpose
6405 escape constructs with names like <tt>exit</tt>, <samp>return</samp>, or
6406 even <tt>goto</tt>. In 1965, however, Peter Landin [Landin65]
6407 invented a general purpose escape operator called the J-operator. John
6408 Reynolds [Reynolds72] described a simpler but equally powerful
6409 construct in 1972. The <samp>catch</samp> special form described by Sussman
6410 and Steele in the 1975 report on Scheme is exactly the same as
6411 Reynolds's construct, though its name came from a less general construct
6412 in MacLisp. Several Scheme implementors noticed that the full power of the
6413 <code>catch</code> construct could be provided by a procedure instead of by a
6414 <a name="index-catch"></a>
6415 special syntactic construct, and the name
6416 <samp>call-with-current-continuation</samp> was coined in 1982. This name is
6417 descriptive, but opinions differ on the merits of such a long name, and
6418 some people use the name <code>call/cc</code> instead.
6419 <a name="index-call_002fcc"></a>
6420 </p></blockquote>
6421
6422
6423
6424
6425
6426 <a name="Definition_of_values"></a><a name="Procedure_values"></a><a name="index-values-1"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Procedure_values">values</a></b></code><i> obj &hellip;</i><code>)</code></td><td align="right">procedure</td></tr></table>
6427
6428 <p>Delivers all of its arguments to its continuation.
6429 Except for continuations created by the <code>call-with-values</code>
6430 <a name="index-call_002dwith_002dvalues-1"></a>
6431 procedure, all continuations take exactly one value.
6432 <tt>Values</tt> might be defined as follows:
6433 </p>
6434 <table><tr><td>&nbsp;</td><td><pre class="format">(define (values . things)
6435 (call-with-current-continuation
6436 (lambda (cont) (apply cont things))))
6437 </pre></td></tr></table>
6438
6439
6440
6441
6442
6443 <a name="Definition_of_call-with-values"></a><a name="Procedure_call-with-values"></a><a name="index-call_002dwith_002dvalues-2"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Procedure_call-with-values">call-with-values</a></b></code><i> producer consumer</i><code>)</code></td><td align="right">procedure</td></tr></table>
6444
6445 <p>Calls its <var>producer</var> argument with no values and
6446 a continuation that, when passed some values, calls the
6447 <var>consumer</var> procedure with those values as arguments.
6448 The continuation for the call to <var>consumer</var> is the
6449 continuation of the call to <tt>call-with-values</tt>.
6450 </p>
6451
6452 <table><tr><td>&nbsp;</td><td><pre class="format">(call-with-values (lambda () (values 4 5))
6453 (lambda (a b) b))
6454 ==&gt; 5
6455
6456 (call-with-values * -) ==&gt; -1
6457 </pre></td></tr></table>
6458
6459
6460
6461
6462
6463 <a name="Definition_of_dynamic-wind"></a><a name="Procedure_dynamic-wind"></a><a name="index-dynamic_002dwind-1"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Procedure_dynamic-wind">dynamic-wind</a></b></code><i> before thunk after</i><code>)</code></td><td align="right">procedure</td></tr></table>
6464
6465 <p>Calls <var>thunk</var> without arguments, returning the result(s) of this call.
6466 <var>Before</var> and <var>after</var> are called, also without arguments, as required
6467 by the following rules (note that in the absence of calls to continuations
6468 captured using <code>call-with-current-continuation</code> the three arguments are
6469 <a name="index-call_002dwith_002dcurrent_002dcontinuation-2"></a>
6470 called once each, in order). <var>Before</var> is called whenever execution
6471 enters the dynamic extent of the call to <var>thunk</var> and <var>after</var> is called
6472 whenever it exits that dynamic extent. The dynamic extent of a procedure
6473 call is the period between when the call is initiated and when it
6474 returns. In Scheme, because of <samp>call-with-current-continuation</samp>, the
6475 dynamic extent of a call may not be a single, connected time period.
6476 It is defined as follows:
6477 </p>
6478
6479 <ul>
6480 <li>
6481 The dynamic extent is entered when execution of the body of the
6482 called procedure begins.
6483
6484 </li><li>
6485 The dynamic extent is also entered when execution is not within
6486 the dynamic extent and a continuation is invoked that was captured
6487 (using <samp>call-with-current-continuation</samp>) during the dynamic extent.
6488
6489 </li><li>
6490 It is exited when the called procedure returns.
6491
6492 </li><li>
6493 It is also exited when execution is within the dynamic extent and
6494 a continuation is invoked that was captured while not within the
6495 dynamic extent.
6496
6497 </li></ul>
6498
6499
6500 <p>If a second call to <samp>dynamic-wind</samp> occurs within the dynamic extent of the
6501 call to <var>thunk</var> and then a continuation is invoked in such a way that the
6502 <var>after</var>s from these two invocations of <samp>dynamic-wind</samp> are both to be
6503 called, then the <var>after</var> associated with the second (inner) call to
6504 <samp>dynamic-wind</samp> is called first.
6505 </p>
6506 <p>If a second call to <samp>dynamic-wind</samp> occurs within the dynamic extent of the
6507 call to <var>thunk</var> and then a continuation is invoked in such a way that the
6508 <var>before</var>s from these two invocations of <samp>dynamic-wind</samp> are both to be
6509 called, then the <var>before</var> associated with the first (outer) call to
6510 <samp>dynamic-wind</samp> is called first.
6511 </p>
6512 <p>If invoking a continuation requires calling the <var>before</var> from one call
6513 to <samp>dynamic-wind</samp> and the <var>after</var> from another, then the <var>after</var>
6514 is called first.
6515 </p>
6516 <p>The effect of using a captured continuation to enter or exit the dynamic
6517 extent of a call to <var>before</var> or <var>after</var> is undefined.
6518 </p>
6519
6520 <table><tr><td>&nbsp;</td><td><pre class="format">(let ((path '())
6521 (c #f))
6522 (let ((add (lambda (s)
6523 (set! path (cons s path)))))
6524 (dynamic-wind
6525 (lambda () (add 'connect))
6526 (lambda ()
6527 (add (call-with-current-continuation
6528 (lambda (c0)
6529 (set! c c0)
6530 'talk1))))
6531 (lambda () (add 'disconnect)))
6532 (if (&lt; (length path) 4)
6533 (c 'talk2)
6534 (reverse path))))
6535
6536 ==&gt; (connect talk1 disconnect
6537 connect talk2 disconnect)
6538 </pre></td></tr></table>
6539
6540
6541
6542 <a name="Eval"></a><hr size="1"><br/><br/><br/>
6543 <table cellpadding="1" cellspacing="1" border="0">
6544 <tr><td valign="middle" align="left"><a href="#Control-features" title="Previous section in reading order"><img src="button-left.png" border="0" alt="Back: 6.4 Control features" align="middle" width="32"></a></td>
6545 <td valign="middle" align="left"><a href="#Input-and-output" title="Next section in reading order"><img src="button-right.png" border="0" alt="Forward: 6.6 Input and output" align="middle" width="32"></a></td>
6546 <td valign="middle" align="left"> &nbsp; </td>
6547 <td valign="middle" align="left"><a href="#Standard-procedures" title="Beginning of this chapter or previous chapter"><img src="button-left-left.png" border="0" alt="FastBack: 6. Standard procedures" align="middle" width="32"></a></td>
6548 <td valign="middle" align="left"><a href="#Standard-procedures" title="Up section"><img src="button-up.png" border="0" alt="Up: 6. Standard procedures" align="middle" width="32"></a></td>
6549 <td valign="middle" align="left"><a href="#Formal-syntax-and-semantics" title="Next chapter"><img src="button-right-right.png" border="0" alt="FastForward: 7. Formal syntax and semantics" align="middle" width="32"></a></td>
6550 <td valign="middle" align="left"><a href="#Top" title="Cover (top) of document"><img src="button-up-arrow.png" border="0" alt="Top: Revised(5) Report on the Algorithmic Language Scheme" align="middle" width="32"></a></td>
6551 <td valign="middle" align="left"><a href="#SEC_Contents" title="Table of contents"><img src="button-compass.png" border="0" alt="Contents: Table of Contents" align="middle" width="32"></a></td>
6552 <td valign="middle" align="left"><a href="#Index" title="Index"><img src="button-abc.png" border="0" alt="Index: Alphabetic index of definitions of concepts, keywords, and procedures" align="middle" width="32"></a></td>
6553 </tr></table>
6554 <a name="Eval-1"></a>
6555 <h2 class="section">6.5 Eval</h2>
6556
6557
6558
6559 <a name="Definition_of_eval"></a><a name="Procedure_eval"></a><a name="index-eval-2"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Procedure_eval">eval</a></b></code><i> expression environment-specifier</i><code>)</code></td><td align="right">procedure</td></tr></table>
6560
6561 <p>Evaluates <var>expression</var> in the specified environment and returns its value.
6562 <var>Expression</var> must be a valid Scheme expression represented as data,
6563 and <var>environment-specifier</var> must be a value returned by one of the
6564 three procedures described below.
6565 Implementations may extend <samp>eval</samp> to allow non-expression programs
6566 (definitions) as the first argument and to allow other
6567 values as environments, with the restriction that <samp>eval</samp> is not
6568 allowed to create new bindings in the environments associated with
6569 <samp>null-environment</samp> or <samp>scheme-report-environment</samp>.
6570 </p>
6571
6572 <table><tr><td>&nbsp;</td><td><pre class="format">(eval '(* 7 3) (scheme-report-environment 5))
6573 ==&gt; 21
6574
6575 (let ((f (eval '(lambda (f x) (f x x))
6576 (null-environment 5))))
6577 (f + 10))
6578 ==&gt; 20
6579 </pre></td></tr></table>
6580
6581
6582
6583
6584
6585 <a name="Definition_of_scheme-report-environment"></a><a name="Procedure_scheme-report-environment"></a><a name="index-scheme_002dreport_002denvironment"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Procedure_scheme-report-environment">scheme-report-environment</a></b></code><i> version</i><code>)</code></td><td align="right">procedure</td></tr></table>
6586 <a name="Definition_of_null-environment"></a><a name="Procedure_null-environment"></a><a name="index-null_002denvironment"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Procedure_null-environment">null-environment</a></b></code><i> version</i><code>)</code></td><td align="right">procedure</td></tr></table>
6587
6588 <p><var>Version</var> must be the exact integer <samp>5</samp>,
6589 corresponding to this revision of the Scheme report (the
6590 Revised^5 Report on Scheme).
6591 <samp>Scheme-report-environment</samp> returns a specifier for an
6592 environment that is empty except for all bindings defined in
6593 this report that are either required or both optional and
6594 supported by the implementation. <samp>Null-environment</samp> returns
6595 a specifier for an environment that is empty except for the
6596 (syntactic) bindings for all syntactic keywords defined in
6597 this report that are either required or both optional and
6598 supported by the implementation.
6599 </p>
6600 <p>Other values of <var>version</var> can be used to specify environments
6601 matching past revisions of this report, but their support is not
6602 required. An implementation will signal an error if <var>version</var>
6603 is neither <samp>5</samp> nor another value supported by
6604 the implementation.
6605 </p>
6606 <p>The effect of assigning (through the use of <samp>eval</samp>) a variable
6607 bound in a <samp>scheme-report-environment</samp>
6608 (for example <samp>car</samp>) is unspecified. Thus the environments specified
6609 by <samp>scheme-report-environment</samp> may be immutable.
6610 </p>
6611
6612
6613
6614 <a name="Definition_of_interaction-environment"></a><a name="Optional_procedure_interaction-environment"></a><a name="index-interaction_002denvironment"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Optional_procedure_interaction-environment">interaction-environment</a></b></code><code>)</code></td><td align="right">optional procedure</td></tr></table>
6615
6616 <p>This procedure returns a specifier for the environment that
6617 contains implementation-defined bindings, typically a superset of
6618 those listed in the report. The intent is that this procedure
6619 will return the environment in which the implementation would evaluate
6620 expressions dynamically typed by the user.
6621 </p>
6622
6623
6624 <a name="Input-and-output"></a><hr size="1"><br/><br/><br/>
6625 <table cellpadding="1" cellspacing="1" border="0">
6626 <tr><td valign="middle" align="left"><a href="#Eval" title="Previous section in reading order"><img src="button-left.png" border="0" alt="Back: 6.5 Eval" align="middle" width="32"></a></td>
6627 <td valign="middle" align="left"><a href="#Ports" title="Next section in reading order"><img src="button-right.png" border="0" alt="Forward: 6.6.1 Ports" align="middle" width="32"></a></td>
6628 <td valign="middle" align="left"> &nbsp; </td>
6629 <td valign="middle" align="left"><a href="#Standard-procedures" title="Beginning of this chapter or previous chapter"><img src="button-left-left.png" border="0" alt="FastBack: 6. Standard procedures" align="middle" width="32"></a></td>
6630 <td valign="middle" align="left"><a href="#Standard-procedures" title="Up section"><img src="button-up.png" border="0" alt="Up: 6. Standard procedures" align="middle" width="32"></a></td>
6631 <td valign="middle" align="left"><a href="#Formal-syntax-and-semantics" title="Next chapter"><img src="button-right-right.png" border="0" alt="FastForward: 7. Formal syntax and semantics" align="middle" width="32"></a></td>
6632 <td valign="middle" align="left"><a href="#Top" title="Cover (top) of document"><img src="button-up-arrow.png" border="0" alt="Top: Revised(5) Report on the Algorithmic Language Scheme" align="middle" width="32"></a></td>
6633 <td valign="middle" align="left"><a href="#SEC_Contents" title="Table of contents"><img src="button-compass.png" border="0" alt="Contents: Table of Contents" align="middle" width="32"></a></td>
6634 <td valign="middle" align="left"><a href="#Index" title="Index"><img src="button-abc.png" border="0" alt="Index: Alphabetic index of definitions of concepts, keywords, and procedures" align="middle" width="32"></a></td>
6635 </tr></table>
6636 <a name="Input-and-output-1"></a>
6637 <h2 class="section">6.6 Input and output</h2>
6638
6639 <table class="menu" border="0" cellspacing="0">
6640 <tr><td align="left" valign="top"><a href="#Ports">6.6.1 Ports</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
6641 </td></tr>
6642 <tr><td align="left" valign="top"><a href="#Input">6.6.2 Input</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
6643 </td></tr>
6644 <tr><td align="left" valign="top"><a href="#Output">6.6.3 Output</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
6645 </td></tr>
6646 <tr><td align="left" valign="top"><a href="#System-interface">6.6.4 System interface</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
6647 </td></tr>
6648 </table>
6649
6650
6651 <a name="Ports"></a><hr size="1"><br/><br/><br/>
6652 <table cellpadding="1" cellspacing="1" border="0">
6653 <tr><td valign="middle" align="left"><a href="#Input-and-output" title="Previous section in reading order"><img src="button-left.png" border="0" alt="Back: 6.6 Input and output" align="middle" width="32"></a></td>
6654 <td valign="middle" align="left"><a href="#Input" title="Next section in reading order"><img src="button-right.png" border="0" alt="Forward: 6.6.2 Input" align="middle" width="32"></a></td>
6655 <td valign="middle" align="left"> &nbsp; </td>
6656 <td valign="middle" align="left"><a href="#Standard-procedures" title="Beginning of this chapter or previous chapter"><img src="button-left-left.png" border="0" alt="FastBack: 6. Standard procedures" align="middle" width="32"></a></td>
6657 <td valign="middle" align="left"><a href="#Input-and-output" title="Up section"><img src="button-up.png" border="0" alt="Up: 6.6 Input and output" align="middle" width="32"></a></td>
6658 <td valign="middle" align="left"><a href="#Formal-syntax-and-semantics" title="Next chapter"><img src="button-right-right.png" border="0" alt="FastForward: 7. Formal syntax and semantics" align="middle" width="32"></a></td>
6659 <td valign="middle" align="left"><a href="#Top" title="Cover (top) of document"><img src="button-up-arrow.png" border="0" alt="Top: Revised(5) Report on the Algorithmic Language Scheme" align="middle" width="32"></a></td>
6660 <td valign="middle" align="left"><a href="#SEC_Contents" title="Table of contents"><img src="button-compass.png" border="0" alt="Contents: Table of Contents" align="middle" width="32"></a></td>
6661 <td valign="middle" align="left"><a href="#Index" title="Index"><img src="button-abc.png" border="0" alt="Index: Alphabetic index of definitions of concepts, keywords, and procedures" align="middle" width="32"></a></td>
6662 </tr></table>
6663 <a name="Ports-1"></a>
6664 <h3 class="subsection">6.6.1 Ports</h3>
6665
6666
6667
6668 <p>Ports represent input and output devices. To Scheme, an input port is a
6669 Scheme object that can deliver characters upon command, while an output port
6670 is a Scheme object that can accept characters.
6671 <a name="index-port"></a>
6672 </p>
6673
6674
6675
6676 <a name="Definition_of_call-with-input-file"></a><a name="Library_procedure_call-with-input-file"></a><a name="index-call_002dwith_002dinput_002dfile"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Library_procedure_call-with-input-file">call-with-input-file</a></b></code><i> string proc</i><code>)</code></td><td align="right">library procedure</td></tr></table>
6677 <a name="Definition_of_call-with-output-file"></a><a name="Library_procedure_call-with-output-file"></a><a name="index-call_002dwith_002doutput_002dfile"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Library_procedure_call-with-output-file">call-with-output-file</a></b></code><i> string proc</i><code>)</code></td><td align="right">library procedure</td></tr></table>
6678
6679 <p><var>String</var> should be a string naming a file, and
6680 <var>proc</var> should be a procedure that accepts one argument.
6681 For <samp>call-with-input-file</samp>,
6682 the file should already exist; for
6683 <samp>call-with-output-file</samp>,
6684 the effect is unspecified if the file
6685 already exists. These procedures call <var>proc</var> with one argument: the
6686 port obtained by opening the named file for input or output. If the
6687 file cannot be opened, an error is signalled. If <var>proc</var> returns,
6688 then the port is closed automatically and the value(s) yielded by the
6689 <var>proc</var> is(are) returned. If <var>proc</var> does not return, then
6690 the port will not be closed automatically unless it is possible to
6691 prove that the port will never again be used for a read or write
6692 operation.
6693 </p>
6694
6695 <blockquote><p><em>Rationale:</em>
6696 Because Scheme's escape procedures have unlimited extent, it is
6697 possible to escape from the current continuation but later to escape back in.
6698 If implementations were permitted to close the port on any escape from the
6699 current continuation, then it would be impossible to write portable code using
6700 both <samp>call-with-current-continuation</samp> and <samp>call-with-input-file</samp> or
6701 <samp>call-with-output-file</samp>.
6702 </p>
6703 </blockquote>
6704
6705
6706
6707
6708
6709 <a name="Definition_of_input-port?"></a><a name="Procedure_input-port?"></a><a name="index-input_002dport_003f"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Procedure_input-port?">input-port?</a></b></code><i> obj</i><code>)</code></td><td align="right">procedure</td></tr></table>
6710 <a name="Definition_of_output-port?"></a><a name="Procedure_output-port?"></a><a name="index-output_002dport_003f"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Procedure_output-port?">output-port?</a></b></code><i> obj</i><code>)</code></td><td align="right">procedure</td></tr></table>
6711
6712 <p>Returns <tt>#t</tt> if <var>obj</var> is an input port or output port
6713 respectively, otherwise returns <tt>#f</tt>.
6714 </p>
6715
6716
6717
6718
6719
6720
6721 <a name="Definition_of_current-input-port"></a><a name="Procedure_current-input-port"></a><a name="index-current_002dinput_002dport"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Procedure_current-input-port">current-input-port</a></b></code><code>)</code></td><td align="right">procedure</td></tr></table>
6722 <a name="Definition_of_current-output-port"></a><a name="Procedure_current-output-port"></a><a name="index-current_002doutput_002dport"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Procedure_current-output-port">current-output-port</a></b></code><code>)</code></td><td align="right">procedure</td></tr></table>
6723
6724 <p>Returns the current default input or output port.
6725 </p>
6726
6727
6728
6729
6730 <a name="Definition_of_with-input-from-file"></a><a name="Optional_procedure_with-input-from-file"></a><a name="index-with_002dinput_002dfrom_002dfile"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Optional_procedure_with-input-from-file">with-input-from-file</a></b></code><i> string thunk</i><code>)</code></td><td align="right">optional procedure</td></tr></table>
6731 <a name="Definition_of_with-output-to-file"></a><a name="Optional_procedure_with-output-to-file"></a><a name="index-with_002doutput_002dto_002dfile"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Optional_procedure_with-output-to-file">with-output-to-file</a></b></code><i> string thunk</i><code>)</code></td><td align="right">optional procedure</td></tr></table>
6732
6733 <p><var>String</var> should be a string naming a file, and
6734 <var>proc</var> should be a procedure of no arguments.
6735 For <samp>with-input-from-file</samp>,
6736 the file should already exist; for
6737 <samp>with-output-to-file</samp>,
6738 the effect is unspecified if the file
6739 already exists.
6740 The file is opened for input or output, an input or output port
6741 connected to it is made the default value returned by
6742 <samp>current-input-port</samp> or <samp>current-output-port</samp>
6743 (and is used by <tt>(read)</tt>, <tt>(write <var>obj</var>)</tt>, and so forth),
6744 and the
6745 <var>thunk</var> is called with no arguments. When the <var>thunk</var> returns,
6746 the port is closed and the previous default is restored.
6747 <samp>With-input-from-file</samp> and <samp>with-output-to-file</samp> return(s) the
6748 value(s) yielded by <var>thunk</var>.
6749 If an escape procedure
6750 is used to escape from the continuation of these procedures, their
6751 behavior is implementation dependent.
6752 </p>
6753
6754
6755
6756
6757
6758
6759
6760
6761
6762 <a name="Definition_of_open-input-file"></a><a name="Procedure_open-input-file"></a><a name="index-open_002dinput_002dfile"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Procedure_open-input-file">open-input-file</a></b></code><i> filename</i><code>)</code></td><td align="right">procedure</td></tr></table>
6763
6764 <p>Takes a string naming an existing file and returns an input port capable of
6765 delivering characters from the file. If the file cannot be opened, an error is
6766 signalled.
6767 </p>
6768
6769
6770
6771
6772 <a name="Definition_of_open-output-file"></a><a name="Procedure_open-output-file"></a><a name="index-open_002doutput_002dfile"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Procedure_open-output-file">open-output-file</a></b></code><i> filename</i><code>)</code></td><td align="right">procedure</td></tr></table>
6773
6774 <p>Takes a string naming an output file to be created and returns an output
6775 port capable of writing characters to a new file by that name. If the file
6776 cannot be opened, an error is signalled. If a file with the given name
6777 already exists, the effect is unspecified.
6778 </p>
6779
6780
6781
6782
6783 <a name="Definition_of_close-input-port"></a><a name="Procedure_close-input-port"></a><a name="index-close_002dinput_002dport"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Procedure_close-input-port">close-input-port</a></b></code><i> port</i><code>)</code></td><td align="right">procedure</td></tr></table>
6784 <a name="Definition_of_close-output-port"></a><a name="Procedure_close-output-port"></a><a name="index-close_002doutput_002dport"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Procedure_close-output-port">close-output-port</a></b></code><i> port</i><code>)</code></td><td align="right">procedure</td></tr></table>
6785
6786 <p>Closes the file associated with <var>port</var>, rendering the <var>port</var>
6787 incapable of delivering or accepting characters.
6788 </p>
6789 <p>These routines have no effect if the file has already been closed.
6790 The value returned is unspecified.
6791 </p>
6792
6793
6794
6795
6796
6797
6798
6799 <a name="Input"></a><hr size="1"><br/><br/><br/>
6800 <table cellpadding="1" cellspacing="1" border="0">
6801 <tr><td valign="middle" align="left"><a href="#Ports" title="Previous section in reading order"><img src="button-left.png" border="0" alt="Back: 6.6.1 Ports" align="middle" width="32"></a></td>
6802 <td valign="middle" align="left"><a href="#Output" title="Next section in reading order"><img src="button-right.png" border="0" alt="Forward: 6.6.3 Output" align="middle" width="32"></a></td>
6803 <td valign="middle" align="left"> &nbsp; </td>
6804 <td valign="middle" align="left"><a href="#Standard-procedures" title="Beginning of this chapter or previous chapter"><img src="button-left-left.png" border="0" alt="FastBack: 6. Standard procedures" align="middle" width="32"></a></td>
6805 <td valign="middle" align="left"><a href="#Input-and-output" title="Up section"><img src="button-up.png" border="0" alt="Up: 6.6 Input and output" align="middle" width="32"></a></td>
6806 <td valign="middle" align="left"><a href="#Formal-syntax-and-semantics" title="Next chapter"><img src="button-right-right.png" border="0" alt="FastForward: 7. Formal syntax and semantics" align="middle" width="32"></a></td>
6807 <td valign="middle" align="left"><a href="#Top" title="Cover (top) of document"><img src="button-up-arrow.png" border="0" alt="Top: Revised(5) Report on the Algorithmic Language Scheme" align="middle" width="32"></a></td>
6808 <td valign="middle" align="left"><a href="#SEC_Contents" title="Table of contents"><img src="button-compass.png" border="0" alt="Contents: Table of Contents" align="middle" width="32"></a></td>
6809 <td valign="middle" align="left"><a href="#Index" title="Index"><img src="button-abc.png" border="0" alt="Index: Alphabetic index of definitions of concepts, keywords, and procedures" align="middle" width="32"></a></td>
6810 </tr></table>
6811 <a name="Input-1"></a>
6812 <h3 class="subsection">6.6.2 Input</h3>
6813
6814
6815
6816
6817 <p>
6818 <br>
6819 <br>
6820 <br>
6821 <br>
6822 <br>
6823 </p>
6824
6825
6826 <a name="Definition_of_read"></a><a name="Library_procedure_read"></a><a name="index-read-1"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Library_procedure_read">read</a></b></code><code>)</code></td><td align="right">library procedure</td></tr></table>
6827 <a name="Definition_of_read"></a><a name="Library_procedure_read"></a><a name="index-read-2"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Library_procedure_read">read</a></b></code><i> port</i><code>)</code></td><td align="right">library procedure</td></tr></table>
6828
6829 <p><samp>Read</samp> converts external representations of Scheme objects into the
6830 objects themselves. That is, it is a parser for the nonterminal
6831 &lt;datum&gt; (see sections see section <a href="#External-representation">External representations</a> and
6832 see section <a href="#Pairs-and-lists">Pairs and lists</a>). <samp>Read</samp> returns the next
6833 object parsable from the given input <var>port</var>, updating <var>port</var> to point to
6834 the first character past the end of the external representation of the object.
6835 </p>
6836 <p>If an end of file is encountered in the input before any
6837 characters are found that can begin an object, then an end of file
6838 object is returned.
6839 The port remains open, and further attempts
6840 to read will also return an end of file object. If an end of file is
6841 encountered after the beginning of an object's external representation,
6842 but the external representation is incomplete and therefore not parsable,
6843 an error is signalled.
6844 </p>
6845 <p>The <var>port</var> argument may be omitted, in which case it defaults to the
6846 value returned by <samp>current-input-port</samp>. It is an error to read from
6847 a closed port.
6848 </p>
6849
6850
6851 <a name="Definition_of_read-char"></a><a name="Procedure_read-char"></a><a name="index-read_002dchar"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Procedure_read-char">read-char</a></b></code><code>)</code></td><td align="right">procedure</td></tr></table>
6852 <a name="Definition_of_read-char"></a><a name="Procedure_read-char"></a><a name="index-read_002dchar-1"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Procedure_read-char">read-char</a></b></code><i> port</i><code>)</code></td><td align="right">procedure</td></tr></table>
6853
6854 <p>Returns the next character available from the input <var>port</var>, updating
6855 the <var>port</var> to point to the following character. If no more characters
6856 are available, an end of file object is returned. <var>Port</var> may be
6857 omitted, in which case it defaults to the value returned by <samp>current-input-port</samp>.
6858 </p>
6859
6860
6861
6862
6863 <a name="Definition_of_peek-char"></a><a name="Procedure_peek-char"></a><a name="index-peek_002dchar"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Procedure_peek-char">peek-char</a></b></code><code>)</code></td><td align="right">procedure</td></tr></table>
6864 <a name="Definition_of_peek-char"></a><a name="Procedure_peek-char"></a><a name="index-peek_002dchar-1"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Procedure_peek-char">peek-char</a></b></code><i> port</i><code>)</code></td><td align="right">procedure</td></tr></table>
6865
6866 <p>Returns the next character available from the input <var>port</var>,
6867 <em>without</em> updating
6868 the <var>port</var> to point to the following character. If no more characters
6869 are available, an end of file object is returned. <var>Port</var> may be
6870 omitted, in which case it defaults to the value returned by <samp>current-input-port</samp>.
6871 </p>
6872
6873 <blockquote><p><em>Note:</em>
6874 The value returned by a call to <samp>peek-char</samp> is the same as the
6875 value that would have been returned by a call to <samp>read-char</samp> with the
6876 same <var>port</var>. The only difference is that the very next call to
6877 <samp>read-char</samp> or <samp>peek-char</samp> on that <var>port</var> will return the
6878 value returned by the preceding call to <samp>peek-char</samp>. In particular, a call
6879 to <samp>peek-char</samp> on an interactive port will hang waiting for input
6880 whenever a call to <samp>read-char</samp> would have hung.
6881 </p></blockquote>
6882
6883
6884
6885
6886
6887
6888 <a name="Definition_of_eof-object?"></a><a name="Procedure_eof-object?"></a><a name="index-eof_002dobject_003f"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Procedure_eof-object?">eof-object?</a></b></code><i> obj</i><code>)</code></td><td align="right">procedure</td></tr></table>
6889
6890 <p>Returns <tt>#t</tt> if <var>obj</var> is an end of file object, otherwise returns
6891 <tt>#f</tt>. The precise set of end of file objects will vary among
6892 implementations, but in any case no end of file object will ever be an object
6893 that can be read in using <samp>read</samp>.
6894 </p>
6895
6896
6897
6898
6899 <a name="Definition_of_char-ready?"></a><a name="Procedure_char-ready?"></a><a name="index-char_002dready_003f"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Procedure_char-ready?">char-ready?</a></b></code><code>)</code></td><td align="right">procedure</td></tr></table>
6900 <a name="Definition_of_char-ready?"></a><a name="Procedure_char-ready?"></a><a name="index-char_002dready_003f-1"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Procedure_char-ready?">char-ready?</a></b></code><i> port</i><code>)</code></td><td align="right">procedure</td></tr></table>
6901
6902 <p>Returns <tt>#t</tt> if a character is ready on the input <var>port</var> and
6903 returns <tt>#f</tt> otherwise. If <samp>char-ready</samp> returns <tt>#t</tt> then
6904 the next <samp>read-char</samp> operation on the given <var>port</var> is guaranteed
6905 not to hang. If the <var>port</var> is at end of file then <samp>char-ready?</samp>
6906 returns <tt>#t</tt>. <var>Port</var> may be omitted, in which case it defaults to
6907 the value returned by <samp>current-input-port</samp>.
6908 </p>
6909
6910 <blockquote><p><em>Rationale:</em>
6911 <samp>Char-ready?</samp> exists to make it possible for a program to
6912 accept characters from interactive ports without getting stuck waiting for
6913 input. Any input editors associated with such ports must ensure that
6914 characters whose existence has been asserted by <samp>char-ready?</samp> cannot
6915 be rubbed out. If <samp>char-ready?</samp> were to return <tt>#f</tt> at end of
6916 file, a port at end of file would be indistinguishable from an interactive
6917 port that has no ready characters.
6918 </p></blockquote>
6919
6920
6921
6922
6923 <a name="Output"></a><hr size="1"><br/><br/><br/>
6924 <table cellpadding="1" cellspacing="1" border="0">
6925 <tr><td valign="middle" align="left"><a href="#Input" title="Previous section in reading order"><img src="button-left.png" border="0" alt="Back: 6.6.2 Input" align="middle" width="32"></a></td>
6926 <td valign="middle" align="left"><a href="#System-interface" title="Next section in reading order"><img src="button-right.png" border="0" alt="Forward: 6.6.4 System interface" align="middle" width="32"></a></td>
6927 <td valign="middle" align="left"> &nbsp; </td>
6928 <td valign="middle" align="left"><a href="#Standard-procedures" title="Beginning of this chapter or previous chapter"><img src="button-left-left.png" border="0" alt="FastBack: 6. Standard procedures" align="middle" width="32"></a></td>
6929 <td valign="middle" align="left"><a href="#Input-and-output" title="Up section"><img src="button-up.png" border="0" alt="Up: 6.6 Input and output" align="middle" width="32"></a></td>
6930 <td valign="middle" align="left"><a href="#Formal-syntax-and-semantics" title="Next chapter"><img src="button-right-right.png" border="0" alt="FastForward: 7. Formal syntax and semantics" align="middle" width="32"></a></td>
6931 <td valign="middle" align="left"><a href="#Top" title="Cover (top) of document"><img src="button-up-arrow.png" border="0" alt="Top: Revised(5) Report on the Algorithmic Language Scheme" align="middle" width="32"></a></td>
6932 <td valign="middle" align="left"><a href="#SEC_Contents" title="Table of contents"><img src="button-compass.png" border="0" alt="Contents: Table of Contents" align="middle" width="32"></a></td>
6933 <td valign="middle" align="left"><a href="#Index" title="Index"><img src="button-abc.png" border="0" alt="Index: Alphabetic index of definitions of concepts, keywords, and procedures" align="middle" width="32"></a></td>
6934 </tr></table>
6935 <a name="Output-1"></a>
6936 <h3 class="subsection">6.6.3 Output</h3>
6937
6938
6939
6940
6941 <p>
6942 <br>
6943 <br>
6944 <br>
6945 <br>
6946 <br>
6947 </p>
6948
6949 <a name="Definition_of_write"></a><a name="Library_procedure_write"></a><a name="index-write-1"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Library_procedure_write">write</a></b></code><i> obj</i><code>)</code></td><td align="right">library procedure</td></tr></table>
6950 <a name="Definition_of_write"></a><a name="Library_procedure_write"></a><a name="index-write-2"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Library_procedure_write">write</a></b></code><i> obj port</i><code>)</code></td><td align="right">library procedure</td></tr></table>
6951
6952 <p>Writes a written representation of <var>obj</var> to the given <var>port</var>. Strings
6953 that appear in the written representation are enclosed in doublequotes, and
6954 within those strings backslash and doublequote characters are
6955 escaped by backslashes.
6956 Character objects are written using the <samp>#\</samp> notation.
6957 <samp>Write</samp> returns an unspecified value. The
6958 <var>port</var> argument may be omitted, in which case it defaults to the value
6959 returned by <samp>current-output-port</samp>.
6960 </p>
6961
6962
6963
6964
6965 <a name="Definition_of_display"></a><a name="Library_procedure_display"></a><a name="index-display"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Library_procedure_display">display</a></b></code><i> obj</i><code>)</code></td><td align="right">library procedure</td></tr></table>
6966 <a name="Definition_of_display"></a><a name="Library_procedure_display"></a><a name="index-display-1"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Library_procedure_display">display</a></b></code><i> obj port</i><code>)</code></td><td align="right">library procedure</td></tr></table>
6967
6968 <p>Writes a representation of <var>obj</var> to the given <var>port</var>. Strings
6969 that appear in the written representation are not enclosed in
6970 doublequotes, and no characters are escaped within those strings. Character
6971 objects appear in the representation as if written by <samp>write-char</samp>
6972 instead of by <samp>write</samp>. <samp>Display</samp> returns an unspecified value.
6973 The <var>port</var> argument may be omitted, in which case it defaults to the
6974 value returned by <samp>current-output-port</samp>.
6975 </p>
6976
6977 <blockquote><p><em>Rationale:</em>
6978 <samp>Write</samp> is intended
6979 for producing machine-readable output and <samp>display</samp> is for producing
6980 human-readable output. Implementations that allow &ldquo;slashification&rdquo;
6981 within symbols will probably want <samp>write</samp> but not <samp>display</samp> to
6982 slashify funny characters in symbols.
6983 </p></blockquote>
6984
6985
6986
6987
6988
6989 <a name="Definition_of_newline"></a><a name="Library_procedure_newline"></a><a name="index-newline"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Library_procedure_newline">newline</a></b></code><code>)</code></td><td align="right">library procedure</td></tr></table>
6990 <a name="Definition_of_newline"></a><a name="Library_procedure_newline"></a><a name="index-newline-1"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Library_procedure_newline">newline</a></b></code><i> port</i><code>)</code></td><td align="right">library procedure</td></tr></table>
6991
6992 <p>Writes an end of line to <var>port</var>. Exactly how this is done differs
6993 from one operating system to another. Returns an unspecified value.
6994 The <var>port</var> argument may be omitted, in which case it defaults to the
6995 value returned by <samp>current-output-port</samp>.
6996 </p>
6997
6998
6999
7000
7001 <a name="Definition_of_write-char"></a><a name="Procedure_write-char"></a><a name="index-write_002dchar"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Procedure_write-char">write-char</a></b></code><i> char</i><code>)</code></td><td align="right">procedure</td></tr></table>
7002 <a name="Definition_of_write-char"></a><a name="Procedure_write-char"></a><a name="index-write_002dchar-1"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Procedure_write-char">write-char</a></b></code><i> char port</i><code>)</code></td><td align="right">procedure</td></tr></table>
7003
7004 <p>Writes the character <var>char</var> (not an external representation of the
7005 character) to the given <var>port</var> and returns an unspecified value. The
7006 <var>port</var> argument may be omitted, in which case it defaults to the value
7007 returned by <samp>current-output-port</samp>.
7008 </p>
7009
7010
7011
7012 <a name="System-interface"></a><hr size="1"><br/><br/><br/>
7013 <table cellpadding="1" cellspacing="1" border="0">
7014 <tr><td valign="middle" align="left"><a href="#Output" title="Previous section in reading order"><img src="button-left.png" border="0" alt="Back: 6.6.3 Output" align="middle" width="32"></a></td>
7015 <td valign="middle" align="left"><a href="#Formal-syntax-and-semantics" title="Next section in reading order"><img src="button-right.png" border="0" alt="Forward: 7. Formal syntax and semantics" align="middle" width="32"></a></td>
7016 <td valign="middle" align="left"> &nbsp; </td>
7017 <td valign="middle" align="left"><a href="#Standard-procedures" title="Beginning of this chapter or previous chapter"><img src="button-left-left.png" border="0" alt="FastBack: 6. Standard procedures" align="middle" width="32"></a></td>
7018 <td valign="middle" align="left"><a href="#Input-and-output" title="Up section"><img src="button-up.png" border="0" alt="Up: 6.6 Input and output" align="middle" width="32"></a></td>
7019 <td valign="middle" align="left"><a href="#Formal-syntax-and-semantics" title="Next chapter"><img src="button-right-right.png" border="0" alt="FastForward: 7. Formal syntax and semantics" align="middle" width="32"></a></td>
7020 <td valign="middle" align="left"><a href="#Top" title="Cover (top) of document"><img src="button-up-arrow.png" border="0" alt="Top: Revised(5) Report on the Algorithmic Language Scheme" align="middle" width="32"></a></td>
7021 <td valign="middle" align="left"><a href="#SEC_Contents" title="Table of contents"><img src="button-compass.png" border="0" alt="Contents: Table of Contents" align="middle" width="32"></a></td>
7022 <td valign="middle" align="left"><a href="#Index" title="Index"><img src="button-abc.png" border="0" alt="Index: Alphabetic index of definitions of concepts, keywords, and procedures" align="middle" width="32"></a></td>
7023 </tr></table>
7024 <a name="System-interface-1"></a>
7025 <h3 class="subsection">6.6.4 System interface</h3>
7026
7027
7028 <p>Questions of system interface generally fall outside of the domain of this
7029 report. However, the following operations are important enough to
7030 deserve description here.
7031 </p>
7032
7033
7034 <a name="Definition_of_load"></a><a name="Optional_procedure_load"></a><a name="index-load"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Optional_procedure_load">load</a></b></code><i> filename</i><code>)</code></td><td align="right">optional procedure</td></tr></table>
7035
7036
7037
7038 <p><var>Filename</var> should be a string naming an existing file
7039 containing Scheme source code. The <samp>load</samp> procedure reads
7040 expressions and definitions from the file and evaluates them
7041 sequentially. It is unspecified whether the results of the expressions
7042 are printed. The <samp>load</samp> procedure does not affect the values
7043 returned by <samp>current-input-port</samp> and <samp>current-output-port</samp>.
7044 <samp>Load</samp> returns an unspecified value.
7045 </p>
7046
7047 <blockquote><p><em>Rationale:</em>
7048 For portability, <samp>load</samp> must operate on source files.
7049 Its operation on other kinds of files necessarily varies among
7050 implementations.
7051 </p></blockquote>
7052
7053
7054
7055
7056
7057 <a name="Definition_of_transcript-on"></a><a name="Optional_procedure_transcript-on"></a><a name="index-transcript_002don"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Optional_procedure_transcript-on">transcript-on</a></b></code><i> filename</i><code>)</code></td><td align="right">optional procedure</td></tr></table>
7058 <a name="Definition_of_transcript-off"></a><a name="Optional_procedure_transcript-off"></a><a name="index-transcript_002doff"></a><table width="100%"><tr><td align="left"> <code>(</code><code><b><a href="http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php?title=Documentation:Optional_procedure_transcript-off">transcript-off</a></b></code><code>)</code></td><td align="right">optional procedure</td></tr></table>
7059
7060 <p><var>Filename</var> must be a string naming an output file to be
7061 created. The effect of <samp>transcript-on</samp> is to open the named file
7062 for output, and to cause a transcript of subsequent interaction between
7063 the user and the Scheme system to be written to the file. The
7064 transcript is ended by a call to <samp>transcript-off</samp>, which closes the
7065 transcript file. Only one transcript may be in progress at any time,
7066 though some implementations may relax this restriction. The values
7067 returned by these procedures are unspecified.
7068 </p>
7069
7070
7071
7072
7073 <a name="Formal-syntax-and-semantics"></a><hr size="1"><br/><br/><br/>
7074 <table cellpadding="1" cellspacing="1" border="0">
7075 <tr><td valign="middle" align="left"><a href="#System-interface" title="Previous section in reading order"><img src="button-left.png" border="0" alt="Back: 6.6.4 System interface" align="middle" width="32"></a></td>
7076 <td valign="middle" align="left"><a href="#Formal-syntax" title="Next section in reading order"><img src="button-right.png" border="0" alt="Forward: 7.1 Formal syntax" align="middle" width="32"></a></td>
7077 <td valign="middle" align="left"> &nbsp; </td>
7078 <td valign="middle" align="left"><a href="#Standard-procedures" title="Beginning of this chapter or previous chapter"><img src="button-left-left.png" border="0" alt="FastBack: 6. Standard procedures" align="middle" width="32"></a></td>
7079 <td valign="middle" align="left"><a href="#Top" title="Up section"><img src="button-up.png" border="0" alt="Up: Revised(5) Report on the Algorithmic Language Scheme" align="middle" width="32"></a></td>
7080 <td valign="middle" align="left"><a href="#Notes" title="Next chapter"><img src="button-right-right.png" border="0" alt="FastForward: Notes" align="middle" width="32"></a></td>
7081 <td valign="middle" align="left"><a href="#Top" title="Cover (top) of document"><img src="button-up-arrow.png" border="0" alt="Top: Revised(5) Report on the Algorithmic Language Scheme" align="middle" width="32"></a></td>
7082 <td valign="middle" align="left"><a href="#SEC_Contents" title="Table of contents"><img src="button-compass.png" border="0" alt="Contents: Table of Contents" align="middle" width="32"></a></td>
7083 <td valign="middle" align="left"><a href="#Index" title="Index"><img src="button-abc.png" border="0" alt="Index: Alphabetic index of definitions of concepts, keywords, and procedures" align="middle" width="32"></a></td>
7084 </tr></table>
7085 <a name="Formal-syntax-and-semantics-1"></a>
7086 <h1 class="chapter">7. Formal syntax and semantics</h1>
7087
7088 <table class="menu" border="0" cellspacing="0">
7089 <tr><td align="left" valign="top"><a href="#Formal-syntax">7.1 Formal syntax</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
7090 </td></tr>
7091 <tr><td align="left" valign="top"><a href="#Formal-semantics">7.2 Formal semantics</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
7092 </td></tr>
7093 <tr><td align="left" valign="top"><a href="#Derived-expression-type">7.3 Derived expression types</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
7094 </td></tr>
7095 </table>
7096
7097
7098
7099 <p>This chapter provides formal descriptions of what has already been
7100 described informally in previous chapters of this report.
7101 </p>
7102
7103
7104
7105 <a name="Formal-syntax"></a><hr size="1"><br/><br/><br/>
7106 <table cellpadding="1" cellspacing="1" border="0">
7107 <tr><td valign="middle" align="left"><a href="#Formal-syntax-and-semantics" title="Previous section in reading order"><img src="button-left.png" border="0" alt="Back: 7. Formal syntax and semantics" align="middle" width="32"></a></td>
7108 <td valign="middle" align="left"><a href="#Lexical-structure" title="Next section in reading order"><img src="button-right.png" border="0" alt="Forward: 7.1.1 Lexical structure" align="middle" width="32"></a></td>
7109 <td valign="middle" align="left"> &nbsp; </td>
7110 <td valign="middle" align="left"><a href="#Formal-syntax-and-semantics" title="Beginning of this chapter or previous chapter"><img src="button-left-left.png" border="0" alt="FastBack: 7. Formal syntax and semantics" align="middle" width="32"></a></td>
7111 <td valign="middle" align="left"><a href="#Formal-syntax-and-semantics" title="Up section"><img src="button-up.png" border="0" alt="Up: 7. Formal syntax and semantics" align="middle" width="32"></a></td>
7112 <td valign="middle" align="left"><a href="#Notes" title="Next chapter"><img src="button-right-right.png" border="0" alt="FastForward: Notes" align="middle" width="32"></a></td>
7113 <td valign="middle" align="left"><a href="#Top" title="Cover (top) of document"><img src="button-up-arrow.png" border="0" alt="Top: Revised(5) Report on the Algorithmic Language Scheme" align="middle" width="32"></a></td>
7114 <td valign="middle" align="left"><a href="#SEC_Contents" title="Table of contents"><img src="button-compass.png" border="0" alt="Contents: Table of Contents" align="middle" width="32"></a></td>
7115 <td valign="middle" align="left"><a href="#Index" title="Index"><img src="button-abc.png" border="0" alt="Index: Alphabetic index of definitions of concepts, keywords, and procedures" align="middle" width="32"></a></td>
7116 </tr></table>
7117 <a name="Formal-syntax-1"></a>
7118 <h2 class="section">7.1 Formal syntax</h2>
7119
7120 <table class="menu" border="0" cellspacing="0">
7121 <tr><td align="left" valign="top"><a href="#Lexical-structure">7.1.1 Lexical structure</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
7122 </td></tr>
7123 <tr><td align="left" valign="top"><a href="#External-representation">7.1.2 External representations</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
7124 </td></tr>
7125 <tr><td align="left" valign="top"><a href="#Expression">7.1.3 Expressions</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
7126 </td></tr>
7127 <tr><td align="left" valign="top"><a href="#Quasiquotations">7.1.4 Quasiquotations</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
7128 </td></tr>
7129 <tr><td align="left" valign="top"><a href="#Transformers">7.1.5 Transformers</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
7130 </td></tr>
7131 <tr><td align="left" valign="top"><a href="#Programs-and-definitions">7.1.6 Programs and definitions</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
7132 </td></tr>
7133 </table>
7134
7135
7136
7137 <p>This section provides a formal syntax for Scheme written in an extended
7138 BNF.
7139 </p>
7140 <p>All spaces in the grammar are for legibility. Case is insignificant;
7141 for example, <samp>#x1A</samp> and <samp>#X1a</samp> are equivalent. &lt;empty&gt;
7142 stands for the empty string.
7143 </p>
7144 <p>The following extensions to BNF are used to make the description more
7145 concise: &lt;thing&gt;* means zero or more occurrences of
7146 &lt;thing&gt;; and &lt;thing&gt;+ means at least one
7147 &lt;thing&gt;.
7148 </p>
7149
7150 <a name="Lexical-structure"></a><hr size="1"><br/><br/><br/>
7151 <table cellpadding="1" cellspacing="1" border="0">
7152 <tr><td valign="middle" align="left"><a href="#Formal-syntax" title="Previous section in reading order"><img src="button-left.png" border="0" alt="Back: 7.1 Formal syntax" align="middle" width="32"></a></td>
7153 <td valign="middle" align="left"><a href="#External-representation" title="Next section in reading order"><img src="button-right.png" border="0" alt="Forward: 7.1.2 External representations" align="middle" width="32"></a></td>
7154 <td valign="middle" align="left"> &nbsp; </td>
7155 <td valign="middle" align="left"><a href="#Formal-syntax-and-semantics" title="Beginning of this chapter or previous chapter"><img src="button-left-left.png" border="0" alt="FastBack: 7. Formal syntax and semantics" align="middle" width="32"></a></td>
7156 <td valign="middle" align="left"><a href="#Formal-syntax" title="Up section"><img src="button-up.png" border="0" alt="Up: 7.1 Formal syntax" align="middle" width="32"></a></td>
7157 <td valign="middle" align="left"><a href="#Notes" title="Next chapter"><img src="button-right-right.png" border="0" alt="FastForward: Notes" align="middle" width="32"></a></td>
7158 <td valign="middle" align="left"><a href="#Top" title="Cover (top) of document"><img src="button-up-arrow.png" border="0" alt="Top: Revised(5) Report on the Algorithmic Language Scheme" align="middle" width="32"></a></td>
7159 <td valign="middle" align="left"><a href="#SEC_Contents" title="Table of contents"><img src="button-compass.png" border="0" alt="Contents: Table of Contents" align="middle" width="32"></a></td>
7160 <td valign="middle" align="left"><a href="#Index" title="Index"><img src="button-abc.png" border="0" alt="Index: Alphabetic index of definitions of concepts, keywords, and procedures" align="middle" width="32"></a></td>
7161 </tr></table>
7162 <a name="Lexical-structure-1"></a>
7163 <h3 class="subsection">7.1.1 Lexical structure</h3>
7164
7165
7166 <p>This section describes how individual tokens (identifiers,
7167 <a name="index-token"></a>
7168 numbers, etc.) are formed from sequences of characters. The following
7169 sections describe how expressions and programs are formed from sequences
7170 of tokens.
7171 </p>
7172 <p>&lt;Intertoken space&gt; may occur on either side of any token, but not
7173 within a token.
7174 </p>
7175 <p>Tokens which require implicit termination (identifiers, numbers,
7176 characters, and dot) may be terminated by any &lt;delimiter&gt;, but not
7177 necessarily by anything else.
7178 </p>
7179 <p>The following five characters are reserved for future extensions to the
7180 language: <tt>[ ] { } |</tt>
7181 </p>
7182
7183 <table><tr><td>&nbsp;</td><td><pre class="format">&lt;token&gt; &ndash;&gt; &lt;identifier&gt; | &lt;boolean&gt; | &lt;number&gt;
7184 <a name="index-identifier-3"></a> | &lt;character&gt; | &lt;string&gt;
7185 | ( | ) | #( | <tt>'</tt> | <tt>&lsquo;</tt> | , | ,@ | <b>.</b>
7186 &lt;delimiter&gt; &ndash;&gt; &lt;whitespace&gt; | ( | ) | &quot; | ;
7187 &lt;whitespace&gt; &ndash;&gt; &lt;space or newline&gt;
7188 &lt;comment&gt; &ndash;&gt; ; &lt;<span class="roman">all subsequent characters up to a</span>
7189 <span class="roman">line break&gt;</span>
7190 <a name="index-comment-1"></a>&lt;atmosphere&gt; &ndash;&gt; &lt;whitespace&gt; | &lt;comment&gt;
7191 &lt;intertoken space&gt; &ndash;&gt; &lt;atmosphere&gt;*
7192 </pre></td></tr></table>
7193
7194
7195
7196
7197
7198
7199
7200
7201
7202 <table><tr><td>&nbsp;</td><td><pre class="format">&lt;identifier&gt; &ndash;&gt; &lt;initial&gt; &lt;subsequent&gt;*
7203 | &lt;peculiar identifier&gt;
7204 &lt;initial&gt; &ndash;&gt; &lt;letter&gt; | &lt;special initial&gt;
7205 &lt;letter&gt; &ndash;&gt; a | b | c | ... | z
7206
7207 &lt;special initial&gt; &ndash;&gt; ! | $ | % | &amp; | * | / | : | &lt; | =
7208 | &gt; | ? | ^ | _ | ~
7209 &lt;subsequent&gt; &ndash;&gt; &lt;initial&gt; | &lt;digit&gt;
7210 | &lt;special subsequent&gt;
7211 &lt;digit&gt; &ndash;&gt; 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
7212 &lt;special subsequent&gt; &ndash;&gt; + | - | . | @
7213 &lt;peculiar identifier&gt; &ndash;&gt; + | - | ...
7214 &lt;syntactic keyword&gt; &ndash;&gt; &lt;expression keyword&gt;
7215 <a name="index-syntactic-keyword-3"></a><a name="index-keyword-2"></a> | else | =&gt; | define
7216 | unquote | unquote-splicing
7217 &lt;expression keyword&gt; &ndash;&gt; quote | lambda | if
7218 | set! | begin | cond | and | or | case
7219 | let | let* | letrec | do | delay
7220 | quasiquote
7221
7222 <samp>&lt;variable&gt; &rArr; &lt;</samp><span class="roman">any &lt;identifier&gt; that isn't</span>
7223 <a name="index-variable-3"></a> <span class="roman">also a &lt;syntactic keyword&gt;&gt;</span>
7224
7225 &lt;boolean&gt; &ndash;&gt; #t | #f
7226 &lt;character&gt; &ndash;&gt; #\ &lt;any character&gt;
7227 | #\ &lt;character name&gt;
7228 &lt;character name&gt; &ndash;&gt; space | newline
7229
7230 &lt;string&gt; &ndash;&gt; &quot; &lt;string element&gt;* &quot;
7231 &lt;string element&gt; &ndash;&gt; &lt;any character other than &quot; or \&gt;
7232 | \&quot; | \\
7233 </pre></td></tr></table>
7234
7235
7236
7237
7238
7239
7240
7241 <table><tr><td>&nbsp;</td><td><pre class="format">&lt;number&gt; &ndash;&gt; &lt;num 2&gt;| &lt;num 8&gt;
7242 | &lt;num 10&gt;| &lt;num 16&gt;
7243 </pre></td></tr></table>
7244
7245
7246
7247 <p>The following rules for &lt;num R&gt;, &lt;complex R&gt;, &lt;real
7248 R&gt;, &lt;ureal R&gt;, &lt;uinteger R&gt;, and &lt;prefix R&gt;
7249 should be replicated for R = 2, 8, 10,
7250 and 16. There are no rules for &lt;decimal 2&gt;, &lt;decimal
7251 8&gt;, and &lt;decimal 16&gt;, which means that numbers containing
7252 decimal points or exponents must be in decimal radix.
7253 </p>
7254
7255
7256 <table><tr><td>&nbsp;</td><td><pre class="format">&lt;num R&gt; &ndash;&gt; &lt;prefix R&gt; &lt;complex R&gt;
7257 &lt;complex R&gt; &ndash;&gt; &lt;real R&gt; | &lt;real R&gt; @ &lt;real R&gt;
7258 | &lt;real R&gt; + &lt;ureal R&gt; i | &lt;real R&gt; - &lt;ureal R&gt; i
7259 | &lt;real R&gt; + i | &lt;real R&gt; - i
7260 | + &lt;ureal R&gt; i | - &lt;ureal R&gt; i | + i | - i
7261 &lt;real R&gt; &ndash;&gt; &lt;sign&gt; &lt;ureal R&gt;
7262 &lt;ureal R&gt; &ndash;&gt; &lt;uinteger R&gt;
7263 | &lt;uinteger R&gt; / &lt;uinteger R&gt;
7264 | &lt;decimal R&gt;
7265 &lt;decimal 10&gt; &ndash;&gt; &lt;uinteger 10&gt; &lt;suffix&gt;
7266 | . &lt;digit 10&gt;+ #* &lt;suffix&gt;
7267 | &lt;digit 10&gt;+ . &lt;digit 10&gt;* #* &lt;suffix&gt;
7268 | &lt;digit 10&gt;+ #+ . #* &lt;suffix&gt;
7269 &lt;uinteger R&gt; &ndash;&gt; &lt;digit R&gt;+ #*
7270 &lt;prefix R&gt; &ndash;&gt; &lt;radix R&gt; &lt;exactness&gt;
7271 | &lt;exactness&gt; &lt;radix R&gt;
7272 </pre></td></tr></table>
7273
7274
7275
7276
7277 <table><tr><td>&nbsp;</td><td><pre class="format">&lt;suffix&gt; &ndash;&gt; &lt;empty&gt;
7278 | &lt;exponent marker&gt; &lt;sign&gt; &lt;digit 10&gt;+
7279 &lt;exponent marker&gt; &ndash;&gt; e | s | f | d | l
7280 &lt;sign&gt; &ndash;&gt; &lt;empty&gt; | + | -
7281 &lt;exactness&gt; &ndash;&gt; &lt;empty&gt; | #i | #e
7282 <a name="index-_0023e-1"></a><a name="index-_0023i-1"></a>&lt;radix 2&gt; &ndash;&gt; #b
7283 <a name="index-_0023b-1"></a>&lt;radix 8&gt; &ndash;&gt; #o
7284 <a name="index-_0023o-1"></a>&lt;radix 10&gt; &ndash;&gt; &lt;empty&gt; | #d
7285 &lt;radix 16&gt; &ndash;&gt; #x
7286 <a name="index-_0023x-1"></a>&lt;digit 2&gt; &ndash;&gt; 0 | 1
7287 &lt;digit 8&gt; &ndash;&gt; 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7
7288 &lt;digit 10&gt; &ndash;&gt; &lt;digit&gt;
7289 &lt;digit 16&gt; &ndash;&gt; &lt;digit 10&gt; | a | b | c | d | e | f
7290 </pre></td></tr></table>
7291
7292
7293
7294
7295
7296
7297 <a name="External-representation"></a><hr size="1"><br/><br/><br/>
7298 <table cellpadding="1" cellspacing="1" border="0">
7299 <tr><td valign="middle" align="left"><a href="#Lexical-structure" title="Previous section in reading order"><img src="button-left.png" border="0" alt="Back: 7.1.1 Lexical structure" align="middle" width="32"></a></td>
7300 <td valign="middle" align="left"><a href="#Expression" title="Next section in reading order"><img src="button-right.png" border="0" alt="Forward: 7.1.3 Expressions" align="middle" width="32"></a></td>
7301 <td valign="middle" align="left"> &nbsp; </td>
7302 <td valign="middle" align="left"><a href="#Formal-syntax-and-semantics" title="Beginning of this chapter or previous chapter"><img src="button-left-left.png" border="0" alt="FastBack: 7. Formal syntax and semantics" align="middle" width="32"></a></td>
7303 <td valign="middle" align="left"><a href="#Formal-syntax" title="Up section"><img src="button-up.png" border="0" alt="Up: 7.1 Formal syntax" align="middle" width="32"></a></td>
7304 <td valign="middle" align="left"><a href="#Notes" title="Next chapter"><img src="button-right-right.png" border="0" alt="FastForward: Notes" align="middle" width="32"></a></td>
7305 <td valign="middle" align="left"><a href="#Top" title="Cover (top) of document"><img src="button-up-arrow.png" border="0" alt="Top: Revised(5) Report on the Algorithmic Language Scheme" align="middle" width="32"></a></td>
7306 <td valign="middle" align="left"><a href="#SEC_Contents" title="Table of contents"><img src="button-compass.png" border="0" alt="Contents: Table of Contents" align="middle" width="32"></a></td>
7307 <td valign="middle" align="left"><a href="#Index" title="Index"><img src="button-abc.png" border="0" alt="Index: Alphabetic index of definitions of concepts, keywords, and procedures" align="middle" width="32"></a></td>
7308 </tr></table>
7309 <a name="External-representations-1"></a>
7310 <h3 class="subsection">7.1.2 External representations</h3>
7311
7312
7313
7314 <p>&lt;Datum&gt; is what the <code>read</code> procedure (section see section <a href="#Input">Input</a>)
7315 <a name="index-read-3"></a>
7316 successfully parses. Note that any string that parses as an
7317 &lt;expression&gt; will also parse as a &lt;datum&gt;.
7318 </p>
7319
7320 <table><tr><td>&nbsp;</td><td><pre class="format">&lt;datum&gt; &ndash;&gt; &lt;simple datum&gt; | &lt;compound datum&gt;
7321 &lt;simple datum&gt; &ndash;&gt; &lt;boolean&gt; | &lt;number&gt;
7322 | &lt;character&gt; | &lt;string&gt; | &lt;symbol&gt;
7323 &lt;symbol&gt; &ndash;&gt; &lt;identifier&gt;
7324 &lt;compound datum&gt; &ndash;&gt; &lt;list&gt; | &lt;vector&gt;
7325 &lt;list&gt; &ndash;&gt; (&lt;datum&gt;*) | (&lt;datum&gt;+ . &lt;datum&gt;)
7326 | &lt;abbreviation&gt;
7327 &lt;abbreviation&gt; &ndash;&gt; &lt;abbrev prefix&gt; &lt;datum&gt;
7328 &lt;abbrev prefix&gt; &ndash;&gt; ' | &lsquo; | , | ,@
7329 &lt;vector&gt; &ndash;&gt; #(&lt;datum&gt;*)
7330 </pre></td></tr></table>
7331
7332
7333
7334
7335 <a name="Expression"></a><hr size="1"><br/><br/><br/>
7336 <table cellpadding="1" cellspacing="1" border="0">
7337 <tr><td valign="middle" align="left"><a href="#External-representation" title="Previous section in reading order"><img src="button-left.png" border="0" alt="Back: 7.1.2 External representations" align="middle" width="32"></a></td>
7338 <td valign="middle" align="left"><a href="#Quasiquotations" title="Next section in reading order"><img src="button-right.png" border="0" alt="Forward: 7.1.4 Quasiquotations" align="middle" width="32"></a></td>
7339 <td valign="middle" align="left"> &nbsp; </td>
7340 <td valign="middle" align="left"><a href="#Formal-syntax-and-semantics" title="Beginning of this chapter or previous chapter"><img src="button-left-left.png" border="0" alt="FastBack: 7. Formal syntax and semantics" align="middle" width="32"></a></td>
7341 <td valign="middle" align="left"><a href="#Formal-syntax" title="Up section"><img src="button-up.png" border="0" alt="Up: 7.1 Formal syntax" align="middle" width="32"></a></td>
7342 <td valign="middle" align="left"><a href="#Notes" title="Next chapter"><img src="button-right-right.png" border="0" alt="FastForward: Notes" align="middle" width="32"></a></td>
7343 <td valign="middle" align="left"><a href="#Top" title="Cover (top) of document"><img src="button-up-arrow.png" border="0" alt="Top: Revised(5) Report on the Algorithmic Language Scheme" align="middle" width="32"></a></td>
7344 <td valign="middle" align="left"><a href="#SEC_Contents" title="Table of contents"><img src="button-compass.png" border="0" alt="Contents: Table of Contents" align="middle" width="32"></a></td>
7345 <td valign="middle" align="left"><a href="#Index" title="Index"><img src="button-abc.png" border="0" alt="Index: Alphabetic index of definitions of concepts, keywords, and procedures" align="middle" width="32"></a></td>
7346 </tr></table>
7347 <a name="Expressions-1"></a>
7348 <h3 class="subsection">7.1.3 Expressions</h3>
7349
7350
7351
7352 <table><tr><td>&nbsp;</td><td><pre class="format">&lt;expression&gt; &ndash;&gt; &lt;variable&gt;
7353 | &lt;literal&gt;
7354 | &lt;procedure call&gt;
7355 | &lt;lambda expression&gt;
7356 | &lt;conditional&gt;
7357 | &lt;assignment&gt;
7358 | &lt;derived expression&gt;
7359 | &lt;macro use&gt;
7360 | &lt;macro block&gt;
7361
7362 &lt;literal&gt; &ndash;&gt; &lt;quotation&gt; | &lt;self-evaluating&gt;
7363 &lt;self-evaluating&gt; &ndash;&gt; &lt;boolean&gt; | &lt;number&gt;
7364 | &lt;character&gt; | &lt;string&gt;
7365 &lt;quotation&gt; &ndash;&gt; '&lt;datum&gt; | (quote &lt;datum&gt;)
7366 &lt;procedure call&gt; &ndash;&gt; (&lt;operator&gt; &lt;operand&gt;*)
7367 &lt;operator&gt; &ndash;&gt; &lt;expression&gt;
7368 &lt;operand&gt; &ndash;&gt; &lt;expression&gt;
7369
7370 &lt;lambda expression&gt; &ndash;&gt; (lambda &lt;formals&gt; &lt;body&gt;)
7371 &lt;formals&gt; &ndash;&gt; (&lt;variable&gt;*) | &lt;variable&gt;
7372 | (&lt;variable&gt;+ . &lt;variable&gt;)
7373 &lt;body&gt; &ndash;&gt; &lt;definition&gt;* &lt;sequence&gt;
7374 &lt;sequence&gt; &ndash;&gt; &lt;command&gt;* &lt;expression&gt;
7375 &lt;command&gt; &ndash;&gt; &lt;expression&gt;
7376
7377 &lt;conditional&gt; &ndash;&gt; (if &lt;test&gt; &lt;consequent&gt; &lt;alternate&gt;)
7378 &lt;test&gt; &ndash;&gt; &lt;expression&gt;
7379 &lt;consequent&gt; &ndash;&gt; &lt;expression&gt;
7380 &lt;alternate&gt; &ndash;&gt; &lt;expression&gt; | &lt;empty&gt;
7381
7382 &lt;assignment&gt; &ndash;&gt; (set! &lt;variable&gt; &lt;expression&gt;)
7383
7384 &lt;derived expression&gt; &ndash;&gt;
7385 (cond &lt;cond clause&gt;+)
7386 | (cond &lt;cond clause&gt;* (else &lt;sequence&gt;))
7387 | (case &lt;expression&gt;
7388 &lt;case clause&gt;+)
7389 | (case &lt;expression&gt;
7390 &lt;case clause&gt;*
7391 (else &lt;sequence&gt;))
7392 | (and &lt;test&gt;*)
7393 | (or &lt;test&gt;*)
7394 | (let (&lt;binding spec&gt;*) &lt;body&gt;)
7395 | (let &lt;variable&gt; (&lt;binding spec&gt;*) &lt;body&gt;)
7396 | (let* (&lt;binding spec&gt;*) &lt;body&gt;)
7397 | (letrec (&lt;binding spec&gt;*) &lt;body&gt;)
7398 | (begin &lt;sequence&gt;)
7399 | (do (&lt;iteration spec&gt;*)
7400 (&lt;test&gt; &lt;do result&gt;)
7401 &lt;command&gt;*)
7402 | (delay &lt;expression&gt;)
7403 | &lt;quasiquotation&gt;
7404
7405 &lt;cond clause&gt; &ndash;&gt; (&lt;test&gt; &lt;sequence&gt;)
7406 | (&lt;test&gt;)
7407 | (&lt;test&gt; =&gt; &lt;recipient&gt;)
7408 &lt;recipient&gt; &ndash;&gt; &lt;expression&gt;
7409 &lt;case clause&gt; &ndash;&gt; ((&lt;datum&gt;*) &lt;sequence&gt;)
7410 &lt;binding spec&gt; &ndash;&gt; (&lt;variable&gt; &lt;expression&gt;)
7411 &lt;iteration spec&gt; &ndash;&gt; (&lt;variable&gt; &lt;init&gt; &lt;step&gt;)
7412 | (&lt;variable&gt; &lt;init&gt;)
7413 &lt;init&gt; &ndash;&gt; &lt;expression&gt;
7414 &lt;step&gt; &ndash;&gt; &lt;expression&gt;
7415 &lt;do result&gt; &ndash;&gt; &lt;sequence&gt; | &lt;empty&gt;
7416
7417 &lt;macro use&gt; &ndash;&gt; (&lt;keyword&gt; &lt;datum&gt;*)
7418 &lt;keyword&gt; &ndash;&gt; &lt;identifier&gt;
7419
7420 &lt;macro block&gt; &ndash;&gt;
7421 (let-syntax (&lt;syntax spec&gt;*) &lt;body&gt;)
7422 | (letrec-syntax (&lt;syntax spec&gt;*) &lt;body&gt;)
7423 &lt;syntax spec&gt; &ndash;&gt; (&lt;keyword&gt; &lt;transformer spec&gt;)
7424 </pre></td></tr></table>
7425
7426
7427
7428 <a name="Quasiquotations"></a><hr size="1"><br/><br/><br/>
7429 <table cellpadding="1" cellspacing="1" border="0">
7430 <tr><td valign="middle" align="left"><a href="#Expression" title="Previous section in reading order"><img src="button-left.png" border="0" alt="Back: 7.1.3 Expressions" align="middle" width="32"></a></td>
7431 <td valign="middle" align="left"><a href="#Transformers" title="Next section in reading order"><img src="button-right.png" border="0" alt="Forward: 7.1.5 Transformers" align="middle" width="32"></a></td>
7432 <td valign="middle" align="left"> &nbsp; </td>
7433 <td valign="middle" align="left"><a href="#Formal-syntax-and-semantics" title="Beginning of this chapter or previous chapter"><img src="button-left-left.png" border="0" alt="FastBack: 7. Formal syntax and semantics" align="middle" width="32"></a></td>
7434 <td valign="middle" align="left"><a href="#Formal-syntax" title="Up section"><img src="button-up.png" border="0" alt="Up: 7.1 Formal syntax" align="middle" width="32"></a></td>
7435 <td valign="middle" align="left"><a href="#Notes" title="Next chapter"><img src="button-right-right.png" border="0" alt="FastForward: Notes" align="middle" width="32"></a></td>
7436 <td valign="middle" align="left"><a href="#Top" title="Cover (top) of document"><img src="button-up-arrow.png" border="0" alt="Top: Revised(5) Report on the Algorithmic Language Scheme" align="middle" width="32"></a></td>
7437 <td valign="middle" align="left"><a href="#SEC_Contents" title="Table of contents"><img src="button-compass.png" border="0" alt="Contents: Table of Contents" align="middle" width="32"></a></td>
7438 <td valign="middle" align="left"><a href="#Index" title="Index"><img src="button-abc.png" border="0" alt="Index: Alphabetic index of definitions of concepts, keywords, and procedures" align="middle" width="32"></a></td>
7439 </tr></table>
7440 <a name="Quasiquotations-1"></a>
7441 <h3 class="subsection">7.1.4 Quasiquotations</h3>
7442
7443
7444 <p>The following grammar for quasiquote expressions is not context-free.
7445 It is presented as a recipe for generating an infinite number of
7446 production rules. Imagine a copy of the following rules for D = 1, 2,3, &hellip;. D keeps track of the nesting depth.
7447 </p>
7448
7449 <table><tr><td>&nbsp;</td><td><pre class="format">&lt;quasiquotation&gt; &ndash;&gt; &lt;quasiquotation 1&gt;
7450 &lt;qq template 0&gt; &ndash;&gt; &lt;expression&gt;
7451 &lt;quasiquotation D&gt; &ndash;&gt; &lsquo;&lt;qq template D&gt;
7452 | (quasiquote &lt;qq template D&gt;)
7453 &lt;qq template D&gt; &ndash;&gt; &lt;simple datum&gt;
7454 | &lt;list qq template D&gt;
7455 | &lt;vector qq template D&gt;
7456 | &lt;unquotation D&gt;
7457 &lt;list qq template D&gt; &ndash;&gt; (&lt;qq template or splice D&gt;*)
7458 | (&lt;qq template or splice D&gt;+ . &lt;qq template D&gt;)
7459 | '&lt;qq template D&gt;
7460 | &lt;quasiquotation D+1&gt;
7461 &lt;vector qq template D&gt; &ndash;&gt; #(&lt;qq template or splice D&gt;*)
7462 &lt;unquotation D&gt; &ndash;&gt; ,&lt;qq template D-1&gt;
7463 | (unquote &lt;qq template D-1&gt;)
7464 &lt;qq template or splice D&gt; &ndash;&gt; &lt;qq template D&gt;
7465 | &lt;splicing unquotation D&gt;
7466 &lt;splicing unquotation D&gt; &ndash;&gt; ,@&lt;qq template D-1&gt;
7467 | (unquote-splicing &lt;qq template D-1&gt;)
7468 </pre></td></tr></table>
7469
7470
7471
7472 <p>In &lt;quasiquotation&gt;s, a &lt;list qq template D&gt; can sometimes
7473 be confused with either an &lt;unquotation D&gt; or a &lt;splicing
7474 unquotation D&gt;. The interpretation as an
7475 &lt;unquotation&gt; or &lt;splicing
7476 unquotation D&gt; takes precedence.
7477 </p>
7478 <a name="Transformers"></a><hr size="1"><br/><br/><br/>
7479 <table cellpadding="1" cellspacing="1" border="0">
7480 <tr><td valign="middle" align="left"><a href="#Quasiquotations" title="Previous section in reading order"><img src="button-left.png" border="0" alt="Back: 7.1.4 Quasiquotations" align="middle" width="32"></a></td>
7481 <td valign="middle" align="left"><a href="#Programs-and-definitions" title="Next section in reading order"><img src="button-right.png" border="0" alt="Forward: 7.1.6 Programs and definitions" align="middle" width="32"></a></td>
7482 <td valign="middle" align="left"> &nbsp; </td>
7483 <td valign="middle" align="left"><a href="#Formal-syntax-and-semantics" title="Beginning of this chapter or previous chapter"><img src="button-left-left.png" border="0" alt="FastBack: 7. Formal syntax and semantics" align="middle" width="32"></a></td>
7484 <td valign="middle" align="left"><a href="#Formal-syntax" title="Up section"><img src="button-up.png" border="0" alt="Up: 7.1 Formal syntax" align="middle" width="32"></a></td>
7485 <td valign="middle" align="left"><a href="#Notes" title="Next chapter"><img src="button-right-right.png" border="0" alt="FastForward: Notes" align="middle" width="32"></a></td>
7486 <td valign="middle" align="left"><a href="#Top" title="Cover (top) of document"><img src="button-up-arrow.png" border="0" alt="Top: Revised(5) Report on the Algorithmic Language Scheme" align="middle" width="32"></a></td>
7487 <td valign="middle" align="left"><a href="#SEC_Contents" title="Table of contents"><img src="button-compass.png" border="0" alt="Contents: Table of Contents" align="middle" width="32"></a></td>
7488 <td valign="middle" align="left"><a href="#Index" title="Index"><img src="button-abc.png" border="0" alt="Index: Alphabetic index of definitions of concepts, keywords, and procedures" align="middle" width="32"></a></td>
7489 </tr></table>
7490 <a name="Transformers-1"></a>
7491 <h3 class="subsection">7.1.5 Transformers</h3>
7492
7493
7494
7495 <table><tr><td>&nbsp;</td><td><pre class="format">&lt;transformer spec&gt; &ndash;&gt;
7496 (syntax-rules (&lt;identifier&gt;*) &lt;syntax rule&gt;*)
7497 &lt;syntax rule&gt; &ndash;&gt; (&lt;pattern&gt; &lt;template&gt;)
7498 &lt;pattern&gt; &ndash;&gt; &lt;pattern identifier&gt;
7499 | (&lt;pattern&gt;*)
7500 | (&lt;pattern&gt;+ . &lt;pattern&gt;)
7501 | (&lt;pattern&gt;* &lt;pattern&gt; &lt;ellipsis&gt;)
7502 | #(&lt;pattern&gt;*)
7503 | #(&lt;pattern&gt;* &lt;pattern&gt; &lt;ellipsis&gt;)
7504 | &lt;pattern datum&gt;
7505 &lt;pattern datum&gt; &ndash;&gt; &lt;string&gt;
7506 | &lt;character&gt;
7507 | &lt;boolean&gt;
7508 | &lt;number&gt;
7509 &lt;template&gt; &ndash;&gt; &lt;pattern identifier&gt;
7510 | (&lt;template element&gt;*)
7511 | (&lt;template element&gt;+ . &lt;template&gt;)
7512 | #(&lt;template element&gt;*)
7513 | &lt;template datum&gt;
7514 &lt;template element&gt; &ndash;&gt; &lt;template&gt;
7515 | &lt;template&gt; &lt;ellipsis&gt;
7516 &lt;template datum&gt; &ndash;&gt; &lt;pattern datum&gt;
7517 &lt;pattern identifier&gt; &ndash;&gt; &lt;any identifier except <samp>...</samp>&gt;
7518 &lt;ellipsis&gt; &ndash;&gt; &lt;the identifier <samp>...</samp>&gt;
7519 </pre></td></tr></table>
7520
7521
7522
7523 <a name="Programs-and-definitions"></a><hr size="1"><br/><br/><br/>
7524 <table cellpadding="1" cellspacing="1" border="0">
7525 <tr><td valign="middle" align="left"><a href="#Transformers" title="Previous section in reading order"><img src="button-left.png" border="0" alt="Back: 7.1.5 Transformers" align="middle" width="32"></a></td>
7526 <td valign="middle" align="left"><a href="#Formal-semantics" title="Next section in reading order"><img src="button-right.png" border="0" alt="Forward: 7.2 Formal semantics" align="middle" width="32"></a></td>
7527 <td valign="middle" align="left"> &nbsp; </td>
7528 <td valign="middle" align="left"><a href="#Formal-syntax-and-semantics" title="Beginning of this chapter or previous chapter"><img src="button-left-left.png" border="0" alt="FastBack: 7. Formal syntax and semantics" align="middle" width="32"></a></td>
7529 <td valign="middle" align="left"><a href="#Formal-syntax" title="Up section"><img src="button-up.png" border="0" alt="Up: 7.1 Formal syntax" align="middle" width="32"></a></td>
7530 <td valign="middle" align="left"><a href="#Notes" title="Next chapter"><img src="button-right-right.png" border="0" alt="FastForward: Notes" align="middle" width="32"></a></td>
7531 <td valign="middle" align="left"><a href="#Top" title="Cover (top) of document"><img src="button-up-arrow.png" border="0" alt="Top: Revised(5) Report on the Algorithmic Language Scheme" align="middle" width="32"></a></td>
7532 <td valign="middle" align="left"><a href="#SEC_Contents" title="Table of contents"><img src="button-compass.png" border="0" alt="Contents: Table of Contents" align="middle" width="32"></a></td>
7533 <td valign="middle" align="left"><a href="#Index" title="Index"><img src="button-abc.png" border="0" alt="Index: Alphabetic index of definitions of concepts, keywords, and procedures" align="middle" width="32"></a></td>
7534 </tr></table>
7535 <a name="Programs-and-definitions-1"></a>
7536 <h3 class="subsection">7.1.6 Programs and definitions</h3>
7537
7538
7539
7540 <table><tr><td>&nbsp;</td><td><pre class="format">&lt;program&gt; &ndash;&gt; &lt;command or definition&gt;*
7541 &lt;command or definition&gt; &ndash;&gt; &lt;command&gt;
7542 | &lt;definition&gt;
7543 | &lt;syntax definition&gt;
7544 | (begin &lt;command or definition&gt;+)
7545 &lt;definition&gt; &ndash;&gt; (define &lt;variable&gt; &lt;expression&gt;)
7546 | (define (&lt;variable&gt; &lt;def formals&gt;) &lt;body&gt;)
7547 | (begin &lt;definition&gt;*)
7548 &lt;def formals&gt; &ndash;&gt; &lt;variable&gt;*
7549 | &lt;variable&gt;* . &lt;variable&gt;
7550 &lt;syntax definition&gt; &ndash;&gt;
7551 (define-syntax &lt;keyword&gt; &lt;transformer spec&gt;)
7552 </pre></td></tr></table>
7553
7554
7555
7556 <a name="Formal-semantics"></a><hr size="1"><br/><br/><br/>
7557 <table cellpadding="1" cellspacing="1" border="0">
7558 <tr><td valign="middle" align="left"><a href="#Programs-and-definitions" title="Previous section in reading order"><img src="button-left.png" border="0" alt="Back: 7.1.6 Programs and definitions" align="middle" width="32"></a></td>
7559 <td valign="middle" align="left"><a href="#Derived-expression-type" title="Next section in reading order"><img src="button-right.png" border="0" alt="Forward: 7.3 Derived expression types" align="middle" width="32"></a></td>
7560 <td valign="middle" align="left"> &nbsp; </td>
7561 <td valign="middle" align="left"><a href="#Formal-syntax-and-semantics" title="Beginning of this chapter or previous chapter"><img src="button-left-left.png" border="0" alt="FastBack: 7. Formal syntax and semantics" align="middle" width="32"></a></td>
7562 <td valign="middle" align="left"><a href="#Formal-syntax-and-semantics" title="Up section"><img src="button-up.png" border="0" alt="Up: 7. Formal syntax and semantics" align="middle" width="32"></a></td>
7563 <td valign="middle" align="left"><a href="#Notes" title="Next chapter"><img src="button-right-right.png" border="0" alt="FastForward: Notes" align="middle" width="32"></a></td>
7564 <td valign="middle" align="left"><a href="#Top" title="Cover (top) of document"><img src="button-up-arrow.png" border="0" alt="Top: Revised(5) Report on the Algorithmic Language Scheme" align="middle" width="32"></a></td>
7565 <td valign="middle" align="left"><a href="#SEC_Contents" title="Table of contents"><img src="button-compass.png" border="0" alt="Contents: Table of Contents" align="middle" width="32"></a></td>
7566 <td valign="middle" align="left"><a href="#Index" title="Index"><img src="button-abc.png" border="0" alt="Index: Alphabetic index of definitions of concepts, keywords, and procedures" align="middle" width="32"></a></td>
7567 </tr></table>
7568 <a name="Formal-semantics-1"></a>
7569 <h2 class="section">7.2 Formal semantics</h2>
7570
7571
7572 <p>This section provides a formal denotational semantics for the primitive
7573 expressions of Scheme and selected built-in procedures. The concepts
7574 and notation used here are described in <small>[STOY77]</small>.
7575 </p>
7576 <blockquote><p><em>Note:</em> The formal semantics section was written in LaTeX which
7577 is incompatible with TeXinfo. See the Formal semantics section of
7578 the original document from which this was derived.
7579 </p></blockquote>
7580
7581
7582 <a name="Derived-expression-type"></a><hr size="1"><br/><br/><br/>
7583 <table cellpadding="1" cellspacing="1" border="0">
7584 <tr><td valign="middle" align="left"><a href="#Formal-semantics" title="Previous section in reading order"><img src="button-left.png" border="0" alt="Back: 7.2 Formal semantics" align="middle" width="32"></a></td>
7585 <td valign="middle" align="left"><a href="#Notes" title="Next section in reading order"><img src="button-right.png" border="0" alt="Forward: Notes" align="middle" width="32"></a></td>
7586 <td valign="middle" align="left"> &nbsp; </td>
7587 <td valign="middle" align="left"><a href="#Formal-syntax-and-semantics" title="Beginning of this chapter or previous chapter"><img src="button-left-left.png" border="0" alt="FastBack: 7. Formal syntax and semantics" align="middle" width="32"></a></td>
7588 <td valign="middle" align="left"><a href="#Formal-syntax-and-semantics" title="Up section"><img src="button-up.png" border="0" alt="Up: 7. Formal syntax and semantics" align="middle" width="32"></a></td>
7589 <td valign="middle" align="left"><a href="#Notes" title="Next chapter"><img src="button-right-right.png" border="0" alt="FastForward: Notes" align="middle" width="32"></a></td>
7590 <td valign="middle" align="left"><a href="#Top" title="Cover (top) of document"><img src="button-up-arrow.png" border="0" alt="Top: Revised(5) Report on the Algorithmic Language Scheme" align="middle" width="32"></a></td>
7591 <td valign="middle" align="left"><a href="#SEC_Contents" title="Table of contents"><img src="button-compass.png" border="0" alt="Contents: Table of Contents" align="middle" width="32"></a></td>
7592 <td valign="middle" align="left"><a href="#Index" title="Index"><img src="button-abc.png" border="0" alt="Index: Alphabetic index of definitions of concepts, keywords, and procedures" align="middle" width="32"></a></td>
7593 </tr></table>
7594 <a name="Derived-expression-types-2"></a>
7595 <h2 class="section">7.3 Derived expression types</h2>
7596
7597
7598
7599 <p>This section gives macro definitions for the derived expression types in
7600 terms of the primitive expression types (literal, variable, call, <samp>lambda</samp>,
7601 <samp>if</samp>, <samp>set!</samp>). See section <a href="#Control-features">Control features</a> for a possible
7602 definition of <samp>delay</samp>.
7603 </p>
7604
7605 <table><tr><td>&nbsp;</td><td><pre class="example">
7606 (define-syntax cond
7607 (syntax-rules (else =&gt;)
7608 ((cond (else result1 result2 ...))
7609 (begin result1 result2 ...))
7610 ((cond (test =&gt; result))
7611 (let ((temp test))
7612 (if temp (result temp))))
7613 ((cond (test =&gt; result) clause1 clause2 ...)
7614 (let ((temp test))
7615 (if temp
7616 (result temp)
7617 (cond clause1 clause2 ...))))
7618 ((cond (test)) test)
7619 ((cond (test) clause1 clause2 ...)
7620 (let ((temp test))
7621 (if temp
7622 temp
7623 (cond clause1 clause2 ...))))
7624 ((cond (test result1 result2 ...))
7625 (if test (begin result1 result2 ...)))
7626 ((cond (test result1 result2 ...)
7627 clause1 clause2 ...)
7628 (if test
7629 (begin result1 result2 ...)
7630 (cond clause1 clause2 ...)))))
7631 </pre></td></tr></table>
7632
7633
7634
7635 <table><tr><td>&nbsp;</td><td><pre class="example">
7636 (define-syntax case
7637 (syntax-rules (else)
7638 ((case (key ...)
7639 clauses ...)
7640 (let ((atom-key (key ...)))
7641 (case atom-key clauses ...)))
7642 ((case key
7643 (else result1 result2 ...))
7644 (begin result1 result2 ...))
7645 ((case key
7646 ((atoms ...) result1 result2 ...))
7647 (if (memv key '(atoms ...))
7648 (begin result1 result2 ...)))
7649 ((case key
7650 ((atoms ...) result1 result2 ...)
7651 clause clauses ...)
7652 (if (memv key '(atoms ...))
7653 (begin result1 result2 ...)
7654 (case key clause clauses ...)))))
7655 </pre></td></tr></table>
7656
7657
7658
7659 <table><tr><td>&nbsp;</td><td><pre class="example">
7660 (define-syntax and
7661 (syntax-rules ()
7662 ((and) #t)
7663 ((and test) test)
7664 ((and test1 test2 ...)
7665 (if test1 (and test2 ...) #f))))
7666 </pre></td></tr></table>
7667
7668
7669
7670 <table><tr><td>&nbsp;</td><td><pre class="example">
7671 (define-syntax or
7672 (syntax-rules ()
7673 ((or) #f)
7674 ((or test) test)
7675 ((or test1 test2 ...)
7676 (let ((x test1))
7677 (if x x (or test2 ...))))))
7678 </pre></td></tr></table>
7679
7680
7681
7682 <table><tr><td>&nbsp;</td><td><pre class="example">
7683 (define-syntax let
7684 (syntax-rules ()
7685 ((let ((name val) ...) body1 body2 ...)
7686 ((lambda (name ...) body1 body2 ...)
7687 val ...))
7688 ((let tag ((name val) ...) body1 body2 ...)
7689 ((letrec ((tag (lambda (name ...)
7690 body1 body2 ...)))
7691 tag)
7692 val ...))))
7693 </pre></td></tr></table>
7694
7695
7696
7697 <table><tr><td>&nbsp;</td><td><pre class="example">
7698 (define-syntax let*
7699 (syntax-rules ()
7700 ((let* () body1 body2 ...)
7701 (let () body1 body2 ...))
7702 ((let* ((name1 val1) (name2 val2) ...)
7703 body1 body2 ...)
7704 (let ((name1 val1))
7705 (let* ((name2 val2) ...)
7706 body1 body2 ...)))))
7707 </pre></td></tr></table>
7708
7709
7710 <p>The following <samp>letrec</samp> macro uses the symbol <samp>&lt;undefined&gt;</samp>
7711 in place of an expression which returns something that when stored in
7712 a location makes it an error to try to obtain the value stored in the
7713 location (no such expression is defined in Scheme).
7714 A trick is used to generate the temporary names needed to avoid
7715 specifying the order in which the values are evaluated.
7716 This could also be accomplished by using an auxiliary macro.
7717 </p>
7718
7719 <table><tr><td>&nbsp;</td><td><pre class="example">
7720 (define-syntax letrec
7721 (syntax-rules ()
7722 ((letrec ((var1 init1) ...) body ...)
7723 (letrec &quot;generate temp names&quot;
7724 (var1 ...)
7725 ()
7726 ((var1 init1) ...)
7727 body ...))
7728 ((letrec &quot;generate temp names&quot;
7729 ()
7730 (temp1 ...)
7731 ((var1 init1) ...)
7732 body ...)
7733 (let ((var1 &lt;undefined&gt;) ...)
7734 (let ((temp1 init1) ...)
7735 (set! var1 temp1)
7736 ...
7737 body ...)))
7738 ((letrec &quot;generate temp names&quot;
7739 (x y ...)
7740 (temp ...)
7741 ((var1 init1) ...)
7742 body ...)
7743 (letrec &quot;generate temp names&quot;
7744 (y ...)
7745 (newtemp temp ...)
7746 ((var1 init1) ...)
7747 body ...))))
7748 </pre></td></tr></table>
7749
7750
7751
7752 <table><tr><td>&nbsp;</td><td><pre class="example">
7753 (define-syntax begin
7754 (syntax-rules ()
7755 ((begin exp ...)
7756 ((lambda () exp ...)))))
7757 </pre></td></tr></table>
7758
7759
7760 <p>The following alternative expansion for <samp>begin</samp> does not make use of
7761 the ability to write more than one expression in the body of a lambda
7762 expression. In any case, note that these rules apply only if the body
7763 of the <samp>begin</samp> contains no definitions.
7764 </p>
7765
7766 <table><tr><td>&nbsp;</td><td><pre class="example">
7767 (define-syntax begin
7768 (syntax-rules ()
7769 ((begin exp)
7770 exp)
7771 ((begin exp1 exp2 ...)
7772 (let ((x exp1))
7773 (begin exp2 ...)))))
7774 </pre></td></tr></table>
7775
7776
7777 <p>The following definition
7778 of <samp>do</samp> uses a trick to expand the variable clauses.
7779 As with <samp>letrec</samp> above, an auxiliary macro would also work.
7780 The expression <samp>(if #f #f)</samp> is used to obtain an unspecific
7781 value.
7782 </p>
7783
7784 <table><tr><td>&nbsp;</td><td><pre class="example">
7785 (define-syntax do
7786 (syntax-rules ()
7787 ((do ((var init step ...) ...)
7788 (test expr ...)
7789 command ...)
7790 (letrec
7791 ((loop
7792 (lambda (var ...)
7793 (if test
7794 (begin
7795 (if #f #f)
7796 expr ...)
7797 (begin
7798 command
7799 ...
7800 (loop (do &quot;step&quot; var step ...)
7801 ...))))))
7802 (loop init ...)))
7803 ((do &quot;step&quot; x)
7804 x)
7805 ((do &quot;step&quot; x y)
7806 y)))
7807 </pre></td></tr></table>
7808
7809
7810
7811
7812
7813 <a name="Notes"></a><hr size="1"><br/><br/><br/>
7814 <table cellpadding="1" cellspacing="1" border="0">
7815 <tr><td valign="middle" align="left"><a href="#Derived-expression-type" title="Previous section in reading order"><img src="button-left.png" border="0" alt="Back: 7.3 Derived expression types" align="middle" width="32"></a></td>
7816 <td valign="middle" align="left"><a href="#Language-changes" title="Next section in reading order"><img src="button-right.png" border="0" alt="Forward: Language changes" align="middle" width="32"></a></td>
7817 <td valign="middle" align="left"> &nbsp; </td>
7818 <td valign="middle" align="left"><a href="#Formal-syntax-and-semantics" title="Beginning of this chapter or previous chapter"><img src="button-left-left.png" border="0" alt="FastBack: 7. Formal syntax and semantics" align="middle" width="32"></a></td>
7819 <td valign="middle" align="left"><a href="#Top" title="Up section"><img src="button-up.png" border="0" alt="Up: Revised(5) Report on the Algorithmic Language Scheme" align="middle" width="32"></a></td>
7820 <td valign="middle" align="left"><a href="#Additional-material" title="Next chapter"><img src="button-right-right.png" border="0" alt="FastForward: Additional material" align="middle" width="32"></a></td>
7821 <td valign="middle" align="left"><a href="#Top" title="Cover (top) of document"><img src="button-up-arrow.png" border="0" alt="Top: Revised(5) Report on the Algorithmic Language Scheme" align="middle" width="32"></a></td>
7822 <td valign="middle" align="left"><a href="#SEC_Contents" title="Table of contents"><img src="button-compass.png" border="0" alt="Contents: Table of Contents" align="middle" width="32"></a></td>
7823 <td valign="middle" align="left"><a href="#Index" title="Index"><img src="button-abc.png" border="0" alt="Index: Alphabetic index of definitions of concepts, keywords, and procedures" align="middle" width="32"></a></td>
7824 </tr></table>
7825 <a name="Notes-1"></a>
7826 <h1 class="unnumbered">Notes</h1>
7827
7828 <table class="menu" border="0" cellspacing="0">
7829 <tr><td align="left" valign="top"><a href="#Language-changes">Language changes</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
7830 </td></tr>
7831 </table>
7832
7833
7834
7835
7836
7837 <a name="Language-changes"></a><hr size="1"><br/><br/><br/>
7838 <table cellpadding="1" cellspacing="1" border="0">
7839 <tr><td valign="middle" align="left"><a href="#Notes" title="Previous section in reading order"><img src="button-left.png" border="0" alt="Back: Notes" align="middle" width="32"></a></td>
7840 <td valign="middle" align="left"><a href="#Additional-material" title="Next section in reading order"><img src="button-right.png" border="0" alt="Forward: Additional material" align="middle" width="32"></a></td>
7841 <td valign="middle" align="left"> &nbsp; </td>
7842 <td valign="middle" align="left"><a href="#Notes" title="Beginning of this chapter or previous chapter"><img src="button-left-left.png" border="0" alt="FastBack: Notes" align="middle" width="32"></a></td>
7843 <td valign="middle" align="left"><a href="#Notes" title="Up section"><img src="button-up.png" border="0" alt="Up: Notes" align="middle" width="32"></a></td>
7844 <td valign="middle" align="left"><a href="#Additional-material" title="Next chapter"><img src="button-right-right.png" border="0" alt="FastForward: Additional material" align="middle" width="32"></a></td>
7845 <td valign="middle" align="left"><a href="#Top" title="Cover (top) of document"><img src="button-up-arrow.png" border="0" alt="Top: Revised(5) Report on the Algorithmic Language Scheme" align="middle" width="32"></a></td>
7846 <td valign="middle" align="left"><a href="#SEC_Contents" title="Table of contents"><img src="button-compass.png" border="0" alt="Contents: Table of Contents" align="middle" width="32"></a></td>
7847 <td valign="middle" align="left"><a href="#Index" title="Index"><img src="button-abc.png" border="0" alt="Index: Alphabetic index of definitions of concepts, keywords, and procedures" align="middle" width="32"></a></td>
7848 </tr></table>
7849 <a name="Language-changes-1"></a>
7850 <h2 class="unnumberedsec">Language changes</h2>
7851
7852
7853
7854 <p>This section enumerates the changes that have been made to Scheme since
7855 the &ldquo;Revised^4 report&rdquo; [R4RS] was published.
7856 </p>
7857
7858
7859 <ul>
7860 <li>
7861 The report is now a superset of the IEEE standard for Scheme
7862 [IEEEScheme]: implementations that conform to the report will
7863 also conform to the standard. This required the following changes:
7864
7865
7866 <ul>
7867 <li>
7868 The empty list is now required to count as true.
7869
7870 </li><li>
7871 The classification of features as essential or inessential has been
7872 removed. There are now three classes of built-in procedures: primitive,
7873 library, and optional. The optional procedures are <samp>load</samp>,
7874 <samp>with-input-from-file</samp>, <samp>with-output-to-file</samp>,
7875 <samp>transcript-on</samp>, <samp>transcript-off</samp>, and
7876 <samp>interaction-environment</samp>,
7877 and <samp>-</samp> and <samp>/</samp> with more than two arguments.
7878 None of these are in the IEEE standard.
7879
7880 </li><li>
7881 Programs are allowed to redefine built-in procedures. Doing so
7882 will not change the behavior of other built-in procedures.
7883
7884 </li></ul>
7885
7886
7887 </li><li>
7888 <em>Port</em> has been added to the list of disjoint types.
7889
7890 </li><li>
7891 The macro appendix has been removed. High-level macros are now part
7892 of the main body of the report. The rewrite rules for derived expressions
7893 have been replaced with macro definitions. There are no reserved identifiers.
7894
7895 </li><li>
7896 <samp>Syntax-rules</samp> now allows vector patterns.
7897
7898 </li><li>
7899 Multiple-value returns, <samp>eval</samp>, and <samp>dynamic-wind</samp> have
7900 been added.
7901
7902 </li><li>
7903 The calls that are required to be implemented in a properly tail-recursive
7904 fashion are defined explicitly.
7905
7906 </li><li>
7907 &lsquo;<samp>@</samp>' can be used within identifiers. &lsquo;<samp>|</samp>' is reserved
7908 for possible future extensions.
7909
7910
7911 </li></ul>
7912
7913
7914
7915
7916
7917
7918
7919
7920
7921
7922
7923
7924
7925
7926
7927 <a name="Additional-material"></a><hr size="1"><br/><br/><br/>
7928 <table cellpadding="1" cellspacing="1" border="0">
7929 <tr><td valign="middle" align="left"><a href="#Language-changes" title="Previous section in reading order"><img src="button-left.png" border="0" alt="Back: Language changes" align="middle" width="32"></a></td>
7930 <td valign="middle" align="left"><a href="#Example" title="Next section in reading order"><img src="button-right.png" border="0" alt="Forward: Example" align="middle" width="32"></a></td>
7931 <td valign="middle" align="left"> &nbsp; </td>
7932 <td valign="middle" align="left"><a href="#Notes" title="Beginning of this chapter or previous chapter"><img src="button-left-left.png" border="0" alt="FastBack: Notes" align="middle" width="32"></a></td>
7933 <td valign="middle" align="left"><a href="#Top" title="Up section"><img src="button-up.png" border="0" alt="Up: Revised(5) Report on the Algorithmic Language Scheme" align="middle" width="32"></a></td>
7934 <td valign="middle" align="left"><a href="#Example" title="Next chapter"><img src="button-right-right.png" border="0" alt="FastForward: Example" align="middle" width="32"></a></td>
7935 <td valign="middle" align="left"><a href="#Top" title="Cover (top) of document"><img src="button-up-arrow.png" border="0" alt="Top: Revised(5) Report on the Algorithmic Language Scheme" align="middle" width="32"></a></td>
7936 <td valign="middle" align="left"><a href="#SEC_Contents" title="Table of contents"><img src="button-compass.png" border="0" alt="Contents: Table of Contents" align="middle" width="32"></a></td>
7937 <td valign="middle" align="left"><a href="#Index" title="Index"><img src="button-abc.png" border="0" alt="Index: Alphabetic index of definitions of concepts, keywords, and procedures" align="middle" width="32"></a></td>
7938 </tr></table>
7939 <a name="Additional-material-1"></a>
7940 <h1 class="unnumbered">Additional material</h1>
7941
7942
7943 <p>The Internet Scheme Repository at
7944 </p>
7945
7946 <p align="center"> <a href="http://www.cs.indiana.edu/scheme-repository/">http://www.cs.indiana.edu/scheme-repository/</a>
7947 </p>
7948
7949 <p>contains an extensive Scheme bibliography, as well as papers,
7950 programs, implementations, and other material related to Scheme.
7951 </p>
7952
7953
7954
7955 <a name="Example"></a><hr size="1"><br/><br/><br/>
7956 <table cellpadding="1" cellspacing="1" border="0">
7957 <tr><td valign="middle" align="left"><a href="#Additional-material" title="Previous section in reading order"><img src="button-left.png" border="0" alt="Back: Additional material" align="middle" width="32"></a></td>
7958 <td valign="middle" align="left"><a href="#Bibliography" title="Next section in reading order"><img src="button-right.png" border="0" alt="Forward: Bibliography" align="middle" width="32"></a></td>
7959 <td valign="middle" align="left"> &nbsp; </td>
7960 <td valign="middle" align="left"><a href="#Additional-material" title="Beginning of this chapter or previous chapter"><img src="button-left-left.png" border="0" alt="FastBack: Additional material" align="middle" width="32"></a></td>
7961 <td valign="middle" align="left"><a href="#Top" title="Up section"><img src="button-up.png" border="0" alt="Up: Revised(5) Report on the Algorithmic Language Scheme" align="middle" width="32"></a></td>
7962 <td valign="middle" align="left"><a href="#Bibliography" title="Next chapter"><img src="button-right-right.png" border="0" alt="FastForward: Bibliography" align="middle" width="32"></a></td>
7963 <td valign="middle" align="left"><a href="#Top" title="Cover (top) of document"><img src="button-up-arrow.png" border="0" alt="Top: Revised(5) Report on the Algorithmic Language Scheme" align="middle" width="32"></a></td>
7964 <td valign="middle" align="left"><a href="#SEC_Contents" title="Table of contents"><img src="button-compass.png" border="0" alt="Contents: Table of Contents" align="middle" width="32"></a></td>
7965 <td valign="middle" align="left"><a href="#Index" title="Index"><img src="button-abc.png" border="0" alt="Index: Alphabetic index of definitions of concepts, keywords, and procedures" align="middle" width="32"></a></td>
7966 </tr></table>
7967 <a name="Example-1"></a>
7968 <h1 class="unnumbered">Example</h1>
7969
7970
7971
7972 <p><samp>Integrate-system</samp> integrates the system
7973 </p>
7974
7975 <p align="center"> y_k^^ = f_k(y_1, y_2, &hellip; y_n), k = 1, &hellip; n
7976 </p>
7977 <p>of differential equations with the method of Runge-Kutta.
7978 </p>
7979 <p>The parameter <tt>system-derivative</tt> is a function that takes a system
7980 state (a vector of values for the state variables y_1, &hellip; y_n)
7981 and produces a system derivative (the values y_1^^, &hellip;y_n^^). The parameter <tt>initial-state</tt> provides an initial
7982 system state, and <tt>h</tt> is an initial guess for the length of the
7983 integration step.
7984 </p>
7985 <p>The value returned by <samp>integrate-system</samp> is an infinite stream of
7986 system states.
7987 </p>
7988
7989 <table><tr><td>&nbsp;</td><td><pre class="example">
7990 (define integrate-system
7991 (lambda (system-derivative initial-state h)
7992 (let ((next (runge-kutta-4 system-derivative h)))
7993 (letrec ((states
7994 (cons initial-state
7995 (delay (map-streams next
7996 states)))))
7997 states))))
7998 </pre></td></tr></table>
7999
8000
8001 <p><samp>Runge-Kutta-4</samp> takes a function, <tt>f</tt>, that produces a
8002 system derivative from a system state. <samp>Runge-Kutta-4</samp>
8003 produces a function that takes a system state and
8004 produces a new system state.
8005 </p>
8006
8007 <table><tr><td>&nbsp;</td><td><pre class="example">
8008 (define runge-kutta-4
8009 (lambda (f h)
8010 (let ((*h (scale-vector h))
8011 (*2 (scale-vector 2))
8012 (*1/2 (scale-vector (/ 1 2)))
8013 (*1/6 (scale-vector (/ 1 6))))
8014 (lambda (y)
8015 ;; y <span class="roman"></span>is a system state
8016 (let* ((k0 (*h (f y)))
8017 (k1 (*h (f (add-vectors y (*1/2 k0)))))
8018 (k2 (*h (f (add-vectors y (*1/2 k1)))))
8019 (k3 (*h (f (add-vectors y k2)))))
8020 (add-vectors y
8021 (*1/6 (add-vectors k0
8022 (*2 k1)
8023 (*2 k2)
8024 k3))))))))
8025
8026 (define elementwise
8027 (lambda (f)
8028 (lambda vectors
8029 (generate-vector
8030 (vector-length (car vectors))
8031 (lambda (i)
8032 (apply f
8033 (map (lambda (v) (vector-ref v i))
8034 vectors)))))))
8035
8036 (define generate-vector
8037 (lambda (size proc)
8038 (let ((ans (make-vector size)))
8039 (letrec ((loop
8040 (lambda (i)
8041 (cond ((= i size) ans)
8042 (else
8043 (vector-set! ans i (proc i))
8044 (loop (+ i 1)))))))
8045 (loop 0)))))
8046
8047 (define add-vectors (elementwise +))
8048
8049 (define scale-vector
8050 (lambda (s)
8051 (elementwise (lambda (x) (* x s)))))
8052 </pre></td></tr></table>
8053
8054
8055 <p><samp>Map-streams</samp> is analogous to <samp>map</samp>: it applies its first
8056 argument (a procedure) to all the elements of its second argument (a
8057 stream).
8058 </p>
8059
8060 <table><tr><td>&nbsp;</td><td><pre class="example">
8061 (define map-streams
8062 (lambda (f s)
8063 (cons (f (head s))
8064 (delay (map-streams f (tail s))))))
8065 </pre></td></tr></table>
8066
8067
8068 <p>Infinite streams are implemented as pairs whose car holds the first
8069 element of the stream and whose cdr holds a promise to deliver the rest
8070 of the stream.
8071 </p>
8072
8073 <table><tr><td>&nbsp;</td><td><pre class="example">
8074 (define head car)
8075 (define tail
8076 (lambda (stream) (force (cdr stream))))
8077 </pre></td></tr></table>
8078
8079
8080 <br>
8081 <br>
8082 <br>
8083 <br>
8084 <br>
8085 <br>
8086 <p>The following illustrates the use of <samp>integrate-system</samp> in
8087 integrating the system
8088 </p>
8089
8090 <p align="center"> C dv_C / dt = -i_L - v_C / R
8091 </p>
8092
8093
8094 <p align="center"> L di_L / dt = v_C
8095 </p>
8096 <p>which models a damped oscillator.
8097 </p>
8098
8099 <table><tr><td>&nbsp;</td><td><pre class="example">
8100 (define damped-oscillator
8101 (lambda (R L C)
8102 (lambda (state)
8103 (let ((Vc (vector-ref state 0))
8104 (Il (vector-ref state 1)))
8105 (vector (- 0 (+ (/ Vc (* R C)) (/ Il C)))
8106 (/ Vc L))))))
8107
8108 (define the-states
8109 (integrate-system
8110 (damped-oscillator 10000 1000 .001)
8111 '#(1 0)
8112 .01))
8113 </pre></td></tr></table>
8114
8115
8116
8117
8118
8119
8120
8121
8122
8123
8124
8125
8126
8127 <a name="Bibliography"></a><hr size="1"><br/><br/><br/>
8128 <table cellpadding="1" cellspacing="1" border="0">
8129 <tr><td valign="middle" align="left"><a href="#Example" title="Previous section in reading order"><img src="button-left.png" border="0" alt="Back: Example" align="middle" width="32"></a></td>
8130 <td valign="middle" align="left"><a href="#Index" title="Next section in reading order"><img src="button-right.png" border="0" alt="Forward: Alphabetic index of definitions of concepts, keywords, and procedures" align="middle" width="32"></a></td>
8131 <td valign="middle" align="left"> &nbsp; </td>
8132 <td valign="middle" align="left"><a href="#Example" title="Beginning of this chapter or previous chapter"><img src="button-left-left.png" border="0" alt="FastBack: Example" align="middle" width="32"></a></td>
8133 <td valign="middle" align="left"><a href="#Top" title="Up section"><img src="button-up.png" border="0" alt="Up: Revised(5) Report on the Algorithmic Language Scheme" align="middle" width="32"></a></td>
8134 <td valign="middle" align="left"><a href="#Index" title="Next chapter"><img src="button-right-right.png" border="0" alt="FastForward: Alphabetic index of definitions of concepts, keywords, and procedures" align="middle" width="32"></a></td>
8135 <td valign="middle" align="left"><a href="#Top" title="Cover (top) of document"><img src="button-up-arrow.png" border="0" alt="Top: Revised(5) Report on the Algorithmic Language Scheme" align="middle" width="32"></a></td>
8136 <td valign="middle" align="left"><a href="#SEC_Contents" title="Table of contents"><img src="button-compass.png" border="0" alt="Contents: Table of Contents" align="middle" width="32"></a></td>
8137 <td valign="middle" align="left"><a href="#Index" title="Index"><img src="button-abc.png" border="0" alt="Index: Alphabetic index of definitions of concepts, keywords, and procedures" align="middle" width="32"></a></td>
8138 </tr></table>
8139 <a name="Bibliography-1"></a>
8140 <h1 class="unnumbered">Bibliography</h1>
8141
8142
8143 <ul>
8144 <li> [SICP]
8145 <a name="index-SICP"></a>
8146 Harold Abelson and Gerald Jay Sussman with Julie Sussman.
8147 <em>Structure and Interpretation of Computer Programs, second edition.</em>
8148 MIT Press, Cambridge, 1996.
8149
8150 </li><li> [Bawden88]
8151 Alan Bawden and Jonathan Rees.
8152 <a name="index-Bawden88"></a>
8153 Syntactic closures.
8154 In <em>Proceedings of the 1988 ACM Symposium on Lisp and
8155 Functional Programming</em>, pages 86&ndash;95.
8156
8157 </li><li> [howtoprint]
8158 <a name="index-howtoprint"></a>
8159 Robert G. Burger and R. Kent Dybvig.
8160 Printing floating-point numbers quickly and accurately.
8161 In <em>Proceedings of the ACM SIGPLAN '96 Conference
8162 on Programming Language Design and Implementation</em>, pages 108&ndash;116.
8163
8164 </li><li> [RRRS]
8165 <a name="index-RRRS"></a>
8166 William Clinger, editor.
8167 The revised revised report on Scheme, or an uncommon Lisp.
8168 MIT Artificial Intelligence Memo 848, August 1985.
8169 Also published as Computer Science Department Technical Report 174,
8170 Indiana University, June 1985.
8171
8172 </li><li> [howtoread]
8173 William Clinger.
8174 <a name="index-howtoread"></a>
8175 How to read floating point numbers accurately.
8176 In <em>Proceedings of the ACM SIGPLAN '90 Conference
8177 on Programming Language Design and Implementation</em>, pages 92&ndash;101.
8178 Proceedings published as <em>SIGPLAN Notices</em> 25(6), June 1990.
8179
8180 </li><li> [R4RS]
8181 <a name="index-R4RS"></a>
8182 William Clinger and Jonathan Rees, editors.
8183 The revised^4 report on the algorithmic language Scheme.
8184 In <em>ACM Lisp Pointers</em> 4(3), pages 1&ndash;55, 1991.
8185
8186 </li><li> [macrosthatwork]
8187 William Clinger and Jonathan Rees.
8188 <a name="index-macrosthatwork"></a>
8189 Macros that work.
8190 In <em>Proceedings of the 1991 ACM Conference on Principles of
8191 Programming Languages</em>, pages 155&ndash;162.
8192
8193 </li><li> [propertailrecursion]
8194 William Clinger.
8195 <a name="index-propertailrecursion"></a>
8196 Proper Tail Recursion and Space Efficiency.
8197 To appear in <em>Proceedings of the 1998 ACM Conference on Programming
8198 Language Design and Implementation</em>, June 1998.
8199
8200 </li><li> [syntacticabstraction]
8201 <a name="index-syntacticabstraction"></a>
8202 R. Kent Dybvig, Robert Hieb, and Carl Bruggeman.
8203 Syntactic abstraction in Scheme.
8204 <em>Lisp and Symbolic Computation</em> 5(4):295&ndash;326, 1993.
8205
8206 </li><li> [Scheme311]
8207 <a name="index-Scheme311"></a>
8208 Carol Fessenden, William Clinger, Daniel P. Friedman, and Christopher Haynes.
8209 Scheme 311 version 4 reference manual.
8210 Indiana University Computer Science Technical Report 137, February 1983.
8211 Superseded by [Scheme84].
8212
8213 </li><li> [Scheme84]
8214 <a name="index-Scheme84"></a>
8215 D. Friedman, C. Haynes, E. Kohlbecker, and M. Wand.
8216 Scheme 84 interim reference manual.
8217 Indiana University Computer Science Technical Report 153, January 1985.
8218
8219 </li><li> [IEEE]
8220 <a name="index-IEEE"></a>
8221 <em>IEEE Standard 754-1985. IEEE Standard for Binary Floating-Point
8222 Arithmetic.</em> IEEE, New York, 1985.
8223
8224 </li><li> [IEEEScheme]
8225 <a name="index-IEEEScheme"></a>
8226 <em>IEEE Standard 1178-1990. IEEE Standard for the Scheme
8227 Programming Language.</em> IEEE, New York, 1991.
8228
8229 </li><li> [Kohlbecker86]
8230 <a name="index-Kohlbecker86"></a>
8231 Eugene E. Kohlbecker Jr.
8232 <em>Syntactic Extensions in the Programming Language Lisp.</em>
8233 PhD thesis, Indiana University, August 1986.
8234
8235 </li><li> [hygienic]
8236 <a name="index-hygienic-1"></a>
8237 Eugene E. Kohlbecker Jr., Daniel P. Friedman, Matthias Felleisen, and Bruce Duba.
8238 Hygienic macro expansion.
8239 In <em>Proceedings of the 1986 ACM Conference on Lisp
8240 and Functional Programming</em>, pages 151&ndash;161.
8241
8242 </li><li> [Landin65]
8243 <a name="index-Landin65"></a>
8244 Peter Landin.
8245 A correspondence between Algol 60 and Church's lambda notation: Part I.
8246 <em>Communications of the ACM</em> 8(2):89&ndash;101, February 1965.
8247
8248 </li><li> [MITScheme]
8249 <a name="index-MITScheme"></a>
8250 MIT Department of Electrical Engineering and Computer Science.
8251 Scheme manual, seventh edition.
8252 September 1984.
8253
8254 </li><li> [Naur63]
8255 <a name="index-Naur63"></a>
8256 Peter Naur et al.
8257 Revised report on the algorithmic language Algol 60.
8258 <em>Communications of the ACM</em> 6(1):1&ndash;17, January 1963.
8259
8260 </li><li> [Penfield81]
8261 <a name="index-Penfield81"></a>
8262 Paul Penfield, Jr.
8263 Principal values and branch cuts in complex APL.
8264 In <em>APL '81 Conference Proceedings,</em> pages 248&ndash;256.
8265 ACM SIGAPL, San Francisco, September 1981.
8266 Proceedings published as <em>APL Quote Quad</em> 12(1), ACM, September 1981.
8267
8268 </li><li> [Pitman83]
8269 <a name="index-Pitman83"></a>
8270 Kent M. Pitman.
8271 The revised MacLisp manual (Saturday evening edition).
8272 MIT Laboratory for Computer Science Technical Report 295, May 1983.
8273
8274 </li><li> [Rees82]
8275 <a name="index-Rees82"></a>
8276 Jonathan A. Rees and Norman I. Adams IV.
8277 T: A dialect of Lisp or, lambda: The ultimate software tool.
8278 In <em>Conference Record of the 1982 ACM Symposium on Lisp and
8279 Functional Programming</em>, pages 114&ndash;122.
8280
8281 </li><li> [Rees84]
8282 <a name="index-Rees84"></a>
8283 Jonathan A. Rees, Norman I. Adams IV, and James R. Meehan.
8284 The T manual, fourth edition.
8285 Yale University Computer Science Department, January 1984.
8286
8287 </li><li> [R3RS]
8288 <a name="index-R3RS"></a>
8289 Jonathan Rees and William Clinger, editors.
8290 The revised^3 report on the algorithmic language Scheme.
8291 In <em>ACM SIGPLAN Notices</em> 21(12), pages 37&ndash;79, December 1986.
8292
8293 </li><li> [Reynolds72]
8294 <a name="index-Reynolds72"></a>
8295 John Reynolds.
8296 Definitional interpreters for higher order programming languages.
8297 In <em>ACM Conference Proceedings</em>, pages 717&ndash;740.
8298 ACM,
8299 1972.
8300
8301 </li><li> [Scheme78]
8302 <a name="index-Scheme78"></a>
8303 Guy Lewis Steele Jr. and Gerald Jay Sussman.
8304 The revised report on Scheme, a dialect of Lisp.
8305 MIT Artificial Intelligence Memo 452, January 1978.
8306
8307 </li><li> [Rabbit]
8308 <a name="index-Rabbit"></a>
8309 Guy Lewis Steele Jr.
8310 Rabbit: a compiler for Scheme.
8311 MIT Artificial Intelligence Laboratory Technical Report 474, May 1978.
8312
8313 </li><li> [CLtL]
8314 <a name="index-CLtL"></a>
8315 Guy Lewis Steele Jr.
8316 <em>Common Lisp: The Language, second edition.</em>
8317 Digital Press, Burlington MA, 1990.
8318
8319 </li><li> [Scheme75]
8320 <a name="index-Scheme75"></a>
8321 Gerald Jay Sussman and Guy Lewis Steele Jr.
8322 Scheme: an interpreter for extended lambda calculus.
8323 MIT Artificial Intelligence Memo 349, December 1975.
8324
8325 </li><li> [Stoy77]
8326 <a name="index-Stoy77"></a>
8327 Joseph E. Stoy.
8328 <em>Denotational Semantics: The Scott-Strachey Approach to
8329 Programming Language Theory.</em>
8330 MIT Press, Cambridge, 1977.
8331
8332 </li><li> [TImanual85]
8333 <a name="index-TImanual85"></a>
8334 Texas Instruments, Inc.
8335 TI Scheme Language Reference Manual.
8336 Preliminary version 1.0, November 1985.
8337
8338 </li></ul>
8339
8340
8341
8342
8343
8344
8345
8346
8347 <a name="Index"></a><hr size="1"><br/><br/><br/>
8348 <table cellpadding="1" cellspacing="1" border="0">
8349 <tr><td valign="middle" align="left"><a href="#Bibliography" title="Previous section in reading order"><img src="button-left.png" border="0" alt="Back: Bibliography" align="middle" width="32"></a></td>
8350 <td valign="middle" align="left"><a href="#Concepts" title="Next section in reading order"><img src="button-right.png" border="0" alt="Forward: Concepts" align="middle" width="32"></a></td>
8351 <td valign="middle" align="left"> &nbsp; </td>
8352 <td valign="middle" align="left"><a href="#Bibliography" title="Beginning of this chapter or previous chapter"><img src="button-left-left.png" border="0" alt="FastBack: Bibliography" align="middle" width="32"></a></td>
8353 <td valign="middle" align="left"><a href="#Top" title="Up section"><img src="button-up.png" border="0" alt="Up: Revised(5) Report on the Algorithmic Language Scheme" align="middle" width="32"></a></td>
8354 <td valign="middle" align="left"><img src="button-empty.png" border="0" alt="FastForward: Alphabetic index of definitions of concepts, keywords, and procedures" align="middle" width="32"></td>
8355 <td valign="middle" align="left"><a href="#Top" title="Cover (top) of document"><img src="button-up-arrow.png" border="0" alt="Top: Revised(5) Report on the Algorithmic Language Scheme" align="middle" width="32"></a></td>
8356 <td valign="middle" align="left"><a href="#SEC_Contents" title="Table of contents"><img src="button-compass.png" border="0" alt="Contents: Table of Contents" align="middle" width="32"></a></td>
8357 <td valign="middle" align="left"><a href="#Index" title="Index"><img src="button-abc.png" border="0" alt="Index: Alphabetic index of definitions of concepts, keywords, and procedures" align="middle" width="32"></a></td>
8358 </tr></table>
8359 <a name="Alphabetic-index-of-definitions-of-concepts_002c-keywords_002c-and-procedures"></a>
8360 <h1 class="unnumbered">Alphabetic index of definitions of concepts, keywords, and procedures</h1>
8361
8362
8363
8364 <p>The principal entry for each term, procedure, or keyword is listed
8365 first, separated from the other entries by a semicolon.
8366 </p>
8367 <br>
8368 <br>
8369 <br>
8370 <br>
8371 <br>
8372 <br>
8373
8374 <a name="Concepts"></a><hr size="1"><br/><br/><br/>
8375 <table cellpadding="1" cellspacing="1" border="0">
8376 <tr><td valign="middle" align="left"><a href="#Index" title="Previous section in reading order"><img src="button-left.png" border="0" alt="Back: Alphabetic index of definitions of concepts, keywords, and procedures" align="middle" width="32"></a></td>
8377 <td valign="middle" align="left"><a href="#Procedures-1" title="Next section in reading order"><img src="button-right.png" border="0" alt="Forward: Procedures" align="middle" width="32"></a></td>
8378 <td valign="middle" align="left"> &nbsp; </td>
8379 <td valign="middle" align="left"><a href="#Index" title="Beginning of this chapter or previous chapter"><img src="button-left-left.png" border="0" alt="FastBack: Alphabetic index of definitions of concepts, keywords, and procedures" align="middle" width="32"></a></td>
8380 <td valign="middle" align="left"><a href="#Index" title="Up section"><img src="button-up.png" border="0" alt="Up: Alphabetic index of definitions of concepts, keywords, and procedures" align="middle" width="32"></a></td>
8381 <td valign="middle" align="left"><img src="button-empty.png" border="0" alt="FastForward: Alphabetic index of definitions of concepts, keywords, and procedures" align="middle" width="32"></td>
8382 <td valign="middle" align="left"><a href="#Top" title="Cover (top) of document"><img src="button-up-arrow.png" border="0" alt="Top: Revised(5) Report on the Algorithmic Language Scheme" align="middle" width="32"></a></td>
8383 <td valign="middle" align="left"><a href="#SEC_Contents" title="Table of contents"><img src="button-compass.png" border="0" alt="Contents: Table of Contents" align="middle" width="32"></a></td>
8384 <td valign="middle" align="left"><a href="#Index" title="Index"><img src="button-abc.png" border="0" alt="Index: Alphabetic index of definitions of concepts, keywords, and procedures" align="middle" width="32"></a></td>
8385 </tr></table>
8386 <h2 class="unnumberedsec">Concepts</h2>
8387 <table><tr><th valign="top">Jump to: &nbsp; </th><td><a href="#Concepts_cp_symbol-1" class="summary-letter"><b>'</b></a>
8388 &nbsp;
8389 <a href="#Concepts_cp_symbol-2" class="summary-letter"><b>,</b></a>
8390 &nbsp;
8391 <a href="#Concepts_cp_symbol-3" class="summary-letter"><b>;</b></a>
8392 &nbsp;
8393 <a href="#Concepts_cp_symbol-4" class="summary-letter"><b>=</b></a>
8394 &nbsp;
8395 <a href="#Concepts_cp_symbol-5" class="summary-letter"><b>`</b></a>
8396 &nbsp;
8397 <br>
8398 <a href="#Concepts_cp_letter-B" class="summary-letter"><b>B</b></a>
8399 &nbsp;
8400 <a href="#Concepts_cp_letter-C" class="summary-letter"><b>C</b></a>
8401 &nbsp;
8402 <a href="#Concepts_cp_letter-D" class="summary-letter"><b>D</b></a>
8403 &nbsp;
8404 <a href="#Concepts_cp_letter-E" class="summary-letter"><b>E</b></a>
8405 &nbsp;
8406 <a href="#Concepts_cp_letter-F" class="summary-letter"><b>F</b></a>
8407 &nbsp;
8408 <a href="#Concepts_cp_letter-H" class="summary-letter"><b>H</b></a>
8409 &nbsp;
8410 <a href="#Concepts_cp_letter-I" class="summary-letter"><b>I</b></a>
8411 &nbsp;
8412 <a href="#Concepts_cp_letter-K" class="summary-letter"><b>K</b></a>
8413 &nbsp;
8414 <a href="#Concepts_cp_letter-L" class="summary-letter"><b>L</b></a>
8415 &nbsp;
8416 <a href="#Concepts_cp_letter-M" class="summary-letter"><b>M</b></a>
8417 &nbsp;
8418 <a href="#Concepts_cp_letter-N" class="summary-letter"><b>N</b></a>
8419 &nbsp;
8420 <a href="#Concepts_cp_letter-O" class="summary-letter"><b>O</b></a>
8421 &nbsp;
8422 <a href="#Concepts_cp_letter-P" class="summary-letter"><b>P</b></a>
8423 &nbsp;
8424 <a href="#Concepts_cp_letter-R" class="summary-letter"><b>R</b></a>
8425 &nbsp;
8426 <a href="#Concepts_cp_letter-S" class="summary-letter"><b>S</b></a>
8427 &nbsp;
8428 <a href="#Concepts_cp_letter-T" class="summary-letter"><b>T</b></a>
8429 &nbsp;
8430 <a href="#Concepts_cp_letter-U" class="summary-letter"><b>U</b></a>
8431 &nbsp;
8432 <a href="#Concepts_cp_letter-V" class="summary-letter"><b>V</b></a>
8433 &nbsp;
8434 <a href="#Concepts_cp_letter-W" class="summary-letter"><b>W</b></a>
8435 &nbsp;
8436 </td></tr></table>
8437 <table border="0" class="index-cp">
8438 <tr><td></td><th align="left">Index Entry</th><th align="left"> Section</th></tr>
8439 <tr><td colspan="3"> <hr></td></tr>
8440 <tr><th><a name="Concepts_cp_symbol-1">'</a></th><td></td><td></td></tr>
8441 <tr><td></td><td valign="top"><a href="#index-_0027-1">'</a></td><td valign="top"><a href="#Literal-expressions">4.1.2 Literal expressions</a></td></tr>
8442 <tr><td colspan="3"> <hr></td></tr>
8443 <tr><th><a name="Concepts_cp_symbol-2">,</a></th><td></td><td></td></tr>
8444 <tr><td></td><td valign="top"><a href="#index-_002c">,</a></td><td valign="top"><a href="#Quasiquotation">4.2.6 Quasiquotation</a></td></tr>
8445 <tr><td></td><td valign="top"><a href="#index-_002c_0040">,@</a></td><td valign="top"><a href="#Quasiquotation">4.2.6 Quasiquotation</a></td></tr>
8446 <tr><td colspan="3"> <hr></td></tr>
8447 <tr><th><a name="Concepts_cp_symbol-3">;</a></th><td></td><td></td></tr>
8448 <tr><td></td><td valign="top"><a href="#index-_003b">;</a></td><td valign="top"><a href="#Whitespace-and-comments">2.2 Whitespace and comments</a></td></tr>
8449 <tr><td colspan="3"> <hr></td></tr>
8450 <tr><th><a name="Concepts_cp_symbol-4">=</a></th><td></td><td></td></tr>
8451 <tr><td></td><td valign="top"><a href="#index-_003d_003e">=&gt;</a></td><td valign="top"><a href="#Conditional">4.2.1 Conditionals</a></td></tr>
8452 <tr><td colspan="3"> <hr></td></tr>
8453 <tr><th><a name="Concepts_cp_symbol-5">`</a></th><td></td><td></td></tr>
8454 <tr><td></td><td valign="top"><a href="#index-_0060-1">&lsquo;</a></td><td valign="top"><a href="#Quasiquotation">4.2.6 Quasiquotation</a></td></tr>
8455 <tr><td colspan="3"> <hr></td></tr>
8456 <tr><th><a name="Concepts_cp_letter-B">B</a></th><td></td><td></td></tr>
8457 <tr><td></td><td valign="top"><a href="#index-backquote">backquote</a></td><td valign="top"><a href="#Quasiquotation">4.2.6 Quasiquotation</a></td></tr>
8458 <tr><td></td><td valign="top"><a href="#index-binding">binding</a></td><td valign="top"><a href="#Variables_003b-syntactic-keywords_003b-and-regions">3.1 Variables; syntactic keywords; and regions</a></td></tr>
8459 <tr><td></td><td valign="top"><a href="#index-binding-construct">binding construct</a></td><td valign="top"><a href="#Variables_003b-syntactic-keywords_003b-and-regions">3.1 Variables; syntactic keywords; and regions</a></td></tr>
8460 <tr><td></td><td valign="top"><a href="#index-bound">bound</a></td><td valign="top"><a href="#Variables_003b-syntactic-keywords_003b-and-regions">3.1 Variables; syntactic keywords; and regions</a></td></tr>
8461 <tr><td colspan="3"> <hr></td></tr>
8462 <tr><th><a name="Concepts_cp_letter-C">C</a></th><td></td><td></td></tr>
8463 <tr><td></td><td valign="top"><a href="#index-call">call</a></td><td valign="top"><a href="#Procedure-calls">4.1.3 Procedure calls</a></td></tr>
8464 <tr><td></td><td valign="top"><a href="#index-call-by-need">call by need</a></td><td valign="top"><a href="#Delayed-evaluation">4.2.5 Delayed evaluation</a></td></tr>
8465 <tr><td></td><td valign="top"><a href="#index-combination">combination</a></td><td valign="top"><a href="#Procedure-calls">4.1.3 Procedure calls</a></td></tr>
8466 <tr><td></td><td valign="top"><a href="#index-comma">comma</a></td><td valign="top"><a href="#Quasiquotation">4.2.6 Quasiquotation</a></td></tr>
8467 <tr><td></td><td valign="top"><a href="#index-comment">comment</a></td><td valign="top"><a href="#Whitespace-and-comments">2.2 Whitespace and comments</a></td></tr>
8468 <tr><td></td><td valign="top"><a href="#index-comment-1">comment</a></td><td valign="top"><a href="#Lexical-structure">7.1.1 Lexical structure</a></td></tr>
8469 <tr><td></td><td valign="top"><a href="#index-constant">constant</a></td><td valign="top"><a href="#Storage-model">3.4 Storage model</a></td></tr>
8470 <tr><td></td><td valign="top"><a href="#index-continuation">continuation</a></td><td valign="top"><a href="#Control-features">6.4 Control features</a></td></tr>
8471 <tr><td colspan="3"> <hr></td></tr>
8472 <tr><th><a name="Concepts_cp_letter-D">D</a></th><td></td><td></td></tr>
8473 <tr><td></td><td valign="top"><a href="#index-define-1">define</a></td><td valign="top"><a href="#Definitions">5.2 Definitions</a></td></tr>
8474 <tr><td></td><td valign="top"><a href="#index-define_002dsyntax">define-syntax</a></td><td valign="top"><a href="#Syntax-definitions">5.3 Syntax definitions</a></td></tr>
8475 <tr><td></td><td valign="top"><a href="#index-definition">definition</a></td><td valign="top"><a href="#Definitions">5.2 Definitions</a></td></tr>
8476 <tr><td></td><td valign="top"><a href="#index-do-1">do</a></td><td valign="top"><a href="#Iteration">4.2.4 Iteration</a></td></tr>
8477 <tr><td></td><td valign="top"><a href="#index-dotted-pair">dotted pair</a></td><td valign="top"><a href="#Pairs-and-lists">6.3.2 Pairs and lists</a></td></tr>
8478 <tr><td colspan="3"> <hr></td></tr>
8479 <tr><th><a name="Concepts_cp_letter-E">E</a></th><td></td><td></td></tr>
8480 <tr><td></td><td valign="top"><a href="#index-else">else</a></td><td valign="top"><a href="#Conditional">4.2.1 Conditionals</a></td></tr>
8481 <tr><td></td><td valign="top"><a href="#index-empty-list">empty list</a></td><td valign="top"><a href="#Disjointness-of-types">3.2 Disjointness of types</a></td></tr>
8482 <tr><td></td><td valign="top"><a href="#index-empty-list-1">empty list</a></td><td valign="top"><a href="#Booleans">6.3.1 Booleans</a></td></tr>
8483 <tr><td></td><td valign="top"><a href="#index-empty-list-2">empty list</a></td><td valign="top"><a href="#Pairs-and-lists">6.3.2 Pairs and lists</a></td></tr>
8484 <tr><td></td><td valign="top"><a href="#index-empty-list-3">empty list</a></td><td valign="top"><a href="#Pairs-and-lists">6.3.2 Pairs and lists</a></td></tr>
8485 <tr><td></td><td valign="top"><a href="#index-empty-list-4">empty list</a></td><td valign="top"><a href="#Pairs-and-lists">6.3.2 Pairs and lists</a></td></tr>
8486 <tr><td></td><td valign="top"><a href="#index-empty-list-5">empty list</a></td><td valign="top"><a href="#Pairs-and-lists">6.3.2 Pairs and lists</a></td></tr>
8487 <tr><td></td><td valign="top"><a href="#index-empty-list-6">empty list</a></td><td valign="top"><a href="#Pairs-and-lists">6.3.2 Pairs and lists</a></td></tr>
8488 <tr><td></td><td valign="top"><a href="#index-equivalence-predicate">equivalence predicate</a></td><td valign="top"><a href="#Equivalence-predicates">6.1 Equivalence predicates</a></td></tr>
8489 <tr><td></td><td valign="top"><a href="#index-error">error</a></td><td valign="top"><a href="#Error-situations-and-unspecified-behavior">1.3.2 Error situations and unspecified behavior</a></td></tr>
8490 <tr><td></td><td valign="top"><a href="#index-escape-procedure">escape procedure</a></td><td valign="top"><a href="#Control-features">6.4 Control features</a></td></tr>
8491 <tr><td></td><td valign="top"><a href="#index-exact">exact</a></td><td valign="top"><a href="#Equivalence-predicates">6.1 Equivalence predicates</a></td></tr>
8492 <tr><td></td><td valign="top"><a href="#index-exactness">exactness</a></td><td valign="top"><a href="#Exactness">6.2.2 Exactness</a></td></tr>
8493 <tr><td colspan="3"> <hr></td></tr>
8494 <tr><th><a name="Concepts_cp_letter-F">F</a></th><td></td><td></td></tr>
8495 <tr><td></td><td valign="top"><a href="#index-false">false</a></td><td valign="top"><a href="#Disjointness-of-types">3.2 Disjointness of types</a></td></tr>
8496 <tr><td></td><td valign="top"><a href="#index-false-1">false</a></td><td valign="top"><a href="#Booleans">6.3.1 Booleans</a></td></tr>
8497 <tr><td></td><td valign="top"><a href="#index-false-2">false</a></td><td valign="top"><a href="#Booleans">6.3.1 Booleans</a></td></tr>
8498 <tr><td colspan="3"> <hr></td></tr>
8499 <tr><th><a name="Concepts_cp_letter-H">H</a></th><td></td><td></td></tr>
8500 <tr><td></td><td valign="top"><a href="#index-hygienic">hygienic</a></td><td valign="top"><a href="#Macros">4.3 Macros</a></td></tr>
8501 <tr><td colspan="3"> <hr></td></tr>
8502 <tr><th><a name="Concepts_cp_letter-I">I</a></th><td></td><td></td></tr>
8503 <tr><td></td><td valign="top"><a href="#index-identifier">identifier</a></td><td valign="top"><a href="#Identifiers">2.1 Identifiers</a></td></tr>
8504 <tr><td></td><td valign="top"><a href="#index-identifier-1">identifier</a></td><td valign="top"><a href="#Variables_003b-syntactic-keywords_003b-and-regions">3.1 Variables; syntactic keywords; and regions</a></td></tr>
8505 <tr><td></td><td valign="top"><a href="#index-identifier-2">identifier</a></td><td valign="top"><a href="#Symbols">6.3.3 Symbols</a></td></tr>
8506 <tr><td></td><td valign="top"><a href="#index-identifier-3">identifier</a></td><td valign="top"><a href="#Lexical-structure">7.1.1 Lexical structure</a></td></tr>
8507 <tr><td></td><td valign="top"><a href="#index-immutable">immutable</a></td><td valign="top"><a href="#Storage-model">3.4 Storage model</a></td></tr>
8508 <tr><td></td><td valign="top"><a href="#index-implementation-restriction">implementation restriction</a></td><td valign="top"><a href="#Error-situations-and-unspecified-behavior">1.3.2 Error situations and unspecified behavior</a></td></tr>
8509 <tr><td></td><td valign="top"><a href="#index-implementation-restriction-1">implementation restriction</a></td><td valign="top"><a href="#Implementation-restrictions">6.2.3 Implementation restrictions</a></td></tr>
8510 <tr><td></td><td valign="top"><a href="#index-improper-list">improper list</a></td><td valign="top"><a href="#Pairs-and-lists">6.3.2 Pairs and lists</a></td></tr>
8511 <tr><td></td><td valign="top"><a href="#index-inexact">inexact</a></td><td valign="top"><a href="#Equivalence-predicates">6.1 Equivalence predicates</a></td></tr>
8512 <tr><td></td><td valign="top"><a href="#index-initial-environment">initial environment</a></td><td valign="top"><a href="#Standard-procedures">6. Standard procedures</a></td></tr>
8513 <tr><td></td><td valign="top"><a href="#index-internal-definition">internal definition</a></td><td valign="top"><a href="#Internal-definitions">5.2.2 Internal definitions</a></td></tr>
8514 <tr><td colspan="3"> <hr></td></tr>
8515 <tr><th><a name="Concepts_cp_letter-K">K</a></th><td></td><td></td></tr>
8516 <tr><td></td><td valign="top"><a href="#index-keyword">keyword</a></td><td valign="top"><a href="#Macros">4.3 Macros</a></td></tr>
8517 <tr><td></td><td valign="top"><a href="#index-keyword-1">keyword</a></td><td valign="top"><a href="#Macros">4.3 Macros</a></td></tr>
8518 <tr><td></td><td valign="top"><a href="#index-keyword-2">keyword</a></td><td valign="top"><a href="#Lexical-structure">7.1.1 Lexical structure</a></td></tr>
8519 <tr><td colspan="3"> <hr></td></tr>
8520 <tr><th><a name="Concepts_cp_letter-L">L</a></th><td></td><td></td></tr>
8521 <tr><td></td><td valign="top"><a href="#index-lazy-evaluation">lazy evaluation</a></td><td valign="top"><a href="#Delayed-evaluation">4.2.5 Delayed evaluation</a></td></tr>
8522 <tr><td></td><td valign="top"><a href="#index-library">library</a></td><td valign="top"><a href="#Primitive_003b-library_003b-and-optional-features">1.3.1 Primitive; library; and optional features</a></td></tr>
8523 <tr><td></td><td valign="top"><a href="#index-library-procedure">library procedure</a></td><td valign="top"><a href="#Standard-procedures">6. Standard procedures</a></td></tr>
8524 <tr><td></td><td valign="top"><a href="#index-location">location</a></td><td valign="top"><a href="#Storage-model">3.4 Storage model</a></td></tr>
8525 <tr><td colspan="3"> <hr></td></tr>
8526 <tr><th><a name="Concepts_cp_letter-M">M</a></th><td></td><td></td></tr>
8527 <tr><td></td><td valign="top"><a href="#index-macro">macro</a></td><td valign="top"><a href="#Macros">4.3 Macros</a></td></tr>
8528 <tr><td></td><td valign="top"><a href="#index-macro-keyword">macro keyword</a></td><td valign="top"><a href="#Macros">4.3 Macros</a></td></tr>
8529 <tr><td></td><td valign="top"><a href="#index-macro-transformer">macro transformer</a></td><td valign="top"><a href="#Macros">4.3 Macros</a></td></tr>
8530 <tr><td></td><td valign="top"><a href="#index-macro-use">macro use</a></td><td valign="top"><a href="#Macros">4.3 Macros</a></td></tr>
8531 <tr><td></td><td valign="top"><a href="#index-mutable">mutable</a></td><td valign="top"><a href="#Storage-model">3.4 Storage model</a></td></tr>
8532 <tr><td colspan="3"> <hr></td></tr>
8533 <tr><th><a name="Concepts_cp_letter-N">N</a></th><td></td><td></td></tr>
8534 <tr><td></td><td valign="top"><a href="#index-number">number</a></td><td valign="top"><a href="#Numbers">6.2 Numbers</a></td></tr>
8535 <tr><td></td><td valign="top"><a href="#index-numerical-types">numerical types</a></td><td valign="top"><a href="#Numerical-types">6.2.1 Numerical types</a></td></tr>
8536 <tr><td colspan="3"> <hr></td></tr>
8537 <tr><th><a name="Concepts_cp_letter-O">O</a></th><td></td><td></td></tr>
8538 <tr><td></td><td valign="top"><a href="#index-object">object</a></td><td valign="top"><a href="#Semantics">1.1 Semantics</a></td></tr>
8539 <tr><td></td><td valign="top"><a href="#index-optional">optional</a></td><td valign="top"><a href="#Primitive_003b-library_003b-and-optional-features">1.3.1 Primitive; library; and optional features</a></td></tr>
8540 <tr><td colspan="3"> <hr></td></tr>
8541 <tr><th><a name="Concepts_cp_letter-P">P</a></th><td></td><td></td></tr>
8542 <tr><td></td><td valign="top"><a href="#index-pair">pair</a></td><td valign="top"><a href="#Pairs-and-lists">6.3.2 Pairs and lists</a></td></tr>
8543 <tr><td></td><td valign="top"><a href="#index-port">port</a></td><td valign="top"><a href="#Ports">6.6.1 Ports</a></td></tr>
8544 <tr><td></td><td valign="top"><a href="#index-predicate">predicate</a></td><td valign="top"><a href="#Equivalence-predicates">6.1 Equivalence predicates</a></td></tr>
8545 <tr><td></td><td valign="top"><a href="#index-procedure-call">procedure call</a></td><td valign="top"><a href="#Procedure-calls">4.1.3 Procedure calls</a></td></tr>
8546 <tr><td></td><td valign="top"><a href="#index-promise">promise</a></td><td valign="top"><a href="#Delayed-evaluation">4.2.5 Delayed evaluation</a></td></tr>
8547 <tr><td></td><td valign="top"><a href="#index-promise-1">promise</a></td><td valign="top"><a href="#Control-features">6.4 Control features</a></td></tr>
8548 <tr><td></td><td valign="top"><a href="#index-proper-tail-recursion">proper tail recursion</a></td><td valign="top"><a href="#Proper-tail-recursion">3.5 Proper tail recursion</a></td></tr>
8549 <tr><td colspan="3"> <hr></td></tr>
8550 <tr><th><a name="Concepts_cp_letter-R">R</a></th><td></td><td></td></tr>
8551 <tr><td></td><td valign="top"><a href="#index-referentially-transparent">referentially transparent</a></td><td valign="top"><a href="#Macros">4.3 Macros</a></td></tr>
8552 <tr><td></td><td valign="top"><a href="#index-region">region</a></td><td valign="top"><a href="#Variables_003b-syntactic-keywords_003b-and-regions">3.1 Variables; syntactic keywords; and regions</a></td></tr>
8553 <tr><td></td><td valign="top"><a href="#index-region-1">region</a></td><td valign="top"><a href="#Assignments">4.1.6 Assignments</a></td></tr>
8554 <tr><td></td><td valign="top"><a href="#index-region-2">region</a></td><td valign="top"><a href="#Binding-constructs">4.2.2 Binding constructs</a></td></tr>
8555 <tr><td></td><td valign="top"><a href="#index-region-3">region</a></td><td valign="top"><a href="#Binding-constructs">4.2.2 Binding constructs</a></td></tr>
8556 <tr><td></td><td valign="top"><a href="#index-region-4">region</a></td><td valign="top"><a href="#Binding-constructs">4.2.2 Binding constructs</a></td></tr>
8557 <tr><td></td><td valign="top"><a href="#index-region-5">region</a></td><td valign="top"><a href="#Binding-constructs">4.2.2 Binding constructs</a></td></tr>
8558 <tr><td></td><td valign="top"><a href="#index-region-6">region</a></td><td valign="top"><a href="#Iteration">4.2.4 Iteration</a></td></tr>
8559 <tr><td colspan="3"> <hr></td></tr>
8560 <tr><th><a name="Concepts_cp_letter-S">S</a></th><td></td><td></td></tr>
8561 <tr><td></td><td valign="top"><a href="#index-simplest-rational">simplest rational</a></td><td valign="top"><a href="#Numerical-operations">6.2.5 Numerical operations</a></td></tr>
8562 <tr><td></td><td valign="top"><a href="#index-syntactic-keyword">syntactic keyword</a></td><td valign="top"><a href="#Identifiers">2.1 Identifiers</a></td></tr>
8563 <tr><td></td><td valign="top"><a href="#index-syntactic-keyword-1">syntactic keyword</a></td><td valign="top"><a href="#Variables_003b-syntactic-keywords_003b-and-regions">3.1 Variables; syntactic keywords; and regions</a></td></tr>
8564 <tr><td></td><td valign="top"><a href="#index-syntactic-keyword-2">syntactic keyword</a></td><td valign="top"><a href="#Macros">4.3 Macros</a></td></tr>
8565 <tr><td></td><td valign="top"><a href="#index-syntactic-keyword-3">syntactic keyword</a></td><td valign="top"><a href="#Lexical-structure">7.1.1 Lexical structure</a></td></tr>
8566 <tr><td></td><td valign="top"><a href="#index-syntax-definition">syntax definition</a></td><td valign="top"><a href="#Syntax-definitions">5.3 Syntax definitions</a></td></tr>
8567 <tr><td colspan="3"> <hr></td></tr>
8568 <tr><th><a name="Concepts_cp_letter-T">T</a></th><td></td><td></td></tr>
8569 <tr><td></td><td valign="top"><a href="#index-tail-call">tail call</a></td><td valign="top"><a href="#Proper-tail-recursion">3.5 Proper tail recursion</a></td></tr>
8570 <tr><td></td><td valign="top"><a href="#index-token">token</a></td><td valign="top"><a href="#Lexical-structure">7.1.1 Lexical structure</a></td></tr>
8571 <tr><td></td><td valign="top"><a href="#index-top-level-environment">top level environment</a></td><td valign="top"><a href="#Variables_003b-syntactic-keywords_003b-and-regions">3.1 Variables; syntactic keywords; and regions</a></td></tr>
8572 <tr><td></td><td valign="top"><a href="#index-top-level-environment-1">top level environment</a></td><td valign="top"><a href="#Standard-procedures">6. Standard procedures</a></td></tr>
8573 <tr><td></td><td valign="top"><a href="#index-true">true</a></td><td valign="top"><a href="#Disjointness-of-types">3.2 Disjointness of types</a></td></tr>
8574 <tr><td></td><td valign="top"><a href="#index-true-1">true</a></td><td valign="top"><a href="#Conditionals">4.1.5 Conditionals</a></td></tr>
8575 <tr><td></td><td valign="top"><a href="#index-true-2">true</a></td><td valign="top"><a href="#Conditional">4.2.1 Conditionals</a></td></tr>
8576 <tr><td></td><td valign="top"><a href="#index-true-3">true</a></td><td valign="top"><a href="#Booleans">6.3.1 Booleans</a></td></tr>
8577 <tr><td></td><td valign="top"><a href="#index-type">type</a></td><td valign="top"><a href="#Disjointness-of-types">3.2 Disjointness of types</a></td></tr>
8578 <tr><td colspan="3"> <hr></td></tr>
8579 <tr><th><a name="Concepts_cp_letter-U">U</a></th><td></td><td></td></tr>
8580 <tr><td></td><td valign="top"><a href="#index-unbound">unbound</a></td><td valign="top"><a href="#Variables_003b-syntactic-keywords_003b-and-regions">3.1 Variables; syntactic keywords; and regions</a></td></tr>
8581 <tr><td></td><td valign="top"><a href="#index-unbound-1">unbound</a></td><td valign="top"><a href="#Variable-references">4.1.1 Variable references</a></td></tr>
8582 <tr><td></td><td valign="top"><a href="#index-unbound-2">unbound</a></td><td valign="top"><a href="#Top-level-definitions">5.2.1 Top level definitions</a></td></tr>
8583 <tr><td></td><td valign="top"><a href="#index-unspecified">unspecified</a></td><td valign="top"><a href="#Error-situations-and-unspecified-behavior">1.3.2 Error situations and unspecified behavior</a></td></tr>
8584 <tr><td colspan="3"> <hr></td></tr>
8585 <tr><th><a name="Concepts_cp_letter-V">V</a></th><td></td><td></td></tr>
8586 <tr><td></td><td valign="top"><a href="#index-valid-indexes">valid indexes</a></td><td valign="top"><a href="#Strings">6.3.5 Strings</a></td></tr>
8587 <tr><td></td><td valign="top"><a href="#index-valid-indexes-1">valid indexes</a></td><td valign="top"><a href="#Vectors">6.3.6 Vectors</a></td></tr>
8588 <tr><td></td><td valign="top"><a href="#index-variable">variable</a></td><td valign="top"><a href="#Identifiers">2.1 Identifiers</a></td></tr>
8589 <tr><td></td><td valign="top"><a href="#index-variable-1">variable</a></td><td valign="top"><a href="#Variables_003b-syntactic-keywords_003b-and-regions">3.1 Variables; syntactic keywords; and regions</a></td></tr>
8590 <tr><td></td><td valign="top"><a href="#index-variable-2">variable</a></td><td valign="top"><a href="#Variable-references">4.1.1 Variable references</a></td></tr>
8591 <tr><td></td><td valign="top"><a href="#index-variable-3">variable</a></td><td valign="top"><a href="#Lexical-structure">7.1.1 Lexical structure</a></td></tr>
8592 <tr><td colspan="3"> <hr></td></tr>
8593 <tr><th><a name="Concepts_cp_letter-W">W</a></th><td></td><td></td></tr>
8594 <tr><td></td><td valign="top"><a href="#index-Whitespace">Whitespace</a></td><td valign="top"><a href="#Whitespace-and-comments">2.2 Whitespace and comments</a></td></tr>
8595 <tr><td colspan="3"> <hr></td></tr>
8596 </table>
8597 <table><tr><th valign="top">Jump to: &nbsp; </th><td><a href="#Concepts_cp_symbol-1" class="summary-letter"><b>'</b></a>
8598 &nbsp;
8599 <a href="#Concepts_cp_symbol-2" class="summary-letter"><b>,</b></a>
8600 &nbsp;
8601 <a href="#Concepts_cp_symbol-3" class="summary-letter"><b>;</b></a>
8602 &nbsp;
8603 <a href="#Concepts_cp_symbol-4" class="summary-letter"><b>=</b></a>
8604 &nbsp;
8605 <a href="#Concepts_cp_symbol-5" class="summary-letter"><b>`</b></a>
8606 &nbsp;
8607 <br>
8608 <a href="#Concepts_cp_letter-B" class="summary-letter"><b>B</b></a>
8609 &nbsp;
8610 <a href="#Concepts_cp_letter-C" class="summary-letter"><b>C</b></a>
8611 &nbsp;
8612 <a href="#Concepts_cp_letter-D" class="summary-letter"><b>D</b></a>
8613 &nbsp;
8614 <a href="#Concepts_cp_letter-E" class="summary-letter"><b>E</b></a>
8615 &nbsp;
8616 <a href="#Concepts_cp_letter-F" class="summary-letter"><b>F</b></a>
8617 &nbsp;
8618 <a href="#Concepts_cp_letter-H" class="summary-letter"><b>H</b></a>
8619 &nbsp;
8620 <a href="#Concepts_cp_letter-I" class="summary-letter"><b>I</b></a>
8621 &nbsp;
8622 <a href="#Concepts_cp_letter-K" class="summary-letter"><b>K</b></a>
8623 &nbsp;
8624 <a href="#Concepts_cp_letter-L" class="summary-letter"><b>L</b></a>
8625 &nbsp;
8626 <a href="#Concepts_cp_letter-M" class="summary-letter"><b>M</b></a>
8627 &nbsp;
8628 <a href="#Concepts_cp_letter-N" class="summary-letter"><b>N</b></a>
8629 &nbsp;
8630 <a href="#Concepts_cp_letter-O" class="summary-letter"><b>O</b></a>
8631 &nbsp;
8632 <a href="#Concepts_cp_letter-P" class="summary-letter"><b>P</b></a>
8633 &nbsp;
8634 <a href="#Concepts_cp_letter-R" class="summary-letter"><b>R</b></a>
8635 &nbsp;
8636 <a href="#Concepts_cp_letter-S" class="summary-letter"><b>S</b></a>
8637 &nbsp;
8638 <a href="#Concepts_cp_letter-T" class="summary-letter"><b>T</b></a>
8639 &nbsp;
8640 <a href="#Concepts_cp_letter-U" class="summary-letter"><b>U</b></a>
8641 &nbsp;
8642 <a href="#Concepts_cp_letter-V" class="summary-letter"><b>V</b></a>
8643 &nbsp;
8644 <a href="#Concepts_cp_letter-W" class="summary-letter"><b>W</b></a>
8645 &nbsp;
8646 </td></tr></table>
8647
8648 <a name="Procedures-1"></a><hr size="1"><br/><br/><br/>
8649 <table cellpadding="1" cellspacing="1" border="0">
8650 <tr><td valign="middle" align="left"><a href="#Concepts" title="Previous section in reading order"><img src="button-left.png" border="0" alt="Back: Concepts" align="middle" width="32"></a></td>
8651 <td valign="middle" align="left"><img src="button-empty.png" border="0" alt="Forward: Procedures" align="middle" width="32"></td>
8652 <td valign="middle" align="left"> &nbsp; </td>
8653 <td valign="middle" align="left"><a href="#Index" title="Beginning of this chapter or previous chapter"><img src="button-left-left.png" border="0" alt="FastBack: Alphabetic index of definitions of concepts, keywords, and procedures" align="middle" width="32"></a></td>
8654 <td valign="middle" align="left"><a href="#Index" title="Up section"><img src="button-up.png" border="0" alt="Up: Alphabetic index of definitions of concepts, keywords, and procedures" align="middle" width="32"></a></td>
8655 <td valign="middle" align="left"><img src="button-empty.png" border="0" alt="FastForward: Alphabetic index of definitions of concepts, keywords, and procedures" align="middle" width="32"></td>
8656 <td valign="middle" align="left"><a href="#Top" title="Cover (top) of document"><img src="button-up-arrow.png" border="0" alt="Top: Revised(5) Report on the Algorithmic Language Scheme" align="middle" width="32"></a></td>
8657 <td valign="middle" align="left"><a href="#SEC_Contents" title="Table of contents"><img src="button-compass.png" border="0" alt="Contents: Table of Contents" align="middle" width="32"></a></td>
8658 <td valign="middle" align="left"><a href="#Index" title="Index"><img src="button-abc.png" border="0" alt="Index: Alphabetic index of definitions of concepts, keywords, and procedures" align="middle" width="32"></a></td>
8659 </tr></table>
8660 <h2 class="unnumberedsec">Procedures</h2>
8661 <table><tr><th valign="top">Jump to: &nbsp; </th><td><a href="#Procedures-1_fn_symbol-1" class="summary-letter"><b> </b></a>
8662 &nbsp;
8663 <a href="#Procedures-1_fn_symbol-2" class="summary-letter"><b>'</b></a>
8664 &nbsp;
8665 <a href="#Procedures-1_fn_symbol-3" class="summary-letter"><b>*</b></a>
8666 &nbsp;
8667 <a href="#Procedures-1_fn_symbol-4" class="summary-letter"><b>+</b></a>
8668 &nbsp;
8669 <a href="#Procedures-1_fn_symbol-5" class="summary-letter"><b>-</b></a>
8670 &nbsp;
8671 <a href="#Procedures-1_fn_symbol-6" class="summary-letter"><b>/</b></a>
8672 &nbsp;
8673 <a href="#Procedures-1_fn_symbol-7" class="summary-letter"><b>&lt;</b></a>
8674 &nbsp;
8675 <a href="#Procedures-1_fn_symbol-8" class="summary-letter"><b>=</b></a>
8676 &nbsp;
8677 <a href="#Procedures-1_fn_symbol-9" class="summary-letter"><b>&gt;</b></a>
8678 &nbsp;
8679 <a href="#Procedures-1_fn_symbol-10" class="summary-letter"><b>`</b></a>
8680 &nbsp;
8681 <br>
8682 <a href="#Procedures-1_fn_letter-A" class="summary-letter"><b>A</b></a>
8683 &nbsp;
8684 <a href="#Procedures-1_fn_letter-B" class="summary-letter"><b>B</b></a>
8685 &nbsp;
8686 <a href="#Procedures-1_fn_letter-C" class="summary-letter"><b>C</b></a>
8687 &nbsp;
8688 <a href="#Procedures-1_fn_letter-D" class="summary-letter"><b>D</b></a>
8689 &nbsp;
8690 <a href="#Procedures-1_fn_letter-E" class="summary-letter"><b>E</b></a>
8691 &nbsp;
8692 <a href="#Procedures-1_fn_letter-F" class="summary-letter"><b>F</b></a>
8693 &nbsp;
8694 <a href="#Procedures-1_fn_letter-G" class="summary-letter"><b>G</b></a>
8695 &nbsp;
8696 <a href="#Procedures-1_fn_letter-I" class="summary-letter"><b>I</b></a>
8697 &nbsp;
8698 <a href="#Procedures-1_fn_letter-L" class="summary-letter"><b>L</b></a>
8699 &nbsp;
8700 <a href="#Procedures-1_fn_letter-M" class="summary-letter"><b>M</b></a>
8701 &nbsp;
8702 <a href="#Procedures-1_fn_letter-N" class="summary-letter"><b>N</b></a>
8703 &nbsp;
8704 <a href="#Procedures-1_fn_letter-O" class="summary-letter"><b>O</b></a>
8705 &nbsp;
8706 <a href="#Procedures-1_fn_letter-P" class="summary-letter"><b>P</b></a>
8707 &nbsp;
8708 <a href="#Procedures-1_fn_letter-Q" class="summary-letter"><b>Q</b></a>
8709 &nbsp;
8710 <a href="#Procedures-1_fn_letter-R" class="summary-letter"><b>R</b></a>
8711 &nbsp;
8712 <a href="#Procedures-1_fn_letter-S" class="summary-letter"><b>S</b></a>
8713 &nbsp;
8714 <a href="#Procedures-1_fn_letter-T" class="summary-letter"><b>T</b></a>
8715 &nbsp;
8716 <a href="#Procedures-1_fn_letter-V" class="summary-letter"><b>V</b></a>
8717 &nbsp;
8718 <a href="#Procedures-1_fn_letter-W" class="summary-letter"><b>W</b></a>
8719 &nbsp;
8720 <a href="#Procedures-1_fn_letter-Z" class="summary-letter"><b>Z</b></a>
8721 &nbsp;
8722 </td></tr></table>
8723 <table border="0" class="index-fn">
8724 <tr><td></td><th align="left">Index Entry</th><th align="left"> Section</th></tr>
8725 <tr><td colspan="3"> <hr></td></tr>
8726 <tr><th><a name="Procedures-1_fn_symbol-1"> </a></th><td></td><td></td></tr>
8727 <tr><td></td><td valign="top"><a href="#index----------_2026"><code> &hellip;</code></a></td><td valign="top"><a href="#Pairs-and-lists">6.3.2 Pairs and lists</a></td></tr>
8728 <tr><td colspan="3"> <hr></td></tr>
8729 <tr><th><a name="Procedures-1_fn_symbol-2">'</a></th><td></td><td></td></tr>
8730 <tr><td></td><td valign="top"><a href="#index-_0027"><code><tt>'</tt></code></a></td><td valign="top"><a href="#Literal-expressions">4.1.2 Literal expressions</a></td></tr>
8731 <tr><td colspan="3"> <hr></td></tr>
8732 <tr><th><a name="Procedures-1_fn_symbol-3">*</a></th><td></td><td></td></tr>
8733 <tr><td></td><td valign="top"><a href="#index-_002a"><code>*</code></a></td><td valign="top"><a href="#Numerical-operations">6.2.5 Numerical operations</a></td></tr>
8734 <tr><td colspan="3"> <hr></td></tr>
8735 <tr><th><a name="Procedures-1_fn_symbol-4">+</a></th><td></td><td></td></tr>
8736 <tr><td></td><td valign="top"><a href="#index-_002b-1"><code>+</code></a></td><td valign="top"><a href="#Numerical-operations">6.2.5 Numerical operations</a></td></tr>
8737 <tr><td colspan="3"> <hr></td></tr>
8738 <tr><th><a name="Procedures-1_fn_symbol-5">-</a></th><td></td><td></td></tr>
8739 <tr><td></td><td valign="top"><a href="#index-_002d-1"><code>-</code></a></td><td valign="top"><a href="#Numerical-operations">6.2.5 Numerical operations</a></td></tr>
8740 <tr><td></td><td valign="top"><a href="#index-_002d-2"><code>-</code></a></td><td valign="top"><a href="#Numerical-operations">6.2.5 Numerical operations</a></td></tr>
8741 <tr><td></td><td valign="top"><a href="#index-_002d-3"><code>-</code></a></td><td valign="top"><a href="#Numerical-operations">6.2.5 Numerical operations</a></td></tr>
8742 <tr><td colspan="3"> <hr></td></tr>
8743 <tr><th><a name="Procedures-1_fn_symbol-6">/</a></th><td></td><td></td></tr>
8744 <tr><td></td><td valign="top"><a href="#index-_002f"><code>/</code></a></td><td valign="top"><a href="#Numerical-operations">6.2.5 Numerical operations</a></td></tr>
8745 <tr><td></td><td valign="top"><a href="#index-_002f-1"><code>/</code></a></td><td valign="top"><a href="#Numerical-operations">6.2.5 Numerical operations</a></td></tr>
8746 <tr><td></td><td valign="top"><a href="#index-_002f-2"><code>/</code></a></td><td valign="top"><a href="#Numerical-operations">6.2.5 Numerical operations</a></td></tr>
8747 <tr><td colspan="3"> <hr></td></tr>
8748 <tr><th><a name="Procedures-1_fn_symbol-7">&lt;</a></th><td></td><td></td></tr>
8749 <tr><td></td><td valign="top"><a href="#index-_003c"><code>&lt;</code></a></td><td valign="top"><a href="#Numerical-operations">6.2.5 Numerical operations</a></td></tr>
8750 <tr><td></td><td valign="top"><a href="#index-_003c_003d"><code>&lt;=</code></a></td><td valign="top"><a href="#Numerical-operations">6.2.5 Numerical operations</a></td></tr>
8751 <tr><td colspan="3"> <hr></td></tr>
8752 <tr><th><a name="Procedures-1_fn_symbol-8">=</a></th><td></td><td></td></tr>
8753 <tr><td></td><td valign="top"><a href="#index-_003d"><code>=</code></a></td><td valign="top"><a href="#Numerical-operations">6.2.5 Numerical operations</a></td></tr>
8754 <tr><td colspan="3"> <hr></td></tr>
8755 <tr><th><a name="Procedures-1_fn_symbol-9">&gt;</a></th><td></td><td></td></tr>
8756 <tr><td></td><td valign="top"><a href="#index-_003e"><code>&gt;</code></a></td><td valign="top"><a href="#Numerical-operations">6.2.5 Numerical operations</a></td></tr>
8757 <tr><td></td><td valign="top"><a href="#index-_003e_003d"><code>&gt;=</code></a></td><td valign="top"><a href="#Numerical-operations">6.2.5 Numerical operations</a></td></tr>
8758 <tr><td colspan="3"> <hr></td></tr>
8759 <tr><th><a name="Procedures-1_fn_symbol-10">`</a></th><td></td><td></td></tr>
8760 <tr><td></td><td valign="top"><a href="#index-_0060"><code><tt>`</tt></code></a></td><td valign="top"><a href="#Quasiquotation">4.2.6 Quasiquotation</a></td></tr>
8761 <tr><td colspan="3"> <hr></td></tr>
8762 <tr><th><a name="Procedures-1_fn_letter-A">A</a></th><td></td><td></td></tr>
8763 <tr><td></td><td valign="top"><a href="#index-abs"><code>abs</code></a></td><td valign="top"><a href="#Numerical-operations">6.2.5 Numerical operations</a></td></tr>
8764 <tr><td></td><td valign="top"><a href="#index-acos"><code>acos</code></a></td><td valign="top"><a href="#Numerical-operations">6.2.5 Numerical operations</a></td></tr>
8765 <tr><td></td><td valign="top"><a href="#index-and"><code>and</code></a></td><td valign="top"><a href="#Conditional">4.2.1 Conditionals</a></td></tr>
8766 <tr><td></td><td valign="top"><a href="#index-angle"><code>angle</code></a></td><td valign="top"><a href="#Numerical-operations">6.2.5 Numerical operations</a></td></tr>
8767 <tr><td></td><td valign="top"><a href="#index-append"><code>append</code></a></td><td valign="top"><a href="#Pairs-and-lists">6.3.2 Pairs and lists</a></td></tr>
8768 <tr><td></td><td valign="top"><a href="#index-apply-1"><code>apply</code></a></td><td valign="top"><a href="#Control-features">6.4 Control features</a></td></tr>
8769 <tr><td></td><td valign="top"><a href="#index-asin"><code>asin</code></a></td><td valign="top"><a href="#Numerical-operations">6.2.5 Numerical operations</a></td></tr>
8770 <tr><td></td><td valign="top"><a href="#index-assoc"><code>assoc</code></a></td><td valign="top"><a href="#Pairs-and-lists">6.3.2 Pairs and lists</a></td></tr>
8771 <tr><td></td><td valign="top"><a href="#index-assq"><code>assq</code></a></td><td valign="top"><a href="#Pairs-and-lists">6.3.2 Pairs and lists</a></td></tr>
8772 <tr><td></td><td valign="top"><a href="#index-assv"><code>assv</code></a></td><td valign="top"><a href="#Pairs-and-lists">6.3.2 Pairs and lists</a></td></tr>
8773 <tr><td></td><td valign="top"><a href="#index-atan"><code>atan</code></a></td><td valign="top"><a href="#Numerical-operations">6.2.5 Numerical operations</a></td></tr>
8774 <tr><td></td><td valign="top"><a href="#index-atan-1"><code>atan</code></a></td><td valign="top"><a href="#Numerical-operations">6.2.5 Numerical operations</a></td></tr>
8775 <tr><td colspan="3"> <hr></td></tr>
8776 <tr><th><a name="Procedures-1_fn_letter-B">B</a></th><td></td><td></td></tr>
8777 <tr><td></td><td valign="top"><a href="#index-begin"><code>begin</code></a></td><td valign="top"><a href="#Sequencing">4.2.3 Sequencing</a></td></tr>
8778 <tr><td></td><td valign="top"><a href="#index-boolean_003f-1"><code>boolean?</code></a></td><td valign="top"><a href="#Booleans">6.3.1 Booleans</a></td></tr>
8779 <tr><td colspan="3"> <hr></td></tr>
8780 <tr><th><a name="Procedures-1_fn_letter-C">C</a></th><td></td><td></td></tr>
8781 <tr><td></td><td valign="top"><a href="#index-caar"><code>caar</code></a></td><td valign="top"><a href="#Pairs-and-lists">6.3.2 Pairs and lists</a></td></tr>
8782 <tr><td></td><td valign="top"><a href="#index-cadr"><code>cadr</code></a></td><td valign="top"><a href="#Pairs-and-lists">6.3.2 Pairs and lists</a></td></tr>
8783 <tr><td></td><td valign="top"><a href="#index-call_002dwith_002dcurrent_002dcontinuation-1"><code>call-with-current-continuation</code></a></td><td valign="top"><a href="#Control-features">6.4 Control features</a></td></tr>
8784 <tr><td></td><td valign="top"><a href="#index-call_002dwith_002dinput_002dfile"><code>call-with-input-file</code></a></td><td valign="top"><a href="#Ports">6.6.1 Ports</a></td></tr>
8785 <tr><td></td><td valign="top"><a href="#index-call_002dwith_002doutput_002dfile"><code>call-with-output-file</code></a></td><td valign="top"><a href="#Ports">6.6.1 Ports</a></td></tr>
8786 <tr><td></td><td valign="top"><a href="#index-call_002dwith_002dvalues-2"><code>call-with-values</code></a></td><td valign="top"><a href="#Control-features">6.4 Control features</a></td></tr>
8787 <tr><td></td><td valign="top"><a href="#index-car"><code>car</code></a></td><td valign="top"><a href="#Pairs-and-lists">6.3.2 Pairs and lists</a></td></tr>
8788 <tr><td></td><td valign="top"><a href="#index-case"><code>case</code></a></td><td valign="top"><a href="#Conditional">4.2.1 Conditionals</a></td></tr>
8789 <tr><td></td><td valign="top"><a href="#index-cdddar"><code>cdddar</code></a></td><td valign="top"><a href="#Pairs-and-lists">6.3.2 Pairs and lists</a></td></tr>
8790 <tr><td></td><td valign="top"><a href="#index-cddddr"><code>cddddr</code></a></td><td valign="top"><a href="#Pairs-and-lists">6.3.2 Pairs and lists</a></td></tr>
8791 <tr><td></td><td valign="top"><a href="#index-cdr"><code>cdr</code></a></td><td valign="top"><a href="#Pairs-and-lists">6.3.2 Pairs and lists</a></td></tr>
8792 <tr><td></td><td valign="top"><a href="#index-ceiling"><code>ceiling</code></a></td><td valign="top"><a href="#Numerical-operations">6.2.5 Numerical operations</a></td></tr>
8793 <tr><td></td><td valign="top"><a href="#index-char_002d_003einteger"><code>char-&gt;integer</code></a></td><td valign="top"><a href="#Characters">6.3.4 Characters</a></td></tr>
8794 <tr><td></td><td valign="top"><a href="#index-char_002dalphabetic_003f"><code>char-alphabetic?</code></a></td><td valign="top"><a href="#Characters">6.3.4 Characters</a></td></tr>
8795 <tr><td></td><td valign="top"><a href="#index-char_002dci_003c_003d_003f"><code>char-ci&lt;=?</code></a></td><td valign="top"><a href="#Characters">6.3.4 Characters</a></td></tr>
8796 <tr><td></td><td valign="top"><a href="#index-char_002dci_003c_003f"><code>char-ci&lt;?</code></a></td><td valign="top"><a href="#Characters">6.3.4 Characters</a></td></tr>
8797 <tr><td></td><td valign="top"><a href="#index-char_002dci_003d_003f"><code>char-ci=?</code></a></td><td valign="top"><a href="#Characters">6.3.4 Characters</a></td></tr>
8798 <tr><td></td><td valign="top"><a href="#index-char_002dci_003e_003d_003f"><code>char-ci&gt;=?</code></a></td><td valign="top"><a href="#Characters">6.3.4 Characters</a></td></tr>
8799 <tr><td></td><td valign="top"><a href="#index-char_002dci_003e_003f"><code>char-ci&gt;?</code></a></td><td valign="top"><a href="#Characters">6.3.4 Characters</a></td></tr>
8800 <tr><td></td><td valign="top"><a href="#index-char_002ddowncase"><code>char-downcase</code></a></td><td valign="top"><a href="#Characters">6.3.4 Characters</a></td></tr>
8801 <tr><td></td><td valign="top"><a href="#index-char_002dlower_002dcase_003f"><code>char-lower-case?</code></a></td><td valign="top"><a href="#Characters">6.3.4 Characters</a></td></tr>
8802 <tr><td></td><td valign="top"><a href="#index-char_002dnumeric_003f"><code>char-numeric?</code></a></td><td valign="top"><a href="#Characters">6.3.4 Characters</a></td></tr>
8803 <tr><td></td><td valign="top"><a href="#index-char_002dready_003f"><code>char-ready?</code></a></td><td valign="top"><a href="#Input">6.6.2 Input</a></td></tr>
8804 <tr><td></td><td valign="top"><a href="#index-char_002dready_003f-1"><code>char-ready?</code></a></td><td valign="top"><a href="#Input">6.6.2 Input</a></td></tr>
8805 <tr><td></td><td valign="top"><a href="#index-char_002dupcase"><code>char-upcase</code></a></td><td valign="top"><a href="#Characters">6.3.4 Characters</a></td></tr>
8806 <tr><td></td><td valign="top"><a href="#index-char_002dupper_002dcase_003f"><code>char-upper-case?</code></a></td><td valign="top"><a href="#Characters">6.3.4 Characters</a></td></tr>
8807 <tr><td></td><td valign="top"><a href="#index-char_002dwhitespace_003f"><code>char-whitespace?</code></a></td><td valign="top"><a href="#Characters">6.3.4 Characters</a></td></tr>
8808 <tr><td></td><td valign="top"><a href="#index-char_003c_003d_003f"><code>char&lt;=?</code></a></td><td valign="top"><a href="#Characters">6.3.4 Characters</a></td></tr>
8809 <tr><td></td><td valign="top"><a href="#index-char_003c_003f"><code>char&lt;?</code></a></td><td valign="top"><a href="#Characters">6.3.4 Characters</a></td></tr>
8810 <tr><td></td><td valign="top"><a href="#index-char_003d_003f"><code>char=?</code></a></td><td valign="top"><a href="#Characters">6.3.4 Characters</a></td></tr>
8811 <tr><td></td><td valign="top"><a href="#index-char_003e_003d_003f"><code>char&gt;=?</code></a></td><td valign="top"><a href="#Characters">6.3.4 Characters</a></td></tr>
8812 <tr><td></td><td valign="top"><a href="#index-char_003e_003f"><code>char&gt;?</code></a></td><td valign="top"><a href="#Characters">6.3.4 Characters</a></td></tr>
8813 <tr><td></td><td valign="top"><a href="#index-char_003f-1"><code>char?</code></a></td><td valign="top"><a href="#Characters">6.3.4 Characters</a></td></tr>
8814 <tr><td></td><td valign="top"><a href="#index-close_002dinput_002dport"><code>close-input-port</code></a></td><td valign="top"><a href="#Ports">6.6.1 Ports</a></td></tr>
8815 <tr><td></td><td valign="top"><a href="#index-close_002doutput_002dport"><code>close-output-port</code></a></td><td valign="top"><a href="#Ports">6.6.1 Ports</a></td></tr>
8816 <tr><td></td><td valign="top"><a href="#index-complex_003f-1"><code>complex?</code></a></td><td valign="top"><a href="#Numerical-operations">6.2.5 Numerical operations</a></td></tr>
8817 <tr><td></td><td valign="top"><a href="#index-cond"><code>cond</code></a></td><td valign="top"><a href="#Conditional">4.2.1 Conditionals</a></td></tr>
8818 <tr><td></td><td valign="top"><a href="#index-cons"><code>cons</code></a></td><td valign="top"><a href="#Pairs-and-lists">6.3.2 Pairs and lists</a></td></tr>
8819 <tr><td></td><td valign="top"><a href="#index-cos"><code>cos</code></a></td><td valign="top"><a href="#Numerical-operations">6.2.5 Numerical operations</a></td></tr>
8820 <tr><td></td><td valign="top"><a href="#index-current_002dinput_002dport"><code>current-input-port</code></a></td><td valign="top"><a href="#Ports">6.6.1 Ports</a></td></tr>
8821 <tr><td></td><td valign="top"><a href="#index-current_002doutput_002dport"><code>current-output-port</code></a></td><td valign="top"><a href="#Ports">6.6.1 Ports</a></td></tr>
8822 <tr><td colspan="3"> <hr></td></tr>
8823 <tr><th><a name="Procedures-1_fn_letter-D">D</a></th><td></td><td></td></tr>
8824 <tr><td></td><td valign="top"><a href="#index-delay"><code>delay</code></a></td><td valign="top"><a href="#Delayed-evaluation">4.2.5 Delayed evaluation</a></td></tr>
8825 <tr><td></td><td valign="top"><a href="#index-denominator"><code>denominator</code></a></td><td valign="top"><a href="#Numerical-operations">6.2.5 Numerical operations</a></td></tr>
8826 <tr><td></td><td valign="top"><a href="#index-display"><code>display</code></a></td><td valign="top"><a href="#Output">6.6.3 Output</a></td></tr>
8827 <tr><td></td><td valign="top"><a href="#index-display-1"><code>display</code></a></td><td valign="top"><a href="#Output">6.6.3 Output</a></td></tr>
8828 <tr><td></td><td valign="top"><a href="#index-do"><code>do</code></a></td><td valign="top"><a href="#Iteration">4.2.4 Iteration</a></td></tr>
8829 <tr><td></td><td valign="top"><a href="#index-dynamic_002dwind-1"><code>dynamic-wind</code></a></td><td valign="top"><a href="#Control-features">6.4 Control features</a></td></tr>
8830 <tr><td colspan="3"> <hr></td></tr>
8831 <tr><th><a name="Procedures-1_fn_letter-E">E</a></th><td></td><td></td></tr>
8832 <tr><td></td><td valign="top"><a href="#index-eof_002dobject_003f"><code>eof-object?</code></a></td><td valign="top"><a href="#Input">6.6.2 Input</a></td></tr>
8833 <tr><td></td><td valign="top"><a href="#index-eq_003f-1"><code>eq?</code></a></td><td valign="top"><a href="#Equivalence-predicates">6.1 Equivalence predicates</a></td></tr>
8834 <tr><td></td><td valign="top"><a href="#index-equal_003f"><code>equal?</code></a></td><td valign="top"><a href="#Equivalence-predicates">6.1 Equivalence predicates</a></td></tr>
8835 <tr><td></td><td valign="top"><a href="#index-eqv_003f-2"><code>eqv?</code></a></td><td valign="top"><a href="#Equivalence-predicates">6.1 Equivalence predicates</a></td></tr>
8836 <tr><td></td><td valign="top"><a href="#index-eval-2"><code>eval</code></a></td><td valign="top"><a href="#Eval">6.5 Eval</a></td></tr>
8837 <tr><td></td><td valign="top"><a href="#index-even_003f"><code>even?</code></a></td><td valign="top"><a href="#Numerical-operations">6.2.5 Numerical operations</a></td></tr>
8838 <tr><td></td><td valign="top"><a href="#index-exact_002d_003einexact"><code>exact-&gt;inexact</code></a></td><td valign="top"><a href="#Numerical-operations">6.2.5 Numerical operations</a></td></tr>
8839 <tr><td></td><td valign="top"><a href="#index-exact_003f"><code>exact?</code></a></td><td valign="top"><a href="#Numerical-operations">6.2.5 Numerical operations</a></td></tr>
8840 <tr><td></td><td valign="top"><a href="#index-exp"><code>exp</code></a></td><td valign="top"><a href="#Numerical-operations">6.2.5 Numerical operations</a></td></tr>
8841 <tr><td></td><td valign="top"><a href="#index-expt"><code>expt</code></a></td><td valign="top"><a href="#Numerical-operations">6.2.5 Numerical operations</a></td></tr>
8842 <tr><td colspan="3"> <hr></td></tr>
8843 <tr><th><a name="Procedures-1_fn_letter-F">F</a></th><td></td><td></td></tr>
8844 <tr><td></td><td valign="top"><a href="#index-floor"><code>floor</code></a></td><td valign="top"><a href="#Numerical-operations">6.2.5 Numerical operations</a></td></tr>
8845 <tr><td></td><td valign="top"><a href="#index-for_002deach"><code>for-each</code></a></td><td valign="top"><a href="#Control-features">6.4 Control features</a></td></tr>
8846 <tr><td></td><td valign="top"><a href="#index-force-1"><code>force</code></a></td><td valign="top"><a href="#Control-features">6.4 Control features</a></td></tr>
8847 <tr><td colspan="3"> <hr></td></tr>
8848 <tr><th><a name="Procedures-1_fn_letter-G">G</a></th><td></td><td></td></tr>
8849 <tr><td></td><td valign="top"><a href="#index-gcd"><code>gcd</code></a></td><td valign="top"><a href="#Numerical-operations">6.2.5 Numerical operations</a></td></tr>
8850 <tr><td colspan="3"> <hr></td></tr>
8851 <tr><th><a name="Procedures-1_fn_letter-I">I</a></th><td></td><td></td></tr>
8852 <tr><td></td><td valign="top"><a href="#index-if"><code>if</code></a></td><td valign="top"><a href="#Conditionals">4.1.5 Conditionals</a></td></tr>
8853 <tr><td></td><td valign="top"><a href="#index-if-1"><code>if</code></a></td><td valign="top"><a href="#Conditionals">4.1.5 Conditionals</a></td></tr>
8854 <tr><td></td><td valign="top"><a href="#index-imag_002dpart"><code>imag-part</code></a></td><td valign="top"><a href="#Numerical-operations">6.2.5 Numerical operations</a></td></tr>
8855 <tr><td></td><td valign="top"><a href="#index-inexact_002d_003eexact-1"><code>inexact-&gt;exact</code></a></td><td valign="top"><a href="#Numerical-operations">6.2.5 Numerical operations</a></td></tr>
8856 <tr><td></td><td valign="top"><a href="#index-inexact_003f"><code>inexact?</code></a></td><td valign="top"><a href="#Numerical-operations">6.2.5 Numerical operations</a></td></tr>
8857 <tr><td></td><td valign="top"><a href="#index-input_002dport_003f"><code>input-port?</code></a></td><td valign="top"><a href="#Ports">6.6.1 Ports</a></td></tr>
8858 <tr><td></td><td valign="top"><a href="#index-integer_002d_003echar"><code>integer-&gt;char</code></a></td><td valign="top"><a href="#Characters">6.3.4 Characters</a></td></tr>
8859 <tr><td></td><td valign="top"><a href="#index-integer_003f-1"><code>integer?</code></a></td><td valign="top"><a href="#Numerical-operations">6.2.5 Numerical operations</a></td></tr>
8860 <tr><td></td><td valign="top"><a href="#index-interaction_002denvironment"><code>interaction-environment</code></a></td><td valign="top"><a href="#Eval">6.5 Eval</a></td></tr>
8861 <tr><td colspan="3"> <hr></td></tr>
8862 <tr><th><a name="Procedures-1_fn_letter-L">L</a></th><td></td><td></td></tr>
8863 <tr><td></td><td valign="top"><a href="#index-lambda"><code>lambda</code></a></td><td valign="top"><a href="#Procedures">4.1.4 Procedures</a></td></tr>
8864 <tr><td></td><td valign="top"><a href="#index-lcm"><code>lcm</code></a></td><td valign="top"><a href="#Numerical-operations">6.2.5 Numerical operations</a></td></tr>
8865 <tr><td></td><td valign="top"><a href="#index-length-1"><code>length</code></a></td><td valign="top"><a href="#Pairs-and-lists">6.3.2 Pairs and lists</a></td></tr>
8866 <tr><td></td><td valign="top"><a href="#index-let"><code>let</code></a></td><td valign="top"><a href="#Binding-constructs">4.2.2 Binding constructs</a></td></tr>
8867 <tr><td></td><td valign="top"><a href="#index-let-1"><code>let</code></a></td><td valign="top"><a href="#Iteration">4.2.4 Iteration</a></td></tr>
8868 <tr><td></td><td valign="top"><a href="#index-let_002a"><code>let*</code></a></td><td valign="top"><a href="#Binding-constructs">4.2.2 Binding constructs</a></td></tr>
8869 <tr><td></td><td valign="top"><a href="#index-let_002dsyntax"><code>let-syntax</code></a></td><td valign="top"><a href="#Binding-constructs-for-syntactic-keywords">4.3.1 Binding constructs for syntactic keywords</a></td></tr>
8870 <tr><td></td><td valign="top"><a href="#index-letrec"><code>letrec</code></a></td><td valign="top"><a href="#Binding-constructs">4.2.2 Binding constructs</a></td></tr>
8871 <tr><td></td><td valign="top"><a href="#index-letrec_002dsyntax"><code>letrec-syntax</code></a></td><td valign="top"><a href="#Binding-constructs-for-syntactic-keywords">4.3.1 Binding constructs for syntactic keywords</a></td></tr>
8872 <tr><td></td><td valign="top"><a href="#index-list"><code>list</code></a></td><td valign="top"><a href="#Pairs-and-lists">6.3.2 Pairs and lists</a></td></tr>
8873 <tr><td></td><td valign="top"><a href="#index-list_002d_003estring"><code>list-&gt;string</code></a></td><td valign="top"><a href="#Strings">6.3.5 Strings</a></td></tr>
8874 <tr><td></td><td valign="top"><a href="#index-list_002d_003evector"><code>list-&gt;vector</code></a></td><td valign="top"><a href="#Vectors">6.3.6 Vectors</a></td></tr>
8875 <tr><td></td><td valign="top"><a href="#index-list_002dref"><code>list-ref</code></a></td><td valign="top"><a href="#Pairs-and-lists">6.3.2 Pairs and lists</a></td></tr>
8876 <tr><td></td><td valign="top"><a href="#index-list_002dtail"><code>list-tail</code></a></td><td valign="top"><a href="#Pairs-and-lists">6.3.2 Pairs and lists</a></td></tr>
8877 <tr><td></td><td valign="top"><a href="#index-list_003f"><code>list?</code></a></td><td valign="top"><a href="#Pairs-and-lists">6.3.2 Pairs and lists</a></td></tr>
8878 <tr><td></td><td valign="top"><a href="#index-load"><code>load</code></a></td><td valign="top"><a href="#System-interface">6.6.4 System interface</a></td></tr>
8879 <tr><td></td><td valign="top"><a href="#index-log"><code>log</code></a></td><td valign="top"><a href="#Numerical-operations">6.2.5 Numerical operations</a></td></tr>
8880 <tr><td colspan="3"> <hr></td></tr>
8881 <tr><th><a name="Procedures-1_fn_letter-M">M</a></th><td></td><td></td></tr>
8882 <tr><td></td><td valign="top"><a href="#index-magnitude"><code>magnitude</code></a></td><td valign="top"><a href="#Numerical-operations">6.2.5 Numerical operations</a></td></tr>
8883 <tr><td></td><td valign="top"><a href="#index-make_002dpolar"><code>make-polar</code></a></td><td valign="top"><a href="#Numerical-operations">6.2.5 Numerical operations</a></td></tr>
8884 <tr><td></td><td valign="top"><a href="#index-make_002drectangular"><code>make-rectangular</code></a></td><td valign="top"><a href="#Numerical-operations">6.2.5 Numerical operations</a></td></tr>
8885 <tr><td></td><td valign="top"><a href="#index-make_002dstring"><code>make-string</code></a></td><td valign="top"><a href="#Strings">6.3.5 Strings</a></td></tr>
8886 <tr><td></td><td valign="top"><a href="#index-make_002dstring-1"><code>make-string</code></a></td><td valign="top"><a href="#Strings">6.3.5 Strings</a></td></tr>
8887 <tr><td></td><td valign="top"><a href="#index-make_002dvector-1"><code>make-vector</code></a></td><td valign="top"><a href="#Vectors">6.3.6 Vectors</a></td></tr>
8888 <tr><td></td><td valign="top"><a href="#index-make_002dvector-2"><code>make-vector</code></a></td><td valign="top"><a href="#Vectors">6.3.6 Vectors</a></td></tr>
8889 <tr><td></td><td valign="top"><a href="#index-map"><code>map</code></a></td><td valign="top"><a href="#Control-features">6.4 Control features</a></td></tr>
8890 <tr><td></td><td valign="top"><a href="#index-max"><code>max</code></a></td><td valign="top"><a href="#Numerical-operations">6.2.5 Numerical operations</a></td></tr>
8891 <tr><td></td><td valign="top"><a href="#index-member"><code>member</code></a></td><td valign="top"><a href="#Pairs-and-lists">6.3.2 Pairs and lists</a></td></tr>
8892 <tr><td></td><td valign="top"><a href="#index-memq"><code>memq</code></a></td><td valign="top"><a href="#Pairs-and-lists">6.3.2 Pairs and lists</a></td></tr>
8893 <tr><td></td><td valign="top"><a href="#index-memv"><code>memv</code></a></td><td valign="top"><a href="#Pairs-and-lists">6.3.2 Pairs and lists</a></td></tr>
8894 <tr><td></td><td valign="top"><a href="#index-min"><code>min</code></a></td><td valign="top"><a href="#Numerical-operations">6.2.5 Numerical operations</a></td></tr>
8895 <tr><td></td><td valign="top"><a href="#index-modulo"><code>modulo</code></a></td><td valign="top"><a href="#Numerical-operations">6.2.5 Numerical operations</a></td></tr>
8896 <tr><td colspan="3"> <hr></td></tr>
8897 <tr><th><a name="Procedures-1_fn_letter-N">N</a></th><td></td><td></td></tr>
8898 <tr><td></td><td valign="top"><a href="#index-negative_003f"><code>negative?</code></a></td><td valign="top"><a href="#Numerical-operations">6.2.5 Numerical operations</a></td></tr>
8899 <tr><td></td><td valign="top"><a href="#index-newline"><code>newline</code></a></td><td valign="top"><a href="#Output">6.6.3 Output</a></td></tr>
8900 <tr><td></td><td valign="top"><a href="#index-newline-1"><code>newline</code></a></td><td valign="top"><a href="#Output">6.6.3 Output</a></td></tr>
8901 <tr><td></td><td valign="top"><a href="#index-not"><code>not</code></a></td><td valign="top"><a href="#Booleans">6.3.1 Booleans</a></td></tr>
8902 <tr><td></td><td valign="top"><a href="#index-null_002denvironment"><code>null-environment</code></a></td><td valign="top"><a href="#Eval">6.5 Eval</a></td></tr>
8903 <tr><td></td><td valign="top"><a href="#index-null_003f"><code>null?</code></a></td><td valign="top"><a href="#Pairs-and-lists">6.3.2 Pairs and lists</a></td></tr>
8904 <tr><td></td><td valign="top"><a href="#index-number_002d_003estring"><code>number-&gt;string</code></a></td><td valign="top"><a href="#Numerical-input-and-output">6.2.6 Numerical input and output</a></td></tr>
8905 <tr><td></td><td valign="top"><a href="#index-number_002d_003estring-1"><code>number-&gt;string</code></a></td><td valign="top"><a href="#Numerical-input-and-output">6.2.6 Numerical input and output</a></td></tr>
8906 <tr><td></td><td valign="top"><a href="#index-number_003f-2"><code>number?</code></a></td><td valign="top"><a href="#Numerical-operations">6.2.5 Numerical operations</a></td></tr>
8907 <tr><td></td><td valign="top"><a href="#index-numerator"><code>numerator</code></a></td><td valign="top"><a href="#Numerical-operations">6.2.5 Numerical operations</a></td></tr>
8908 <tr><td colspan="3"> <hr></td></tr>
8909 <tr><th><a name="Procedures-1_fn_letter-O">O</a></th><td></td><td></td></tr>
8910 <tr><td></td><td valign="top"><a href="#index-odd_003f"><code>odd?</code></a></td><td valign="top"><a href="#Numerical-operations">6.2.5 Numerical operations</a></td></tr>
8911 <tr><td></td><td valign="top"><a href="#index-open_002dinput_002dfile"><code>open-input-file</code></a></td><td valign="top"><a href="#Ports">6.6.1 Ports</a></td></tr>
8912 <tr><td></td><td valign="top"><a href="#index-open_002doutput_002dfile"><code>open-output-file</code></a></td><td valign="top"><a href="#Ports">6.6.1 Ports</a></td></tr>
8913 <tr><td></td><td valign="top"><a href="#index-or"><code>or</code></a></td><td valign="top"><a href="#Conditional">4.2.1 Conditionals</a></td></tr>
8914 <tr><td></td><td valign="top"><a href="#index-output_002dport_003f"><code>output-port?</code></a></td><td valign="top"><a href="#Ports">6.6.1 Ports</a></td></tr>
8915 <tr><td colspan="3"> <hr></td></tr>
8916 <tr><th><a name="Procedures-1_fn_letter-P">P</a></th><td></td><td></td></tr>
8917 <tr><td></td><td valign="top"><a href="#index-pair_003f-1"><code>pair?</code></a></td><td valign="top"><a href="#Pairs-and-lists">6.3.2 Pairs and lists</a></td></tr>
8918 <tr><td></td><td valign="top"><a href="#index-peek_002dchar"><code>peek-char</code></a></td><td valign="top"><a href="#Input">6.6.2 Input</a></td></tr>
8919 <tr><td></td><td valign="top"><a href="#index-peek_002dchar-1"><code>peek-char</code></a></td><td valign="top"><a href="#Input">6.6.2 Input</a></td></tr>
8920 <tr><td></td><td valign="top"><a href="#index-positive_003f"><code>positive?</code></a></td><td valign="top"><a href="#Numerical-operations">6.2.5 Numerical operations</a></td></tr>
8921 <tr><td></td><td valign="top"><a href="#index-procedure_003f-1"><code>procedure?</code></a></td><td valign="top"><a href="#Control-features">6.4 Control features</a></td></tr>
8922 <tr><td colspan="3"> <hr></td></tr>
8923 <tr><th><a name="Procedures-1_fn_letter-Q">Q</a></th><td></td><td></td></tr>
8924 <tr><td></td><td valign="top"><a href="#index-quasiquote"><code>quasiquote</code></a></td><td valign="top"><a href="#Quasiquotation">4.2.6 Quasiquotation</a></td></tr>
8925 <tr><td></td><td valign="top"><a href="#index-quote"><code>quote</code></a></td><td valign="top"><a href="#Literal-expressions">4.1.2 Literal expressions</a></td></tr>
8926 <tr><td></td><td valign="top"><a href="#index-quotient"><code>quotient</code></a></td><td valign="top"><a href="#Numerical-operations">6.2.5 Numerical operations</a></td></tr>
8927 <tr><td colspan="3"> <hr></td></tr>
8928 <tr><th><a name="Procedures-1_fn_letter-R">R</a></th><td></td><td></td></tr>
8929 <tr><td></td><td valign="top"><a href="#index-rational_003f-1"><code>rational?</code></a></td><td valign="top"><a href="#Numerical-operations">6.2.5 Numerical operations</a></td></tr>
8930 <tr><td></td><td valign="top"><a href="#index-rationalize"><code>rationalize</code></a></td><td valign="top"><a href="#Numerical-operations">6.2.5 Numerical operations</a></td></tr>
8931 <tr><td></td><td valign="top"><a href="#index-read-1"><code>read</code></a></td><td valign="top"><a href="#Input">6.6.2 Input</a></td></tr>
8932 <tr><td></td><td valign="top"><a href="#index-read-2"><code>read</code></a></td><td valign="top"><a href="#Input">6.6.2 Input</a></td></tr>
8933 <tr><td></td><td valign="top"><a href="#index-read_002dchar"><code>read-char</code></a></td><td valign="top"><a href="#Input">6.6.2 Input</a></td></tr>
8934 <tr><td></td><td valign="top"><a href="#index-read_002dchar-1"><code>read-char</code></a></td><td valign="top"><a href="#Input">6.6.2 Input</a></td></tr>
8935 <tr><td></td><td valign="top"><a href="#index-real_002dpart"><code>real-part</code></a></td><td valign="top"><a href="#Numerical-operations">6.2.5 Numerical operations</a></td></tr>
8936 <tr><td></td><td valign="top"><a href="#index-real_003f-1"><code>real?</code></a></td><td valign="top"><a href="#Numerical-operations">6.2.5 Numerical operations</a></td></tr>
8937 <tr><td></td><td valign="top"><a href="#index-remainder"><code>remainder</code></a></td><td valign="top"><a href="#Numerical-operations">6.2.5 Numerical operations</a></td></tr>
8938 <tr><td></td><td valign="top"><a href="#index-reverse"><code>reverse</code></a></td><td valign="top"><a href="#Pairs-and-lists">6.3.2 Pairs and lists</a></td></tr>
8939 <tr><td></td><td valign="top"><a href="#index-round"><code>round</code></a></td><td valign="top"><a href="#Numerical-operations">6.2.5 Numerical operations</a></td></tr>
8940 <tr><td colspan="3"> <hr></td></tr>
8941 <tr><th><a name="Procedures-1_fn_letter-S">S</a></th><td></td><td></td></tr>
8942 <tr><td></td><td valign="top"><a href="#index-scheme_002dreport_002denvironment"><code>scheme-report-environment</code></a></td><td valign="top"><a href="#Eval">6.5 Eval</a></td></tr>
8943 <tr><td></td><td valign="top"><a href="#index-set_0021"><code>set!</code></a></td><td valign="top"><a href="#Assignments">4.1.6 Assignments</a></td></tr>
8944 <tr><td></td><td valign="top"><a href="#index-set_002dcar_0021"><code>set-car!</code></a></td><td valign="top"><a href="#Pairs-and-lists">6.3.2 Pairs and lists</a></td></tr>
8945 <tr><td></td><td valign="top"><a href="#index-set_002dcdr_0021-1"><code>set-cdr!</code></a></td><td valign="top"><a href="#Pairs-and-lists">6.3.2 Pairs and lists</a></td></tr>
8946 <tr><td></td><td valign="top"><a href="#index-sin"><code>sin</code></a></td><td valign="top"><a href="#Numerical-operations">6.2.5 Numerical operations</a></td></tr>
8947 <tr><td></td><td valign="top"><a href="#index-sqrt"><code>sqrt</code></a></td><td valign="top"><a href="#Numerical-operations">6.2.5 Numerical operations</a></td></tr>
8948 <tr><td></td><td valign="top"><a href="#index-string"><code>string</code></a></td><td valign="top"><a href="#Strings">6.3.5 Strings</a></td></tr>
8949 <tr><td></td><td valign="top"><a href="#index-string_002d_003elist"><code>string-&gt;list</code></a></td><td valign="top"><a href="#Strings">6.3.5 Strings</a></td></tr>
8950 <tr><td></td><td valign="top"><a href="#index-string_002d_003enumber"><code>string-&gt;number</code></a></td><td valign="top"><a href="#Numerical-input-and-output">6.2.6 Numerical input and output</a></td></tr>
8951 <tr><td></td><td valign="top"><a href="#index-string_002d_003enumber-1"><code>string-&gt;number</code></a></td><td valign="top"><a href="#Numerical-input-and-output">6.2.6 Numerical input and output</a></td></tr>
8952 <tr><td></td><td valign="top"><a href="#index-string_002d_003esymbol"><code>string-&gt;symbol</code></a></td><td valign="top"><a href="#Symbols">6.3.3 Symbols</a></td></tr>
8953 <tr><td></td><td valign="top"><a href="#index-string_002dappend"><code>string-append</code></a></td><td valign="top"><a href="#Strings">6.3.5 Strings</a></td></tr>
8954 <tr><td></td><td valign="top"><a href="#index-string_002dci_003c_003d_003f"><code>string-ci&lt;=?</code></a></td><td valign="top"><a href="#Strings">6.3.5 Strings</a></td></tr>
8955 <tr><td></td><td valign="top"><a href="#index-string_002dci_003c_003f"><code>string-ci&lt;?</code></a></td><td valign="top"><a href="#Strings">6.3.5 Strings</a></td></tr>
8956 <tr><td></td><td valign="top"><a href="#index-string_002dci_003d_003f"><code>string-ci=?</code></a></td><td valign="top"><a href="#Strings">6.3.5 Strings</a></td></tr>
8957 <tr><td></td><td valign="top"><a href="#index-string_002dci_003e_003d_003f"><code>string-ci&gt;=?</code></a></td><td valign="top"><a href="#Strings">6.3.5 Strings</a></td></tr>
8958 <tr><td></td><td valign="top"><a href="#index-string_002dci_003e_003f"><code>string-ci&gt;?</code></a></td><td valign="top"><a href="#Strings">6.3.5 Strings</a></td></tr>
8959 <tr><td></td><td valign="top"><a href="#index-string_002dcopy"><code>string-copy</code></a></td><td valign="top"><a href="#Strings">6.3.5 Strings</a></td></tr>
8960 <tr><td></td><td valign="top"><a href="#index-string_002dfill_0021"><code>string-fill!</code></a></td><td valign="top"><a href="#Strings">6.3.5 Strings</a></td></tr>
8961 <tr><td></td><td valign="top"><a href="#index-string_002dlength-1"><code>string-length</code></a></td><td valign="top"><a href="#Strings">6.3.5 Strings</a></td></tr>
8962 <tr><td></td><td valign="top"><a href="#index-string_002dref"><code>string-ref</code></a></td><td valign="top"><a href="#Strings">6.3.5 Strings</a></td></tr>
8963 <tr><td></td><td valign="top"><a href="#index-string_002dset_0021-1"><code>string-set!</code></a></td><td valign="top"><a href="#Strings">6.3.5 Strings</a></td></tr>
8964 <tr><td></td><td valign="top"><a href="#index-string_003c_003d_003f"><code>string&lt;=?</code></a></td><td valign="top"><a href="#Strings">6.3.5 Strings</a></td></tr>
8965 <tr><td></td><td valign="top"><a href="#index-string_003c_003f"><code>string&lt;?</code></a></td><td valign="top"><a href="#Strings">6.3.5 Strings</a></td></tr>
8966 <tr><td></td><td valign="top"><a href="#index-string_003d_003f"><code>string=?</code></a></td><td valign="top"><a href="#Strings">6.3.5 Strings</a></td></tr>
8967 <tr><td></td><td valign="top"><a href="#index-string_003e_003d_003f"><code>string&gt;=?</code></a></td><td valign="top"><a href="#Strings">6.3.5 Strings</a></td></tr>
8968 <tr><td></td><td valign="top"><a href="#index-string_003e_003f"><code>string&gt;?</code></a></td><td valign="top"><a href="#Strings">6.3.5 Strings</a></td></tr>
8969 <tr><td></td><td valign="top"><a href="#index-string_003f-1"><code>string?</code></a></td><td valign="top"><a href="#Strings">6.3.5 Strings</a></td></tr>
8970 <tr><td></td><td valign="top"><a href="#index-substring"><code>substring</code></a></td><td valign="top"><a href="#Strings">6.3.5 Strings</a></td></tr>
8971 <tr><td></td><td valign="top"><a href="#index-symbol_002d_003estring-1"><code>symbol-&gt;string</code></a></td><td valign="top"><a href="#Symbols">6.3.3 Symbols</a></td></tr>
8972 <tr><td></td><td valign="top"><a href="#index-symbol_003f-1"><code>symbol?</code></a></td><td valign="top"><a href="#Symbols">6.3.3 Symbols</a></td></tr>
8973 <tr><td></td><td valign="top"><a href="#index-syntax_002drules"><code>syntax-rules</code></a></td><td valign="top"><a href="#Pattern-language">4.3.2 Pattern language</a></td></tr>
8974 <tr><td colspan="3"> <hr></td></tr>
8975 <tr><th><a name="Procedures-1_fn_letter-T">T</a></th><td></td><td></td></tr>
8976 <tr><td></td><td valign="top"><a href="#index-tan"><code>tan</code></a></td><td valign="top"><a href="#Numerical-operations">6.2.5 Numerical operations</a></td></tr>
8977 <tr><td></td><td valign="top"><a href="#index-transcript_002doff"><code>transcript-off</code></a></td><td valign="top"><a href="#System-interface">6.6.4 System interface</a></td></tr>
8978 <tr><td></td><td valign="top"><a href="#index-transcript_002don"><code>transcript-on</code></a></td><td valign="top"><a href="#System-interface">6.6.4 System interface</a></td></tr>
8979 <tr><td></td><td valign="top"><a href="#index-truncate"><code>truncate</code></a></td><td valign="top"><a href="#Numerical-operations">6.2.5 Numerical operations</a></td></tr>
8980 <tr><td colspan="3"> <hr></td></tr>
8981 <tr><th><a name="Procedures-1_fn_letter-V">V</a></th><td></td><td></td></tr>
8982 <tr><td></td><td valign="top"><a href="#index-values-1"><code>values</code></a></td><td valign="top"><a href="#Control-features">6.4 Control features</a></td></tr>
8983 <tr><td></td><td valign="top"><a href="#index-vector"><code>vector</code></a></td><td valign="top"><a href="#Vectors">6.3.6 Vectors</a></td></tr>
8984 <tr><td></td><td valign="top"><a href="#index-vector_002d_003elist"><code>vector-&gt;list</code></a></td><td valign="top"><a href="#Vectors">6.3.6 Vectors</a></td></tr>
8985 <tr><td></td><td valign="top"><a href="#index-vector_002dfill_0021"><code>vector-fill!</code></a></td><td valign="top"><a href="#Vectors">6.3.6 Vectors</a></td></tr>
8986 <tr><td></td><td valign="top"><a href="#index-vector_002dlength-1"><code>vector-length</code></a></td><td valign="top"><a href="#Vectors">6.3.6 Vectors</a></td></tr>
8987 <tr><td></td><td valign="top"><a href="#index-vector_002dref"><code>vector-ref</code></a></td><td valign="top"><a href="#Entry-format">1.3.3 Entry format</a></td></tr>
8988 <tr><td></td><td valign="top"><a href="#index-vector_002dref-1"><code>vector-ref</code></a></td><td valign="top"><a href="#Vectors">6.3.6 Vectors</a></td></tr>
8989 <tr><td></td><td valign="top"><a href="#index-vector_002dset_0021"><code>vector-set!</code></a></td><td valign="top"><a href="#Vectors">6.3.6 Vectors</a></td></tr>
8990 <tr><td></td><td valign="top"><a href="#index-vector_003f-1"><code>vector?</code></a></td><td valign="top"><a href="#Vectors">6.3.6 Vectors</a></td></tr>
8991 <tr><td colspan="3"> <hr></td></tr>
8992 <tr><th><a name="Procedures-1_fn_letter-W">W</a></th><td></td><td></td></tr>
8993 <tr><td></td><td valign="top"><a href="#index-with_002dinput_002dfrom_002dfile"><code>with-input-from-file</code></a></td><td valign="top"><a href="#Ports">6.6.1 Ports</a></td></tr>
8994 <tr><td></td><td valign="top"><a href="#index-with_002doutput_002dto_002dfile"><code>with-output-to-file</code></a></td><td valign="top"><a href="#Ports">6.6.1 Ports</a></td></tr>
8995 <tr><td></td><td valign="top"><a href="#index-write-1"><code>write</code></a></td><td valign="top"><a href="#Output">6.6.3 Output</a></td></tr>
8996 <tr><td></td><td valign="top"><a href="#index-write-2"><code>write</code></a></td><td valign="top"><a href="#Output">6.6.3 Output</a></td></tr>
8997 <tr><td></td><td valign="top"><a href="#index-write_002dchar"><code>write-char</code></a></td><td valign="top"><a href="#Output">6.6.3 Output</a></td></tr>
8998 <tr><td></td><td valign="top"><a href="#index-write_002dchar-1"><code>write-char</code></a></td><td valign="top"><a href="#Output">6.6.3 Output</a></td></tr>
8999 <tr><td colspan="3"> <hr></td></tr>
9000 <tr><th><a name="Procedures-1_fn_letter-Z">Z</a></th><td></td><td></td></tr>
9001 <tr><td></td><td valign="top"><a href="#index-zero_003f-1"><code>zero?</code></a></td><td valign="top"><a href="#Numerical-operations">6.2.5 Numerical operations</a></td></tr>
9002 <tr><td colspan="3"> <hr></td></tr>
9003 </table>
9004 <table><tr><th valign="top">Jump to: &nbsp; </th><td><a href="#Procedures-1_fn_symbol-1" class="summary-letter"><b> </b></a>
9005 &nbsp;
9006 <a href="#Procedures-1_fn_symbol-2" class="summary-letter"><b>'</b></a>
9007 &nbsp;
9008 <a href="#Procedures-1_fn_symbol-3" class="summary-letter"><b>*</b></a>
9009 &nbsp;
9010 <a href="#Procedures-1_fn_symbol-4" class="summary-letter"><b>+</b></a>
9011 &nbsp;
9012 <a href="#Procedures-1_fn_symbol-5" class="summary-letter"><b>-</b></a>
9013 &nbsp;
9014 <a href="#Procedures-1_fn_symbol-6" class="summary-letter"><b>/</b></a>
9015 &nbsp;
9016 <a href="#Procedures-1_fn_symbol-7" class="summary-letter"><b>&lt;</b></a>
9017 &nbsp;
9018 <a href="#Procedures-1_fn_symbol-8" class="summary-letter"><b>=</b></a>
9019 &nbsp;
9020 <a href="#Procedures-1_fn_symbol-9" class="summary-letter"><b>&gt;</b></a>
9021 &nbsp;
9022 <a href="#Procedures-1_fn_symbol-10" class="summary-letter"><b>`</b></a>
9023 &nbsp;
9024 <br>
9025 <a href="#Procedures-1_fn_letter-A" class="summary-letter"><b>A</b></a>
9026 &nbsp;
9027 <a href="#Procedures-1_fn_letter-B" class="summary-letter"><b>B</b></a>
9028 &nbsp;
9029 <a href="#Procedures-1_fn_letter-C" class="summary-letter"><b>C</b></a>
9030 &nbsp;
9031 <a href="#Procedures-1_fn_letter-D" class="summary-letter"><b>D</b></a>
9032 &nbsp;
9033 <a href="#Procedures-1_fn_letter-E" class="summary-letter"><b>E</b></a>
9034 &nbsp;
9035 <a href="#Procedures-1_fn_letter-F" class="summary-letter"><b>F</b></a>
9036 &nbsp;
9037 <a href="#Procedures-1_fn_letter-G" class="summary-letter"><b>G</b></a>
9038 &nbsp;
9039 <a href="#Procedures-1_fn_letter-I" class="summary-letter"><b>I</b></a>
9040 &nbsp;
9041 <a href="#Procedures-1_fn_letter-L" class="summary-letter"><b>L</b></a>
9042 &nbsp;
9043 <a href="#Procedures-1_fn_letter-M" class="summary-letter"><b>M</b></a>
9044 &nbsp;
9045 <a href="#Procedures-1_fn_letter-N" class="summary-letter"><b>N</b></a>
9046 &nbsp;
9047 <a href="#Procedures-1_fn_letter-O" class="summary-letter"><b>O</b></a>
9048 &nbsp;
9049 <a href="#Procedures-1_fn_letter-P" class="summary-letter"><b>P</b></a>
9050 &nbsp;
9051 <a href="#Procedures-1_fn_letter-Q" class="summary-letter"><b>Q</b></a>
9052 &nbsp;
9053 <a href="#Procedures-1_fn_letter-R" class="summary-letter"><b>R</b></a>
9054 &nbsp;
9055 <a href="#Procedures-1_fn_letter-S" class="summary-letter"><b>S</b></a>
9056 &nbsp;
9057 <a href="#Procedures-1_fn_letter-T" class="summary-letter"><b>T</b></a>
9058 &nbsp;
9059 <a href="#Procedures-1_fn_letter-V" class="summary-letter"><b>V</b></a>
9060 &nbsp;
9061 <a href="#Procedures-1_fn_letter-W" class="summary-letter"><b>W</b></a>
9062 &nbsp;
9063 <a href="#Procedures-1_fn_letter-Z" class="summary-letter"><b>Z</b></a>
9064 &nbsp;
9065 </td></tr></table>
9066
9067
9068
9069 <a name="SEC_Contents"></a><hr size="1"><br/><br/><br/>
9070 <table cellpadding="1" cellspacing="1" border="0">
9071 <tr><td valign="middle" align="left"><a href="#Top" title="Cover (top) of document"><img src="button-up-arrow.png" border="0" alt="Top: Revised(5) Report on the Algorithmic Language Scheme" align="middle" width="32"></a></td>
9072 <td valign="middle" align="left"><a href="#SEC_Contents" title="Table of contents"><img src="button-compass.png" border="0" alt="Contents: Table of Contents" align="middle" width="32"></a></td>
9073 <td valign="middle" align="left"><a href="#Index" title="Index"><img src="button-abc.png" border="0" alt="Index: Alphabetic index of definitions of concepts, keywords, and procedures" align="middle" width="32"></a></td>
9074 </tr></table>
9075 <h1>Table of Contents</h1>
9076 <div class="contents">
9077
9078 <ul class="toc">
9079 <li><a name="toc-Summary" href="#Summary">Summary</a></li>
9080 <li><a name="toc-Contents" href="#Contents">Contents</a></li>
9081 <li><a name="toc-Introduction-1" href="#Introduction">Introduction</a>
9082 <ul class="toc">
9083 <li><a name="toc-Background-1" href="#Background">Background</a></li>
9084 <li><a name="toc-Acknowledgements-1" href="#Acknowledgements">Acknowledgements</a></li>
9085 </ul></li>
9086 <li><a name="toc-Overview-of-Scheme-1" href="#Overview-of-Scheme">1. Overview of Scheme</a>
9087 <ul class="toc">
9088 <li><a name="toc-Semantics-1" href="#Semantics">1.1 Semantics</a></li>
9089 <li><a name="toc-Syntax-1" href="#Syntax">1.2 Syntax</a></li>
9090 <li><a name="toc-Notation-and-terminology-1" href="#Notation-and-terminology">1.3 Notation and terminology</a>
9091 <ul class="toc">
9092 <li><a name="toc-Primitive_003b-library_003b-and-optional-features-1" href="#Primitive_003b-library_003b-and-optional-features">1.3.1 Primitive; library; and optional features</a></li>
9093 <li><a name="toc-Error-situations-and-unspecified-behavior-1" href="#Error-situations-and-unspecified-behavior">1.3.2 Error situations and unspecified behavior</a></li>
9094 <li><a name="toc-Entry-format-1" href="#Entry-format">1.3.3 Entry format</a></li>
9095 <li><a name="toc-Evaluation-examples-1" href="#Evaluation-examples">1.3.4 Evaluation examples</a></li>
9096 <li><a name="toc-Naming-conventions-1" href="#Naming-conventions">1.3.5 Naming conventions</a></li>
9097 </ul>
9098 </li>
9099 </ul></li>
9100 <li><a name="toc-Lexical-conventions-1" href="#Lexical-conventions">2. Lexical conventions</a>
9101 <ul class="toc">
9102 <li><a name="toc-Identifiers-1" href="#Identifiers">2.1 Identifiers</a></li>
9103 <li><a name="toc-Whitespace-and-comments-1" href="#Whitespace-and-comments">2.2 Whitespace and comments</a></li>
9104 <li><a name="toc-Other-notations-1" href="#Other-notations">2.3 Other notations</a></li>
9105 </ul></li>
9106 <li><a name="toc-Basic-concepts-1" href="#Basic-concepts">3. Basic concepts</a>
9107 <ul class="toc">
9108 <li><a name="toc-Variables_003b-syntactic-keywords_003b-and-regions-1" href="#Variables_003b-syntactic-keywords_003b-and-regions">3.1 Variables; syntactic keywords; and regions</a></li>
9109 <li><a name="toc-Disjointness-of-types-1" href="#Disjointness-of-types">3.2 Disjointness of types</a></li>
9110 <li><a name="toc-External-representations-2" href="#External-representations">3.3 External representations</a></li>
9111 <li><a name="toc-Storage-model-1" href="#Storage-model">3.4 Storage model</a></li>
9112 <li><a name="toc-Proper-tail-recursion-1" href="#Proper-tail-recursion">3.5 Proper tail recursion</a></li>
9113 </ul></li>
9114 <li><a name="toc-Expressions-2" href="#Expressions">4. Expressions</a>
9115 <ul class="toc">
9116 <li><a name="toc-Primitive-expression-types-1" href="#Primitive-expression-types">4.1 Primitive expression types</a>
9117 <ul class="toc">
9118 <li><a name="toc-Variable-references-1" href="#Variable-references">4.1.1 Variable references</a></li>
9119 <li><a name="toc-Literal-expressions-1" href="#Literal-expressions">4.1.2 Literal expressions</a></li>
9120 <li><a name="toc-Procedure-calls-1" href="#Procedure-calls">4.1.3 Procedure calls</a></li>
9121 <li><a name="toc-Procedures-2" href="#Procedures">4.1.4 Procedures</a></li>
9122 <li><a name="toc-Conditionals-1" href="#Conditionals">4.1.5 Conditionals</a></li>
9123 <li><a name="toc-Assignments-1" href="#Assignments">4.1.6 Assignments</a></li>
9124 </ul></li>
9125 <li><a name="toc-Derived-expression-types-1" href="#Derived-expression-types">4.2 Derived expression types</a>
9126 <ul class="toc">
9127 <li><a name="toc-Conditionals-2" href="#Conditional">4.2.1 Conditionals</a></li>
9128 <li><a name="toc-Binding-constructs-1" href="#Binding-constructs">4.2.2 Binding constructs</a></li>
9129 <li><a name="toc-Sequencing-1" href="#Sequencing">4.2.3 Sequencing</a></li>
9130 <li><a name="toc-Iteration-1" href="#Iteration">4.2.4 Iteration</a></li>
9131 <li><a name="toc-Delayed-evaluation-1" href="#Delayed-evaluation">4.2.5 Delayed evaluation</a></li>
9132 <li><a name="toc-Quasiquotation-1" href="#Quasiquotation">4.2.6 Quasiquotation</a></li>
9133 </ul></li>
9134 <li><a name="toc-Macros-1" href="#Macros">4.3 Macros</a>
9135 <ul class="toc">
9136 <li><a name="toc-Binding-constructs-for-syntactic-keywords-1" href="#Binding-constructs-for-syntactic-keywords">4.3.1 Binding constructs for syntactic keywords</a></li>
9137 <li><a name="toc-Pattern-language-1" href="#Pattern-language">4.3.2 Pattern language</a></li>
9138 </ul>
9139 </li>
9140 </ul></li>
9141 <li><a name="toc-Program-structure-1" href="#Program-structure">5. Program structure</a>
9142 <ul class="toc">
9143 <li><a name="toc-Programs-1" href="#Programs">5.1 Programs</a></li>
9144 <li><a name="toc-Definitions-1" href="#Definitions">5.2 Definitions</a>
9145 <ul class="toc">
9146 <li><a name="toc-Top-level-definitions-1" href="#Top-level-definitions">5.2.1 Top level definitions</a></li>
9147 <li><a name="toc-Internal-definitions-1" href="#Internal-definitions">5.2.2 Internal definitions</a></li>
9148 </ul></li>
9149 <li><a name="toc-Syntax-definitions-1" href="#Syntax-definitions">5.3 Syntax definitions</a></li>
9150 </ul></li>
9151 <li><a name="toc-Standard-procedures-1" href="#Standard-procedures">6. Standard procedures</a>
9152 <ul class="toc">
9153 <li><a name="toc-Equivalence-predicates-1" href="#Equivalence-predicates">6.1 Equivalence predicates</a></li>
9154 <li><a name="toc-Numbers-1" href="#Numbers">6.2 Numbers</a>
9155 <ul class="toc">
9156 <li><a name="toc-Numerical-types-1" href="#Numerical-types">6.2.1 Numerical types</a></li>
9157 <li><a name="toc-Exactness-1" href="#Exactness">6.2.2 Exactness</a></li>
9158 <li><a name="toc-Implementation-restrictions-1" href="#Implementation-restrictions">6.2.3 Implementation restrictions</a></li>
9159 <li><a name="toc-Syntax-of-numerical-constants-1" href="#Syntax-of-numerical-constants">6.2.4 Syntax of numerical constants</a></li>
9160 <li><a name="toc-Numerical-operations-1" href="#Numerical-operations">6.2.5 Numerical operations</a></li>
9161 <li><a name="toc-Numerical-input-and-output-1" href="#Numerical-input-and-output">6.2.6 Numerical input and output</a></li>
9162 </ul></li>
9163 <li><a name="toc-Other-data-types-1" href="#Other-data-types">6.3 Other data types</a>
9164 <ul class="toc">
9165 <li><a name="toc-Booleans-1" href="#Booleans">6.3.1 Booleans</a></li>
9166 <li><a name="toc-Pairs-and-lists-1" href="#Pairs-and-lists">6.3.2 Pairs and lists</a></li>
9167 <li><a name="toc-Symbols-1" href="#Symbols">6.3.3 Symbols</a></li>
9168 <li><a name="toc-Characters-1" href="#Characters">6.3.4 Characters</a></li>
9169 <li><a name="toc-Strings-1" href="#Strings">6.3.5 Strings</a></li>
9170 <li><a name="toc-Vectors-1" href="#Vectors">6.3.6 Vectors</a></li>
9171 </ul></li>
9172 <li><a name="toc-Control-features-1" href="#Control-features">6.4 Control features</a></li>
9173 <li><a name="toc-Eval-1" href="#Eval">6.5 Eval</a></li>
9174 <li><a name="toc-Input-and-output-1" href="#Input-and-output">6.6 Input and output</a>
9175 <ul class="toc">
9176 <li><a name="toc-Ports-1" href="#Ports">6.6.1 Ports</a></li>
9177 <li><a name="toc-Input-1" href="#Input">6.6.2 Input</a></li>
9178 <li><a name="toc-Output-1" href="#Output">6.6.3 Output</a></li>
9179 <li><a name="toc-System-interface-1" href="#System-interface">6.6.4 System interface</a></li>
9180 </ul>
9181 </li>
9182 </ul></li>
9183 <li><a name="toc-Formal-syntax-and-semantics-1" href="#Formal-syntax-and-semantics">7. Formal syntax and semantics</a>
9184 <ul class="toc">
9185 <li><a name="toc-Formal-syntax-1" href="#Formal-syntax">7.1 Formal syntax</a>
9186 <ul class="toc">
9187 <li><a name="toc-Lexical-structure-1" href="#Lexical-structure">7.1.1 Lexical structure</a></li>
9188 <li><a name="toc-External-representations-1" href="#External-representation">7.1.2 External representations</a></li>
9189 <li><a name="toc-Expressions-1" href="#Expression">7.1.3 Expressions</a></li>
9190 <li><a name="toc-Quasiquotations-1" href="#Quasiquotations">7.1.4 Quasiquotations</a></li>
9191 <li><a name="toc-Transformers-1" href="#Transformers">7.1.5 Transformers</a></li>
9192 <li><a name="toc-Programs-and-definitions-1" href="#Programs-and-definitions">7.1.6 Programs and definitions</a></li>
9193 </ul></li>
9194 <li><a name="toc-Formal-semantics-1" href="#Formal-semantics">7.2 Formal semantics</a></li>
9195 <li><a name="toc-Derived-expression-types-2" href="#Derived-expression-type">7.3 Derived expression types</a></li>
9196 </ul></li>
9197 <li><a name="toc-Notes-1" href="#Notes">Notes</a>
9198 <ul class="toc">
9199 <li><a name="toc-Language-changes-1" href="#Language-changes">Language changes</a></li>
9200 </ul></li>
9201 <li><a name="toc-Additional-material-1" href="#Additional-material">Additional material</a></li>
9202 <li><a name="toc-Example-1" href="#Example">Example</a></li>
9203 <li><a name="toc-Bibliography-1" href="#Bibliography">Bibliography</a></li>
9204 <li><a name="toc-Alphabetic-index-of-definitions-of-concepts_002c-keywords_002c-and-procedures" href="#Index">Alphabetic index of definitions of concepts, keywords, and procedures</a>
9205 <ul class="toc">
9206 <li><a name="toc-Concepts" href="#Concepts">Concepts</a></li>
9207 <li><a name="toc-Procedures-1" href="#Procedures-1">Procedures</a></li>
9208 </ul>
9209 </li>
9210 </ul>
9211 </div>
9212 <a name="SEC_About"></a><hr size="1"><br/><br/><br/>
9213 <table cellpadding="1" cellspacing="1" border="0">
9214 <tr><td valign="middle" align="left"><a href="#Top" title="Cover (top) of document"><img src="button-up-arrow.png" border="0" alt="Top: Revised(5) Report on the Algorithmic Language Scheme" align="middle" width="32"></a></td>
9215 <td valign="middle" align="left"><a href="#SEC_Contents" title="Table of contents"><img src="button-compass.png" border="0" alt="Contents: Table of Contents" align="middle" width="32"></a></td>
9216 <td valign="middle" align="left"><a href="#Index" title="Index"><img src="button-abc.png" border="0" alt="Index: Alphabetic index of definitions of concepts, keywords, and procedures" align="middle" width="32"></a></td>
9217 </tr></table>
9218
9219 </body>
9220 </html>