Improve grd program in Gambit REPL iOS example (add "mv" command, on Windows provide...
[gambit-c.git] / examples / iOS / r5rs.html
blob53778196d70f34fa430ef3fdb718df3890a8890b
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 <Lionel.Cons@cern.ch> (original author)
6 Karl Berry <karl@freefriends.org>
7 Olaf Bachmann <obachman@mathematik.uni-kl.de>
8 and many others.
9 Maintained by: Many creative people.
10 Send bugs and suggestions to <texi2html-bug@nongnu.org>
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">
20 <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=0.25, maximum-scale=1.6">
22 <script>
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";
33 document.addEventListener("gesturestart", gestureStart, false);
35 </script>
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 <a name="Top"></a>
61 <table cellpadding="1" cellspacing="1" border="0">
62 <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>
63 <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>
64 <td valign="middle" align="left"> &nbsp; </td>
65 <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>
66 <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>
67 <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>
68 <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>
69 <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>
70 <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>
71 </tr></table>
73 <h1 class="settitle">Revised(5) Report on the Algorithmic Language Scheme</h1>
75 <br>
77 <center><a href="r5rs.pdf">[View PDF version]</a></center>
79 <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>)
80 <br>
81 </p><table>
82 <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>
83 <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>
84 <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>
85 <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>
86 <tr><td width="25%"></td></tr>
87 </table>
88 </blockquote>
90 <p><i>Dedicated to the Memory of Robert Hieb</i>
91 </p>
94 <a name="Summary"></a>
95 <h1 class="majorheading">Summary</h1>
98 <p>The report gives a defining description of the programming language
99 Scheme. Scheme is a statically scoped and properly tail-recursive
100 dialect of the Lisp programming language invented by Guy Lewis
101 Steele Jr. and Gerald Jay Sussman. It was designed to have an
102 exceptionally clear and simple semantics and few different ways to
103 form expressions. A wide variety of programming paradigms, including
104 imperative, functional, and message passing styles, find convenient
105 expression in Scheme.
106 </p>
107 <p>The introduction offers a brief history of the language and of
108 the report.
109 </p>
110 <p>The first three chapters present the fundamental ideas of the
111 language and describe the notational conventions used for describing the
112 language and for writing programs in the language.
113 </p>
114 <p>Chapters <a href="#Expressions">Expressions</a> and <a href="#Program-structure">Program structure</a> describe
115 the syntax and semantics of expressions, programs, and definitions.
116 </p>
117 <p>Chapter <a href="#Standard-procedures">Standard procedures</a> describes Scheme's built-in
118 procedures, which include all of the language's data manipulation and
119 input/output primitives.
120 </p>
121 <p>Chapter <a href="#Formal-syntax-and-semantics">Formal syntax and semantics</a> provides a formal syntax for Scheme
122 written in extended BNF, along with a formal denotational semantics.
123 An example of the use of the language follows the formal syntax and
124 semantics.
125 </p>
126 <p>The report concludes with a list of references and an
127 alphabetic index.
128 </p>
137 <hr size="1">
138 <a name="Contents"></a>
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>
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>
189 <hr size="1">
190 <a name="Introduction"></a>
191 <table cellpadding="1" cellspacing="1" border="0">
192 <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>
193 <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>
194 <td valign="middle" align="left"> &nbsp; </td>
195 <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>
196 <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>
197 <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>
198 <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>
199 <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>
200 <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>
201 </tr></table>
202 <a name="Introduction-1"></a>
203 <h1 class="unnumbered">Introduction</h1>
205 <table class="menu" border="0" cellspacing="0">
206 <tr><td align="left" valign="top"><a href="#Background">Background</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
207 </td></tr>
208 <tr><td align="left" valign="top"><a href="#Acknowledgements">Acknowledgements</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
209 </td></tr>
210 </table>
215 <p>Programming languages should be designed not by piling feature on top of
216 feature, but by removing the weaknesses and restrictions that make additional
217 features appear necessary. Scheme demonstrates that a very small number
218 of rules for forming expressions, with no restrictions on how they are
219 composed, suffice to form a practical and efficient programming language
220 that is flexible enough to support most of the major programming
221 paradigms in use today.
222 </p>
223 <p>Scheme
224 was one of the first programming languages to incorporate first class
225 procedures as in the lambda calculus, thereby proving the usefulness of
226 static scope rules and block structure in a dynamically typed language.
227 Scheme was the first major dialect of Lisp to distinguish procedures
228 from lambda expressions and symbols, to use a single lexical
229 environment for all variables, and to evaluate the operator position
230 of a procedure call in the same way as an operand position. By relying
231 entirely on procedure calls to express iteration, Scheme emphasized the
232 fact that tail-recursive procedure calls are essentially goto's that
233 pass arguments. Scheme was the first widely used programming language to
234 embrace first class escape procedures, from which all previously known
235 sequential control structures can be synthesized. A subsequent
236 version of Scheme introduced the concept of exact and inexact numbers,
237 an extension of Common Lisp's generic arithmetic.
238 More recently, Scheme became the first programming language to support
239 hygienic macros, which permit the syntax of a block-structured language
240 to be extended in a consistent and reliable manner.
241 </p>
244 <hr size="1">
245 <a name="Background"></a>
246 <table cellpadding="1" cellspacing="1" border="0">
247 <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>
248 <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>
249 <td valign="middle" align="left"> &nbsp; </td>
250 <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>
251 <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>
252 <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>
253 <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>
254 <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>
255 <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>
256 </tr></table>
257 <a name="Background-1"></a>
258 <h2 class="unnumberedsec">Background</h2>
261 <p>The first description of Scheme was written in
262 1975 [Scheme75]. A revised report [Scheme78]
263 appeared in 1978, which described the evolution
264 of the language as its MIT implementation was upgraded to support an
265 innovative compiler [Rabbit]. Three distinct projects began in
266 1981 and 1982 to use variants of Scheme for courses at MIT, Yale, and
267 Indiana University [Rees82], [MITScheme], [Scheme311]. An introductory
268 computer science textbook using Scheme was published in
269 1984 [SICP].
270 </p>
271 <p>As Scheme became more widespread,
272 local dialects began to diverge until students and researchers
273 occasionally found it difficult to understand code written at other
274 sites.
275 Fifteen representatives of the major implementations of Scheme therefore
276 met in October 1984 to work toward a better and more widely accepted
277 standard for Scheme.
278 </p>
279 <p>Their report [RRRS]
280 was published at MIT and Indiana University in the summer of 1985.
281 Further revision took place in the spring of 1986 [R3RS],
282 and in the spring of 1988 [R4RS].
283 The present report reflects further revisions agreed upon in a meeting
284 at Xerox PARC in June 1992.
285 </p>
290 <br>
291 <br>
292 <br>
294 <p>We intend this report to belong to the entire Scheme community, and so
295 we grant permission to copy it in whole or in part without fee. In
296 particular, we encourage implementors of Scheme to use this report as
297 a starting point for manuals and other documentation, modifying it as
298 necessary.
299 </p>
303 <hr size="1">
304 <a name="Acknowledgements"></a>
305 <table cellpadding="1" cellspacing="1" border="0">
306 <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>
307 <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>
308 <td valign="middle" align="left"> &nbsp; </td>
309 <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>
310 <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>
311 <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>
312 <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>
313 <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>
314 <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>
315 </tr></table>
316 <a name="Acknowledgements-1"></a>
317 <h2 class="unnumberedsec">Acknowledgements</h2>
320 <p>We would like to thank the following people for their help: Alan Bawden, Michael
321 Blair, George Carrette, Andy Cromarty, Pavel Curtis, Jeff Dalton, Olivier Danvy,
322 Ken Dickey, Bruce Duba, Marc Feeley,
323 Andy Freeman, Richard Gabriel, Yekta G&quot;ursel, Ken Haase, Robert
324 Hieb, Paul Hudak, Morry Katz, Chris Lindblad, Mark Meyer, Jim Miller, Jim Philbin,
325 John Ramsdell, Mike Shaff, Jonathan Shapiro, Julie Sussman,
326 Perry Wagle, Daniel Weise, Henry Wu, and Ozan Yigit.
327 We thank Carol Fessenden, Daniel
328 Friedman, and Christopher Haynes for permission to use text from the Scheme 311
329 version 4 reference manual. We thank Texas Instruments, Inc. for permission to
330 use text from the <em>TI Scheme Language Reference Manual</em>[TImanual85].
331 We gladly acknowledge the influence of manuals for MIT Scheme[MITScheme],
332 T[Rees84], Scheme 84[Scheme84],Common Lisp[CLtL],
333 and Algol 60[Naur63].
334 </p>
335 <p>We also thank Betty Dexter for the extreme effort she put into
336 setting this report in TeX, and Donald Knuth for designing the program
337 that caused her troubles.
338 </p>
339 <p>The Artificial Intelligence Laboratory of the
340 Massachusetts Institute of Technology, the Computer Science
341 Department of Indiana University, the Computer and Information
342 Sciences Department of the University of Oregon, and the NEC Research
343 Institute supported the preparation of this report. Support for the MIT
344 work was provided in part by
345 the Advanced Research Projects Agency of the Department of Defense under Office
346 of Naval Research contract N00014-80-C-0505. Support for the Indiana
347 University work was provided by NSF grants NCS 83-04567 and NCS
348 83-03325.
349 </p>
353 <br>
354 <br>
358 <hr size="1">
359 <a name="Overview-of-Scheme"></a>
360 <table cellpadding="1" cellspacing="1" border="0">
361 <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>
362 <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>
363 <td valign="middle" align="left"> &nbsp; </td>
364 <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>
365 <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>
366 <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>
367 <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>
368 <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>
369 <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>
370 </tr></table>
371 <a name="Overview-of-Scheme-1"></a>
372 <h1 class="chapter">1. Overview of Scheme</h1>
374 <table class="menu" border="0" cellspacing="0">
375 <tr><td align="left" valign="top"><a href="#Semantics">1.1 Semantics</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
376 </td></tr>
377 <tr><td align="left" valign="top"><a href="#Syntax">1.2 Syntax</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
378 </td></tr>
379 <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">
380 </td></tr>
381 </table>
384 <hr size="1">
385 <a name="Semantics"></a>
386 <table cellpadding="1" cellspacing="1" border="0">
387 <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>
388 <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>
389 <td valign="middle" align="left"> &nbsp; </td>
390 <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>
391 <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>
392 <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>
393 <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>
394 <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>
395 <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>
396 </tr></table>
397 <a name="Semantics-1"></a>
398 <h2 class="section">1.1 Semantics</h2>
402 <p>This section gives an overview of Scheme's semantics. A
403 detailed informal semantics is the subject of
404 chapters <a href="#Basic-concepts">Basic concepts</a> through <a href="#Standard-procedures">Standard procedures</a>. For reference
405 purposes, section <a href="#Formal-semantics">Formal semantics</a> provides a formal
406 semantics of Scheme.
407 </p>
408 <p>Following Algol, Scheme is a statically scoped programming
409 language. Each use of a variable is associated with a lexically
410 apparent binding of that variable.
411 </p>
412 <p>Scheme has latent as opposed to manifest types. Types
413 are associated with values (also called objects) rather than
414 <a name="index-object"></a>
415 with variables. (Some authors refer to languages with latent types as
416 weakly typed or dynamically typed languages.) Other languages with
417 latent types are APL, Snobol, and other dialects of Lisp. Languages
418 with manifest types (sometimes referred to as strongly typed or
419 statically typed languages) include Algol 60, Pascal, and C.
420 </p>
421 <p>All objects created in the course of a Scheme computation, including
422 procedures and continuations, have unlimited extent.
423 No Scheme object is ever destroyed. The reason that
424 implementations of Scheme do not (usually!) run out of storage is that
425 they are permitted to reclaim the storage occupied by an object if
426 they can prove that the object cannot possibly matter to any future
427 computation. Other languages in which most objects have unlimited
428 extent include APL and other Lisp dialects.
429 </p>
430 <p>Implementations of Scheme are required to be properly tail-recursive.
431 This allows the execution of an iterative computation in constant space,
432 even if the iterative computation is described by a syntactically
433 recursive procedure. Thus with a properly tail-recursive implementation,
434 iteration can be expressed using the ordinary procedure-call
435 mechanics, so that special iteration constructs are useful only as
436 syntactic sugar. See section <a href="#Proper-tail-recursion">Proper tail recursion</a>.
437 </p>
438 <p>Scheme procedures are objects in their own right. Procedures can be
439 created dynamically, stored in data structures, returned as results of
440 procedures, and so on. Other languages with these properties include
441 Common Lisp and ML.
442 </p>
444 <p>One distinguishing feature of Scheme is that continuations, which
445 in most other languages only operate behind the scenes, also have
446 &ldquo;first-class&rdquo; status. Continuations are useful for implementing a
447 wide variety of advanced control constructs, including non-local exits,
448 backtracking, and coroutines. See section <a href="#Control-features">Control features</a>.
449 </p>
450 <p>Arguments to Scheme procedures are always passed by value, which
451 means that the actual argument expressions are evaluated before the
452 procedure gains control, whether the procedure needs the result of the
453 evaluation or not. ML, C, and APL are three other languages that always
454 pass arguments by value.
455 This is distinct from the lazy-evaluation semantics of Haskell,
456 or the call-by-name semantics of Algol 60, where an argument
457 expression is not evaluated unless its value is needed by the
458 procedure.
459 </p>
462 <p>Scheme's model of arithmetic is designed to remain as independent as
463 possible of the particular ways in which numbers are represented within a
464 computer. In Scheme, every integer is a rational number, every rational is a
465 real, and every real is a complex number. Thus the distinction between integer
466 and real arithmetic, so important to many programming languages, does not
467 appear in Scheme. In its place is a distinction between exact arithmetic,
468 which corresponds to the mathematical ideal, and inexact arithmetic on
469 approximations. As in Common Lisp, exact arithmetic is not limited to
470 integers.
471 </p>
472 <hr size="1">
473 <a name="Syntax"></a>
474 <table cellpadding="1" cellspacing="1" border="0">
475 <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>
476 <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>
477 <td valign="middle" align="left"> &nbsp; </td>
478 <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>
479 <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>
480 <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>
481 <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>
482 <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>
483 <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>
484 </tr></table>
485 <a name="Syntax-1"></a>
486 <h2 class="section">1.2 Syntax</h2>
489 <p>Scheme, like most dialects of Lisp, employs a fully parenthesized prefix
490 notation for programs and (other) data; the grammar of Scheme generates a
491 sublanguage of the language used for data. An important
492 consequence of this simple, uniform representation is the susceptibility of
493 Scheme programs and data to uniform treatment by other Scheme programs.
494 For example, the <samp>eval</samp> procedure evaluates a Scheme program expressed
495 as data.
496 </p>
497 <p>The <samp>read</samp> procedure performs syntactic as well as lexical decomposition of
498 the data it reads. The <samp>read</samp> procedure parses its input as data
499 (section see section <a href="#External-representation">External representations</a>), not as program.
500 </p>
501 <p>The formal syntax of Scheme is described in section <a href="#Formal-syntax">Formal syntax</a>.
502 </p>
504 <hr size="1">
505 <a name="Notation-and-terminology"></a>
506 <table cellpadding="1" cellspacing="1" border="0">
507 <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>
508 <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>
509 <td valign="middle" align="left"> &nbsp; </td>
510 <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>
511 <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>
512 <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>
513 <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>
514 <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>
515 <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>
516 </tr></table>
517 <a name="Notation-and-terminology-1"></a>
518 <h2 class="section">1.3 Notation and terminology</h2>
520 <table class="menu" border="0" cellspacing="0">
521 <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">
522 </td></tr>
523 <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">
524 </td></tr>
525 <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">
526 </td></tr>
527 <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">
528 </td></tr>
529 <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">
530 </td></tr>
531 </table>
535 <hr size="1">
536 <a name="Primitive_003b-library_003b-and-optional-features"></a>
537 <table cellpadding="1" cellspacing="1" border="0">
538 <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>
539 <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>
540 <td valign="middle" align="left"> &nbsp; </td>
541 <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>
542 <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>
543 <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>
544 <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>
545 <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>
546 <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>
547 </tr></table>
548 <a name="Primitive_003b-library_003b-and-optional-features-1"></a>
549 <h3 class="subsection">1.3.1 Primitive; library; and optional features</h3>
553 <p>It is required that every implementation of Scheme support all
554 features that are not marked as being <em>optional</em>. Implementations are
555 <a name="index-optional"></a>
556 free to omit optional features of Scheme or to add extensions,
557 provided the extensions are not in conflict with the language reported
558 here. In particular, implementations must support portable code by
559 providing a syntactic mode that preempts no lexical conventions of this
560 report.
561 </p>
562 <p>To aid in understanding and implementing Scheme, some features are marked
563 as <em>library</em>. These can be easily implemented in terms of the other,
564 <a name="index-library"></a>
565 primitive, features. They are redundant in the strict sense of
566 the word, but they capture common patterns of usage, and are therefore
567 provided as convenient abbreviations.
568 </p>
569 <hr size="1">
570 <a name="Error-situations-and-unspecified-behavior"></a>
571 <table cellpadding="1" cellspacing="1" border="0">
572 <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>
573 <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>
574 <td valign="middle" align="left"> &nbsp; </td>
575 <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>
576 <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>
577 <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>
578 <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>
579 <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>
580 <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>
581 </tr></table>
582 <a name="Error-situations-and-unspecified-behavior-1"></a>
583 <h3 class="subsection">1.3.2 Error situations and unspecified behavior</h3>
587 <a name="index-error"></a>
588 <p>When speaking of an error situation, this report uses the phrase &ldquo;an
589 error is signalled&rdquo; to indicate that implementations must detect and
590 report the error. If such wording does not appear in the discussion of
591 an error, then implementations are not required to detect or report the
592 error, though they are encouraged to do so. An error situation that
593 implementations are not required to detect is usually referred to simply
594 as &ldquo;an error.&rdquo;
595 </p>
596 <p>For example, it is an error for a procedure to be passed an argument that
597 the procedure is not explicitly specified to handle, even though such
598 domain errors are seldom mentioned in this report. Implementations may
599 extend a procedure's domain of definition to include such arguments.
600 </p>
601 <p>This report uses the phrase &ldquo;may report a violation of an
602 implementation restriction&rdquo; to indicate circumstances under which an
603 implementation is permitted to report that it is unable to continue
604 execution of a correct program because of some restriction imposed by the
605 implementation. Implementation restrictions are of course discouraged,
606 but implementations are encouraged to report violations of implementation
607 restrictions.
608 <a name="index-implementation-restriction"></a>
609 </p>
610 <p>For example, an implementation may report a violation of an
611 implementation restriction if it does not have enough storage to run a
612 program.
613 </p>
614 <p>If the value of an expression is said to be &ldquo;unspecified,&rdquo; then
615 the expression must evaluate to some object without signalling an error,
616 but the value depends on the implementation; this report explicitly does
617 not say what value should be returned.
618 <a name="index-unspecified"></a>
619 </p>
625 <hr size="1">
626 <a name="Entry-format"></a>
627 <table cellpadding="1" cellspacing="1" border="0">
628 <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>
629 <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>
630 <td valign="middle" align="left"> &nbsp; </td>
631 <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>
632 <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>
633 <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>
634 <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>
635 <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>
636 <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>
637 </tr></table>
638 <a name="Entry-format-1"></a>
639 <h3 class="subsection">1.3.3 Entry format</h3>
642 <p>Chapters <a href="#Expressions">Expressions</a> and <a href="#Standard-procedures">Standard procedures</a> are organized
643 into entries. Each entry describes one language feature or a group of
644 related features, where a feature is either a syntactic construct or a
645 built-in procedure. An entry begins with one or more header lines of the form
646 </p>
648 <table width="100%"><tr><td align="left"> <b><var>template</var></b></td><td align="right"><var>category</var></td></tr></table>
651 <p>for required, primitive features, or
652 </p>
654 <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>
657 <p>where <var>qualifier</var> is either &ldquo;library&rdquo; or &ldquo;optional&rdquo; as defined
658 in section <a href="#Primitive_003b-library_003b-and-optional-features">Primitive; library; and optional features</a>.
659 </p>
660 <p>If <var>category</var> is &ldquo;syntax&rdquo;, the entry describes an expression
661 type, and the template gives the syntax of the expression type.
662 Components of expressions are designated by syntactic variables, which
663 are written using angle brackets, for example, <span class="roman">&lt;expression&gt;</span>,
664 <span class="roman">&lt;variable&gt;</span>. Syntactic variables should be understood to denote segments of
665 program text; for example, <span class="roman">&lt;expression&gt;</span> stands for any string of
666 characters which is a syntactically valid expression. The notation
667 </p>
668 <table><tr><td>&nbsp;</td><td><pre class="format"> <span class="roman">&lt;thing1&gt;</span> &hellip;
669 </pre></td></tr></table>
671 <p>indicates zero or more occurrences of a <span class="roman">&lt;thing&gt;</span>, and
672 </p>
673 <table><tr><td>&nbsp;</td><td><pre class="format"> <span class="roman">&lt;thing1&gt;</span> <span class="roman">&lt;thing2&gt;</span> &hellip;
674 </pre></td></tr></table>
676 <p>indicates one or more occurrences of a <span class="roman">&lt;thing&gt;</span>.
677 </p>
678 <p>If <var>category</var> is &ldquo;procedure&rdquo;, then the entry describes a procedure, and
679 the header line gives a template for a call to the procedure. Argument
680 names in the template are <var>italicized</var>. Thus the header line
681 </p>
683 <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>
686 <p>indicates that the built-in procedure <tt>vector-ref</tt> takes
687 two arguments, a vector <var>vector</var> and an exact non-negative integer
688 <var>k</var> (see below). The header lines
689 </p>
692 <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>
693 <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>
696 <p>indicate that the <tt>make-vector</tt> procedure must be defined to take
697 either one or two arguments.
698 </p>
700 <p>It is an error for an operation to be presented with an argument that it
701 is not specified to handle. For succinctness, we follow the convention
702 that if an argument name is also the name of a type listed in
703 section <a href="#Disjointness-of-types">Disjointness of types</a>, then that argument must be of the named type.
704 For example, the header line for <tt>vector-ref</tt> given above dictates that the
705 first argument to <tt>vector-ref</tt> must be a vector. The following naming
706 conventions also imply type restrictions:
707 </p>
709 <blockquote><dl compact="compact">
710 <dt> <var>obj</var></dt>
711 </dl>
712 </blockquote>
713 <p>any object
714 </p> <var>list</var>, <var>list1</var>, &hellip; <var>listj</var>, &hellip;
715 <p>list (see section see section <a href="#Pairs-and-lists">Pairs and lists</a>)
716 </p> <var>z</var>, <var>z1</var>, &hellip; <var>zj</var>, &hellip;
717 <p>complex number
718 </p> <var>x</var>, <var>x1</var>, &hellip; <var>xj</var>, &hellip;
719 <p>real number
720 </p> <var>y</var>, <var>y1</var>, &hellip; <var>yj</var>, &hellip;
721 <p>real number
722 </p> <var>q</var>, <var>q1</var>, &hellip; <var>qj</var>, &hellip;
723 <p>rational number
724 </p> <var>n</var>, <var>n1</var>, &hellip; <var>nj</var>, &hellip;
725 <p>integer
726 </p> <var>k</var>, <var>k1</var>, &hellip; <var>kj</var>, &hellip;
727 <p>exact non-negative integer
728 </p>
736 <hr size="1">
737 <a name="Evaluation-examples"></a>
738 <table cellpadding="1" cellspacing="1" border="0">
739 <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>
740 <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>
741 <td valign="middle" align="left"> &nbsp; </td>
742 <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>
743 <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>
744 <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>
745 <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>
746 <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>
747 <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>
748 </tr></table>
749 <a name="Evaluation-examples-1"></a>
750 <h3 class="subsection">1.3.4 Evaluation examples</h3>
753 <p>The symbol &ldquo;&rArr;&rdquo; used in program examples should be read
754 &ldquo;evaluates to.&rdquo; For example,
755 </p>
757 <table><tr><td>&nbsp;</td><td><pre class="example">
758 (* 5 8) ==&gt; 40
759 </pre></td></tr></table>
762 <p>means that the expression <tt>(* 5 8)</tt> evaluates to the object <tt>40</tt>.
763 Or, more precisely: the expression given by the sequence of characters
764 &ldquo;<tt>(* 5 8)</tt>&rdquo; evaluates, in the initial environment, to an object
765 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
766 representations of objects.
767 </p>
768 <hr size="1">
769 <a name="Naming-conventions"></a>
770 <table cellpadding="1" cellspacing="1" border="0">
771 <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>
772 <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>
773 <td valign="middle" align="left"> &nbsp; </td>
774 <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>
775 <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>
776 <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>
777 <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>
778 <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>
779 <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>
780 </tr></table>
781 <a name="Naming-conventions-1"></a>
782 <h3 class="subsection">1.3.5 Naming conventions</h3>
785 <p>By convention, the names of procedures that always return a boolean
786 value usually end
787 in &ldquo;<code>?</code>&rdquo;. Such procedures are called predicates.
788 <a name="index-_003f"></a>
789 </p>
790 <p>By convention, the names of procedures that store values into previously
791 allocated locations (see section see section <a href="#Storage-model">Storage model</a>) usually end in
792 &ldquo;<code>!</code>&rdquo;.
793 <a name="index-_0021"></a>
794 Such procedures are called mutation procedures.
795 By convention, the value returned by a mutation procedure is unspecified.
796 </p>
797 <p>By convention, &ldquo;<code>-&gt;</code>&rdquo; appears within the names of procedures that
798 <a name="index-_002d_003e"></a>
799 take an object of one type and return an analogous object of another type.
800 For example, <samp>list-&gt;vector</samp> takes a list and returns a vector whose
801 elements are the same as those of the list.
802 </p>
809 <hr size="1">
810 <a name="Lexical-conventions"></a>
811 <table cellpadding="1" cellspacing="1" border="0">
812 <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>
813 <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>
814 <td valign="middle" align="left"> &nbsp; </td>
815 <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>
816 <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>
817 <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>
818 <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>
819 <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>
820 <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>
821 </tr></table>
822 <a name="Lexical-conventions-1"></a>
823 <h1 class="chapter">2. Lexical conventions</h1>
825 <table class="menu" border="0" cellspacing="0">
826 <tr><td align="left" valign="top"><a href="#Identifiers">2.1 Identifiers</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
827 </td></tr>
828 <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">
829 </td></tr>
830 <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">
831 </td></tr>
832 </table>
835 <p>This section gives an informal account of some of the lexical
836 conventions used in writing Scheme programs. For a formal syntax of
837 Scheme, see section <a href="#Formal-syntax">Formal syntax</a>.
838 </p>
839 <p>Upper and lower case forms of a letter are never distinguished
840 except within character and string constants. For example, <samp>Foo</samp> is
841 the same identifier as <samp>FOO</samp>, and <tt>#x1AB</tt> is the same number as
842 <tt>#X1ab</tt>.
843 </p>
844 <hr size="1">
845 <a name="Identifiers"></a>
846 <table cellpadding="1" cellspacing="1" border="0">
847 <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>
848 <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>
849 <td valign="middle" align="left"> &nbsp; </td>
850 <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>
851 <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>
852 <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>
853 <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>
854 <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>
855 <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>
856 </tr></table>
857 <a name="Identifiers-1"></a>
858 <h2 class="section">2.1 Identifiers</h2>
862 <p>Most identifiers allowed by other programming
863 <a name="index-identifier"></a>
864 languages are also acceptable to Scheme. The precise rules for forming
865 identifiers vary among implementations of Scheme, but in all
866 implementations a sequence of letters, digits, and &ldquo;extended alphabetic
867 characters&rdquo; that begins with a character that cannot begin a number is
868 an identifier. In addition, <code>+</code>, <code>-</code>, and <code>...</code> are identifiers.
869 <a name="index-_002e_002e_002e"></a>
870 <a name="index-_002d"></a>
871 <a name="index-_002b"></a>
872 Here are some examples of identifiers:
873 </p>
875 <table><tr><td>&nbsp;</td><td><pre class="example">
876 lambda q
877 list-&gt;vector soup
878 + V17a
879 &lt;=? a34kTMNs
880 the-word-recursion-has-many-meanings
881 </pre></td></tr></table>
884 <p>Extended alphabetic characters may be used within identifiers as if
885 they were letters. The following are extended alphabetic characters:
886 </p>
888 <table><tr><td>&nbsp;</td><td><pre class="example">
889 ! $ % &amp; * + - . / : &lt; = &gt; ? @ ^ _ ~
890 </pre></td></tr></table>
893 <p>See section <a href="#Lexical-structure">Lexical structure</a> for a formal syntax of identifiers.
894 </p>
895 <p>Identifiers have two uses within Scheme programs:
896 </p>
898 <ul>
899 <li>
900 Any identifier may be used as a variable
901 or as a syntactic keyword
902 (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>).
904 </li><li>
905 When an identifier appears as a literal or within a literal
906 (see section see section <a href="#Literal-expressions">Literal expressions</a>), it is being used to denote a <em>symbol</em>
907 (see section see section <a href="#Symbols">Symbols</a>).
910 </li></ul>
912 <a name="index-syntactic-keyword"></a>
913 <a name="index-variable"></a>
919 <hr size="1">
920 <a name="Whitespace-and-comments"></a>
921 <table cellpadding="1" cellspacing="1" border="0">
922 <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>
923 <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>
924 <td valign="middle" align="left"> &nbsp; </td>
925 <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>
926 <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>
927 <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>
928 <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>
929 <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>
930 <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>
931 </tr></table>
932 <a name="Whitespace-and-comments-1"></a>
933 <h2 class="section">2.2 Whitespace and comments</h2>
936 <p><em>Whitespace</em> characters are spaces and newlines.
937 <a name="index-Whitespace"></a>
938 (Implementations typically provide additional whitespace characters such
939 as tab or page break.) Whitespace is used for improved readability and
940 as necessary to separate tokens from each other, a token being an
941 indivisible lexical unit such as an identifier or number, but is
942 otherwise insignificant. Whitespace may occur between any two tokens,
943 but not within a token. Whitespace may also occur inside a string,
944 where it is significant.
945 </p>
946 <p>A semicolon (<tt>;</tt>) indicates the start of a
947 comment. The comment continues to the
948 <a name="index-_003b"></a>
949 <a name="index-comment"></a>
950 end of the line on which the semicolon appears. Comments are invisible
951 to Scheme, but the end of the line is visible as whitespace. This
952 prevents a comment from appearing in the middle of an identifier or
953 number.
954 </p>
956 <table><tr><td>&nbsp;</td><td><pre class="example">
957 ;;; The FACT procedure computes the factorial
958 ;;; of a non-negative integer.
959 (define fact
960 (lambda (n)
961 (if (= n 0)
962 1 ;Base case: return 1
963 (* n (fact (- n 1))))))
964 </pre></td></tr></table>
968 <hr size="1">
969 <a name="Other-notations"></a>
970 <table cellpadding="1" cellspacing="1" border="0">
971 <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>
972 <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>
973 <td valign="middle" align="left"> &nbsp; </td>
974 <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>
975 <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>
976 <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>
977 <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>
978 <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>
979 <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>
980 </tr></table>
981 <a name="Other-notations-1"></a>
982 <h2 class="section">2.3 Other notations</h2>
987 <p>For a description of the notations used for numbers, see
988 section <a href="#Numbers">Numbers</a>.
989 </p>
991 <dl compact="compact">
992 <dt> <tt>. + -</tt></dt>
993 <dd><p>These are used in numbers, and may also occur anywhere in an identifier
994 except as the first character. A delimited plus or minus sign by itself
995 is also an identifier.
996 A delimited period (not occurring within a number or identifier) is used
997 in the notation for pairs (section see section <a href="#Pairs-and-lists">Pairs and lists</a>), and to indicate a
998 rest-parameter in a formal parameter list (section see section <a href="#Procedures">Procedures</a>).
999 A delimited sequence of three successive periods is also an identifier.
1000 </p>
1001 </dd>
1002 <dt> <tt>( )</tt></dt>
1003 <dd><p>Parentheses are used for grouping and to notate lists
1004 (section see section <a href="#Pairs-and-lists">Pairs and lists</a>).
1005 </p>
1006 </dd>
1007 <dt> <tt>'</tt></dt>
1008 <dd><p>The single quote character is used to indicate literal data (section see section <a href="#Literal-expressions">Literal expressions</a>).
1009 </p>
1010 </dd>
1011 <dt> <tt>&lsquo;</tt></dt>
1012 <dd><p>The backquote character is used to indicate almost-constant
1013 data (section see section <a href="#Quasiquotation">Quasiquotation</a>).
1014 </p>
1015 </dd>
1016 <dt> <tt>, ,@</tt></dt>
1017 <dd><p>The character comma and the sequence comma at-sign are used in conjunction
1018 with backquote (section see section <a href="#Quasiquotation">Quasiquotation</a>).
1019 </p>
1020 </dd>
1021 <dt> <tt>&quot;</tt></dt>
1022 <dd><p>The double quote character is used to delimit strings (section see section <a href="#Strings">Strings</a>).
1023 </p>
1024 </dd>
1025 <dt> <tt>\</tt></dt>
1026 <dd><p>Backslash is used in the syntax for character constants
1027 (section see section <a href="#Characters">Characters</a>) and as an escape character within string
1028 constants (section see section <a href="#Strings">Strings</a>).
1029 </p>
1031 </dd>
1032 <dt> <tt>[ ] { } |</tt></dt>
1033 <dd><p>Left and right square brackets and curly braces and vertical bar
1034 are reserved for possible future extensions to the language.
1035 </p>
1036 </dd>
1037 <dt> <tt>#</tt></dt>
1038 <dd><p> Sharp sign is used for a variety of purposes depending on
1039 the character that immediately follows it:
1040 </p>
1041 </dd>
1042 <dt> <tt>#t</tt> <tt>#f</tt></dt>
1043 <dd><p>These are the boolean constants (section see section <a href="#Booleans">Booleans</a>).
1044 </p>
1045 </dd>
1046 <dt> <tt>#\</tt></dt>
1047 <dd><p>This introduces a character constant (section see section <a href="#Characters">Characters</a>).
1048 </p>
1049 </dd>
1050 <dt> <tt>#(</tt></dt>
1051 <dd><p>This introduces a vector constant (section see section <a href="#Vectors">Vectors</a>). Vector constants
1052 are terminated by <tt>)</tt> .
1053 </p>
1054 </dd>
1055 <dt> <tt>#e #i #b #o #d #x</tt></dt>
1056 <dd><p>These are used in the notation for numbers (section see section <a href="#Syntax-of-numerical-constants">Syntax of numerical constants</a>).
1057 </p>
1058 </dd>
1059 </dl>
1063 <hr size="1">
1064 <a name="Basic-concepts"></a>
1065 <table cellpadding="1" cellspacing="1" border="0">
1066 <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>
1067 <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>
1068 <td valign="middle" align="left"> &nbsp; </td>
1069 <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>
1070 <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>
1071 <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>
1072 <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>
1073 <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>
1074 <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>
1075 </tr></table>
1076 <a name="Basic-concepts-1"></a>
1077 <h1 class="chapter">3. Basic concepts</h1>
1079 <table class="menu" border="0" cellspacing="0">
1080 <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">
1081 </td></tr>
1082 <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">
1083 </td></tr>
1084 <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">
1085 </td></tr>
1086 <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">
1087 </td></tr>
1088 <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">
1089 </td></tr>
1090 </table>
1094 <hr size="1">
1095 <a name="Variables_003b-syntactic-keywords_003b-and-regions"></a>
1096 <table cellpadding="1" cellspacing="1" border="0">
1097 <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>
1098 <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>
1099 <td valign="middle" align="left"> &nbsp; </td>
1100 <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>
1101 <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>
1102 <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>
1103 <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>
1104 <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>
1105 <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>
1106 </tr></table>
1107 <a name="Variables_003b-syntactic-keywords_003b-and-regions-1"></a>
1108 <h2 class="section">3.1 Variables; syntactic keywords; and regions</h2>
1113 <p>An identifier may name a type of syntax, or it may name
1114 <a name="index-identifier-1"></a>
1115 a location where a value can be stored. An identifier that names a type
1116 of syntax is called a <em>syntactic keyword</em>
1117 <a name="index-syntactic-keyword-1"></a>
1118 and is said to be <em>bound</em> to that syntax. An identifier that names a
1119 location is called a <em>variable</em> and is said to be
1120 <a name="index-variable-1"></a>
1121 <em>bound</em> to that location. The set of all visible
1122 bindings in effect at some point in a program is
1123 <a name="index-binding"></a>
1124 known as the <em>environment</em> in effect at that point. The value
1125 stored in the location to which a variable is bound is called the
1126 variable's value. By abuse of terminology, the variable is sometimes
1127 said to name the value or to be bound to the value. This is not quite
1128 accurate, but confusion rarely results from this practice.
1129 </p>
1134 <p>Certain expression types are used to create new kinds of syntax
1135 and bind syntactic keywords to those new syntaxes, while other
1136 expression types create new locations and bind variables to those
1137 locations. These expression types are called <em>binding constructs</em>.
1138 </p>
1139 <a name="index-binding-construct"></a>
1140 <p>Those that bind syntactic keywords are listed in section <a href="#Macros">Macros</a>.
1141 The most fundamental of the variable binding constructs is the
1142 <samp>lambda</samp> expression, because all other variable binding constructs
1143 can be explained in terms of <samp>lambda</samp> expressions. The other
1144 variable binding constructs are <samp>let</samp>, <samp>let*</samp>, <samp>letrec</samp>,
1145 and <samp>do</samp> expressions (see sections see section <a href="#Procedures">Procedures</a>, see section <a href="#Binding-constructs">Binding constructs</a>, and
1146 see section <a href="#Iteration">Iteration</a>).
1147 </p>
1149 <p>Like Algol and Pascal, and unlike most other dialects of Lisp
1150 except for Common Lisp, Scheme is a statically scoped language with
1151 block structure. To each place where an identifier is bound in a program
1152 there corresponds a <em>region</em> of the program text within which
1153 <a name="index-region"></a>
1154 the binding is visible. The region is determined by the particular
1155 binding construct that establishes the binding; if the binding is
1156 established by a <samp>lambda</samp> expression, for example, then its region
1157 is the entire <samp>lambda</samp> expression. Every mention of an identifier
1158 refers to the binding of the identifier that established the
1159 innermost of the regions containing the use. If there is no binding of
1160 the identifier whose region contains the use, then the use refers to the
1161 binding for the variable in the top level environment, if any
1162 (chapters see section <a href="#Expressions">Expressions</a> and see section <a href="#Standard-procedures">Standard procedures</a>); if there is no
1163 binding for the identifier,
1164 it is said to be <em>unbound</em>.
1165 <a name="index-top-level-environment"></a>
1166 <a name="index-bound"></a>
1167 <a name="index-unbound"></a>
1168 </p>
1175 <hr size="1">
1176 <a name="Disjointness-of-types"></a>
1177 <table cellpadding="1" cellspacing="1" border="0">
1178 <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>
1179 <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>
1180 <td valign="middle" align="left"> &nbsp; </td>
1181 <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>
1182 <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>
1183 <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>
1184 <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>
1185 <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>
1186 <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>
1187 </tr></table>
1188 <a name="Disjointness-of-types-1"></a>
1189 <h2 class="section">3.2 Disjointness of types</h2>
1193 <p>No object satisfies more than one of the following predicates:
1194 </p>
1196 <table><tr><td>&nbsp;</td><td><pre class="example">
1197 boolean? pair?
1198 symbol? number?
1199 char? string?
1200 vector? port?
1201 procedure?
1202 </pre></td></tr></table>
1205 <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
1206 object of its own type; it satisfies none of the above predicates.
1207 </p>
1208 <a name="index-symbol_003f"></a>
1209 <a name="index-pair_003f"></a>
1210 <a name="index-boolean_003f"></a>
1211 <a name="index-type"></a>
1213 <a name="index-vector_003f"></a>
1214 <a name="index-string_003f"></a>
1215 <a name="index-char_003f"></a>
1216 <a name="index-number_003f"></a>
1218 <a name="index-empty-list"></a>
1219 <a name="index-procedure_003f"></a>
1220 <a name="index-port_003f"></a>
1222 <p>Although there is a separate boolean type,
1223 any Scheme value can be used as a boolean value for the purpose of a
1224 conditional test. As explained in section <a href="#Booleans">Booleans</a>, all
1225 values count as true in such a test except for <tt>#f</tt>.
1226 This report uses the word &ldquo;true&rdquo; to refer to any
1227 Scheme value except <tt>#f</tt>, and the word &ldquo;false&rdquo; to refer to
1228 <tt>#f</tt>.
1229 <a name="index-false"></a>
1230 <a name="index-true"></a>
1231 </p>
1232 <hr size="1">
1233 <a name="External-representations"></a>
1234 <table cellpadding="1" cellspacing="1" border="0">
1235 <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>
1236 <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>
1237 <td valign="middle" align="left"> &nbsp; </td>
1238 <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>
1239 <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>
1240 <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>
1241 <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>
1242 <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>
1243 <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>
1244 </tr></table>
1245 <a name="External-representations-2"></a>
1246 <h2 class="section">3.3 External representations</h2>
1250 <p>An important concept in Scheme (and Lisp) is that of the <em>external
1251 representation</em> of an object as a sequence of characters. For example,
1252 an external representation of the integer 28 is the sequence of
1253 characters &ldquo;<tt>28</tt>&rdquo;, and an external representation of a list consisting
1254 of the integers 8 and 13 is the sequence of characters &ldquo;<tt>(8 13)</tt>&rdquo;.
1255 </p>
1256 <p>The external representation of an object is not necessarily unique. The
1257 integer 28 also has representations &ldquo;<tt>#e28.000</tt>&rdquo; and &ldquo;<tt>#x1c</tt>&rdquo;, and the
1258 list in the previous paragraph also has the representations &ldquo;<tt>( 08 13
1259 )</tt>&rdquo; and &ldquo;<tt>(8 . (13 . ()))</tt>&rdquo; (see section see section <a href="#Pairs-and-lists">Pairs and lists</a>).
1260 </p>
1261 <p>Many objects have standard external representations, but some, such as
1262 procedures, do not have standard representations (although particular
1263 implementations may define representations for them).
1264 </p>
1265 <p>An external representation may be written in a program to obtain the
1266 corresponding object (see <samp>quote</samp>, section see section <a href="#Literal-expressions">Literal expressions</a>).
1267 </p>
1268 <p>External representations can also be used for input and output. The
1269 procedure <samp>read</samp> (section see section <a href="#Input">Input</a>) parses external
1270 representations, and the procedure <samp>write</samp> (section see section <a href="#Output">Output</a>)
1271 generates them. Together, they provide an elegant and powerful
1272 input/output facility.
1273 </p>
1274 <p>Note that the sequence of characters &ldquo;<tt>(+ 2 6)</tt>&rdquo; is <em>not</em> an
1275 external representation of the integer 8, even though it <em>is</em> an
1276 expression evaluating to the integer 8; rather, it is an external
1277 representation of a three-element list, the elements of which are the symbol
1278 <tt>+</tt> and the integers 2 and 6. Scheme's syntax has the property that
1279 any sequence of characters that is an expression is also the external
1280 representation of some object. This can lead to confusion, since it may
1281 not be obvious out of context whether a given sequence of characters is
1282 intended to denote data or program, but it is also a source of power,
1283 since it facilitates writing programs such as interpreters and
1284 compilers that treat programs as data (or vice versa).
1285 </p>
1286 <p>The syntax of external representations of various kinds of objects
1287 accompanies the description of the primitives for manipulating the
1288 objects in the appropriate sections of chapter <a href="#Standard-procedures">Standard procedures</a>.
1289 </p>
1290 <hr size="1">
1291 <a name="Storage-model"></a>
1292 <table cellpadding="1" cellspacing="1" border="0">
1293 <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>
1294 <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>
1295 <td valign="middle" align="left"> &nbsp; </td>
1296 <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>
1297 <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>
1298 <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>
1299 <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>
1300 <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>
1301 <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>
1302 </tr></table>
1303 <a name="Storage-model-1"></a>
1304 <h2 class="section">3.4 Storage model</h2>
1308 <p>Variables and objects such as pairs, vectors, and strings implicitly
1309 denote locations or sequences of locations. A string, for
1310 <a name="index-location"></a>
1311 example, denotes as many locations as there are characters in the string.
1312 (These locations need not correspond to a full machine word.) A new value may be
1313 stored into one of these locations using the <tt>string-set!</tt> procedure, but
1314 the string continues to denote the same locations as before.
1315 </p>
1316 <p>An object fetched from a location, by a variable reference or by
1317 a procedure such as <samp>car</samp>, <samp>vector-ref</samp>, or <samp>string-ref</samp>, is
1318 equivalent in the sense of <code>eqv?</code>
1319 (section see section <a href="#Equivalence-predicates">Equivalence predicates</a>)
1320 <a name="index-eqv_003f"></a>
1321 to the object last stored in the location before the fetch.
1322 </p>
1323 <p>Every location is marked to show whether it is in use.
1324 No variable or object ever refers to a location that is not in use.
1325 Whenever this report speaks of storage being allocated for a variable
1326 or object, what is meant is that an appropriate number of locations are
1327 chosen from the set of locations that are not in use, and the chosen
1328 locations are marked to indicate that they are now in use before the variable
1329 or object is made to denote them.
1330 </p>
1331 <p>In many systems it is desirable for constants (i.e. the values of
1332 <a name="index-constant"></a>
1333 literal expressions) to reside in read-only-memory. To express this, it is
1334 convenient to imagine that every object that denotes locations is associated
1335 with a flag telling whether that object is mutable or
1336 <a name="index-mutable"></a>
1337 immutable. In such systems literal constants and the strings
1338 <a name="index-immutable"></a>
1339 returned by <code>symbol-&gt;string</code> are immutable objects, while all objects
1340 <a name="index-symbol_002d_003estring"></a>
1341 created by the other procedures listed in this report are mutable. It is an
1342 error to attempt to store a new value into a location that is denoted by an
1343 immutable object.
1344 </p>
1345 <hr size="1">
1346 <a name="Proper-tail-recursion"></a>
1347 <table cellpadding="1" cellspacing="1" border="0">
1348 <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>
1349 <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>
1350 <td valign="middle" align="left"> &nbsp; </td>
1351 <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>
1352 <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>
1353 <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>
1354 <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>
1355 <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>
1356 <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>
1357 </tr></table>
1358 <a name="Proper-tail-recursion-1"></a>
1359 <h2 class="section">3.5 Proper tail recursion</h2>
1363 <p>Implementations of Scheme are required to be
1364 <em>properly tail-recursive</em>.
1365 <a name="index-proper-tail-recursion"></a>
1366 Procedure calls that occur in certain syntactic
1367 contexts defined below are &lsquo;tail calls'. A Scheme implementation is
1368 properly tail-recursive if it supports an unbounded number of active
1369 tail calls. A call is <em>active</em> if the called procedure may still
1370 return. Note that this includes calls that may be returned from either
1371 by the current continuation or by continuations captured earlier by
1372 <samp>call-with-current-continuation</samp> that are later invoked.
1373 In the absence of captured continuations, calls could
1374 return at most once and the active calls would be those that had not
1375 yet returned.
1376 A formal definition of proper tail recursion can be found
1377 in [propertailrecursion].
1378 </p>
1380 <blockquote><p><em>Rationale:</em>
1381 </p>
1382 <p>Intuitively, no space is needed for an active tail call because the
1383 continuation that is used in the tail call has the same semantics as the
1384 continuation passed to the procedure containing the call. Although an improper
1385 implementation might use a new continuation in the call, a return
1386 to this new continuation would be followed immediately by a return
1387 to the continuation passed to the procedure. A properly tail-recursive
1388 implementation returns to that continuation directly.
1389 </p>
1390 <p>Proper tail recursion was one of the central ideas in Steele and
1391 Sussman's original version of Scheme. Their first Scheme interpreter
1392 implemented both functions and actors. Control flow was expressed using
1393 actors, which differed from functions in that they passed their results
1394 on to another actor instead of returning to a caller. In the terminology
1395 of this section, each actor finished with a tail call to another actor.
1396 </p>
1397 <p>Steele and Sussman later observed that in their interpreter the code
1398 for dealing with actors was identical to that for functions and thus
1399 there was no need to include both in the language.
1400 </p>
1401 </blockquote>
1404 <p>A <em>tail call</em> is a procedure call that occurs
1405 <a name="index-tail-call"></a>
1406 in a <em>tail context</em>. Tail contexts are defined inductively. Note
1407 that a tail context is always determined with respect to a particular lambda
1408 expression.
1409 </p>
1412 <ul>
1413 <li>
1414 The last expression within the body of a lambda expression,
1415 shown as <span class="roman">&lt;tail expression&gt;</span> below, occurs in a tail context.
1417 <table><tr><td>&nbsp;</td><td><pre class="format">(lambda &lt;formals&gt;
1418 &lt;definition&gt;* &lt;expression&gt;* &lt;tail expression&gt;)
1419 </pre></td></tr></table>
1423 </li><li>
1424 If one of the following expressions is in a tail context,
1425 then the subexpressions shown as &lt;tail expression&gt; are in a tail context.
1426 These were derived from rules in the grammar given in
1427 chapter <a href="#Formal-syntax-and-semantics">Formal syntax and semantics</a> by replacing some occurrences of &lt;expression&gt;
1428 with &lt;tail expression&gt;. Only those rules that contain tail contexts
1429 are shown here.
1432 <table><tr><td>&nbsp;</td><td><pre class="format">(if &lt;expression&gt; &lt;tail expression&gt; &lt;tail expression&gt;)
1433 (if &lt;expression&gt; &lt;tail expression&gt;)
1435 (cond &lt;cond clause&gt;+)
1436 (cond &lt;cond clause&gt;* (else &lt;tail sequence&gt;))
1438 (case &lt;expression&gt;
1439 &lt;case clause&gt;+)
1440 (case &lt;expression&gt;
1441 &lt;case clause&gt;*
1442 (else &lt;tail sequence&gt;))
1444 (and &lt;expression&gt;* &lt;tail expression&gt;)
1445 (or &lt;expression&gt;* &lt;tail expression&gt;)
1447 (let (&lt;binding spec&gt;*) &lt;tail body&gt;)
1448 (let &lt;variable&gt; (&lt;binding spec&gt;*) &lt;tail body&gt;)
1449 (let* (&lt;binding spec&gt;*) &lt;tail body&gt;)
1450 (letrec (&lt;binding spec&gt;*) &lt;tail body&gt;)
1452 (let-syntax (&lt;syntax spec&gt;*) &lt;tail body&gt;)
1453 (letrec-syntax (&lt;syntax spec&gt;*) &lt;tail body&gt;)
1455 (begin &lt;tail sequence&gt;)
1457 (do (&lt;iteration spec&gt;*)
1458 (&lt;test&gt; &lt;tail sequence&gt;)
1459 &lt;expression&gt;*)
1461 <span class="roman">where</span>
1463 &lt;cond clause&gt; &ndash;&gt; (&lt;test&gt; &lt;tail sequence&gt;)
1464 &lt;case clause&gt; &ndash;&gt; ((&lt;datum&gt;*) &lt;tail sequence&gt;)
1466 &lt;tail body&gt; &ndash;&gt; &lt;definition&gt;* &lt;tail sequence&gt;
1467 &lt;tail sequence&gt; &ndash;&gt; &lt;expression&gt;* &lt;tail expression&gt;
1468 </pre></td></tr></table>
1472 </li><li>
1473 If a <samp>cond</samp> expression is in a tail context, and has a clause of
1474 the form <samp>(<span class="roman">&lt;expression1&gt;</span> =&gt; <span class="roman">&lt;expression2&gt;</span>)</samp>
1475 then the (implied) call to
1476 the procedure that results from the evaluation of <span class="roman">&lt;expression2&gt;</span> is in a
1477 tail context. <span class="roman">&lt;expression2&gt;</span> itself is not in a tail context.
1480 </li></ul>
1483 <p>Certain built-in procedures are also required to perform tail calls.
1484 The first argument passed to <code>apply</code> and to
1485 <a name="index-apply"></a>
1486 <code>call-with-current-continuation</code>, and the second argument passed to
1487 <a name="index-call_002dwith_002dcurrent_002dcontinuation"></a>
1488 <code>call-with-values</code>, must be called via a tail call.
1489 <a name="index-call_002dwith_002dvalues"></a>
1490 Similarly, <code>eval</code> must evaluate its argument as if it
1491 <a name="index-eval"></a>
1492 were in tail position within the <code>eval</code> procedure.
1493 <a name="index-eval-1"></a>
1494 </p>
1495 <p>In the following example the only tail call is the call to <samp>f</samp>.
1496 None of the calls to <samp>g</samp> or <samp>h</samp> are tail calls. The reference to
1497 <samp>x</samp> is in a tail context, but it is not a call and thus is not a
1498 tail call.
1499 </p>
1500 <table><tr><td>&nbsp;</td><td><pre class="example">
1501 (lambda ()
1502 (if (g)
1503 (let ((x (h)))
1505 (and (g) (f))))
1506 </pre></td></tr></table>
1510 <blockquote><p><em>Note:</em>
1511 Implementations are allowed, but not required, to
1512 recognize that some non-tail calls, such as the call to <samp>h</samp>
1513 above, can be evaluated as though they were tail calls.
1514 In the example above, the <samp>let</samp> expression could be compiled
1515 as a tail call to <samp>h</samp>. (The possibility of <samp>h</samp> returning
1516 an unexpected number of values can be ignored, because in that
1517 case the effect of the <samp>let</samp> is explicitly unspecified and
1518 implementation-dependent.)
1519 </p></blockquote>
1524 <hr size="1">
1525 <a name="Expressions"></a>
1526 <table cellpadding="1" cellspacing="1" border="0">
1527 <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>
1528 <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>
1529 <td valign="middle" align="left"> &nbsp; </td>
1530 <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>
1531 <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>
1532 <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>
1533 <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>
1534 <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>
1535 <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>
1536 </tr></table>
1537 <a name="Expressions-2"></a>
1538 <h1 class="chapter">4. Expressions</h1>
1540 <table class="menu" border="0" cellspacing="0">
1541 <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">
1542 </td></tr>
1543 <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">
1544 </td></tr>
1545 <tr><td align="left" valign="top"><a href="#Macros">4.3 Macros</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
1546 </td></tr>
1547 </table>
1553 <p>Expression types are categorized as <em>primitive</em> or <em>derived</em>.
1554 Primitive expression types include variables and procedure calls.
1555 Derived expression types are not semantically primitive, but can instead
1556 be defined as macros.
1557 With the exception of <samp>quasiquote</samp>, whose macro definition is complex,
1558 the derived expressions are classified as library features.
1559 Suitable definitions are given in section <a href="#Derived-expression-type">Derived expression types</a>.
1560 </p>
1561 <hr size="1">
1562 <a name="Primitive-expression-types"></a>
1563 <table cellpadding="1" cellspacing="1" border="0">
1564 <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>
1565 <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>
1566 <td valign="middle" align="left"> &nbsp; </td>
1567 <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>
1568 <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>
1569 <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>
1570 <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>
1571 <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>
1572 <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>
1573 </tr></table>
1574 <a name="Primitive-expression-types-1"></a>
1575 <h2 class="section">4.1 Primitive expression types</h2>
1577 <table class="menu" border="0" cellspacing="0">
1578 <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">
1579 </td></tr>
1580 <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">
1581 </td></tr>
1582 <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">
1583 </td></tr>
1584 <tr><td align="left" valign="top"><a href="#Procedures">4.1.4 Procedures</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
1585 </td></tr>
1586 <tr><td align="left" valign="top"><a href="#Conditionals">4.1.5 Conditionals</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
1587 </td></tr>
1588 <tr><td align="left" valign="top"><a href="#Assignments">4.1.6 Assignments</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
1589 </td></tr>
1590 </table>
1594 <hr size="1">
1595 <a name="Variable-references"></a>
1596 <table cellpadding="1" cellspacing="1" border="0">
1597 <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>
1598 <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>
1599 <td valign="middle" align="left"> &nbsp; </td>
1600 <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>
1601 <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>
1602 <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>
1603 <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>
1604 <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>
1605 <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>
1606 </tr></table>
1607 <a name="Variable-references-1"></a>
1608 <h3 class="subsection">4.1.1 Variable references</h3>
1612 <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>
1615 <p>An expression consisting of a variable
1616 <a name="index-variable-2"></a>
1617 (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
1618 the variable reference is the value stored in the location to which the
1619 variable is bound. It is an error to reference an
1620 unbound variable.
1621 <a name="index-unbound-1"></a>
1622 </p>
1624 <table><tr><td>&nbsp;</td><td><pre class="format">(define x 28)
1625 x ==&gt; 28
1626 </pre></td></tr></table>
1630 <hr size="1">
1631 <a name="Literal-expressions"></a>
1632 <table cellpadding="1" cellspacing="1" border="0">
1633 <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>
1634 <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>
1635 <td valign="middle" align="left"> &nbsp; </td>
1636 <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>
1637 <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>
1638 <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>
1639 <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>
1640 <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>
1641 <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>
1642 </tr></table>
1643 <a name="Literal-expressions-1"></a>
1644 <h3 class="subsection">4.1.2 Literal expressions</h3>
1649 <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>
1650 <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>
1651 <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>
1654 <p><samp>(quote <span class="roman">&lt;datum&gt;</span>)</samp> evaluates to <span class="roman">&lt;datum&gt;</span>.
1655 <a name="index-_0027-1"></a>
1656 <span class="roman">&lt;Datum&gt;</span>
1657 may be any external representation of a Scheme object (see
1658 section see section <a href="#External-representations">External representations</a>). This notation is used to include literal
1659 constants in Scheme code.
1660 </p>
1662 <table><tr><td>&nbsp;</td><td><pre class="format">
1663 (quote a) ==&gt; a
1664 (quote #(a b c)) ==&gt; #(a b c)
1665 (quote (+ 1 2)) ==&gt; (+ 1 2)
1666 </pre></td></tr></table>
1669 <p><samp>(quote <span class="roman">&lt;datum&gt;</span>)</samp> may be abbreviated as
1670 <tt>'</tt><span class="roman">&lt;datum&gt;</span>. The two notations are equivalent in all
1671 respects.
1672 </p>
1674 <table><tr><td>&nbsp;</td><td><pre class="format">'a ==&gt; a
1675 '#(a b c) ==&gt; #(a b c)
1676 '() ==&gt; ()
1677 '(+ 1 2) ==&gt; (+ 1 2)
1678 '(quote a) ==&gt; (quote a)
1679 ''a ==&gt; (quote a)
1680 </pre></td></tr></table>
1683 <p>Numerical constants, string constants, character constants, and boolean
1684 constants evaluate &ldquo;to themselves&rdquo;; they need not be quoted.
1685 </p>
1687 <table><tr><td>&nbsp;</td><td><pre class="format">'&quot;abc&quot; ==&gt; &quot;abc&quot;
1688 &quot;abc&quot; ==&gt; &quot;abc&quot;
1689 '145932 ==&gt; 145932
1690 145932 ==&gt; 145932
1691 '#t ==&gt; #t
1692 #t ==&gt; #t
1693 </pre></td></tr></table>
1696 <p>As noted in section <a href="#Storage-model">Storage model</a>, it is an error to alter a constant
1697 (i.e. the value of a literal expression) using a mutation procedure like
1698 <samp>set-car!</samp> or <samp>string-set!</samp>.
1699 </p>
1703 <hr size="1">
1704 <a name="Procedure-calls"></a>
1705 <table cellpadding="1" cellspacing="1" border="0">
1706 <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>
1707 <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>
1708 <td valign="middle" align="left"> &nbsp; </td>
1709 <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>
1710 <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>
1711 <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>
1712 <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>
1713 <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>
1714 <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>
1715 </tr></table>
1716 <a name="Procedure-calls-1"></a>
1717 <h3 class="subsection">4.1.3 Procedure calls</h3>
1721 <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>
1724 <p>A procedure call is written by simply enclosing in parentheses
1725 expressions for the procedure to be called and the arguments to be
1726 passed to it. The operator and operand expressions are evaluated (in an
1727 unspecified order) and the resulting procedure is passed the resulting
1728 arguments.
1729 <a name="index-procedure-call"></a>
1730 <a name="index-call"></a>
1731 </p>
1732 <table><tr><td>&nbsp;</td><td><pre class="format">(+ 3 4) ==&gt; 7
1733 ((if #f + *) 3 4) ==&gt; 12
1734 </pre></td></tr></table>
1737 <p>A number of procedures are available as the values of variables in the
1738 initial environment; for example, the addition and multiplication
1739 procedures in the above examples are the values of the variables <samp>+</samp>
1740 and <samp>*</samp>. New procedures are created by evaluating lambda expressions
1741 (see section see section <a href="#Procedures">Procedures</a>).
1742 </p>
1744 <p>Procedure calls may return any number of values (see <code>values</code> in
1745 <a name="index-values"></a>
1746 section see section <a href="#Control-features">Control features</a>). With the exception of <samp>values</samp>
1747 the procedures available in the initial environment return one
1748 value or, for procedures such as <samp>apply</samp>, pass on the values returned
1749 by a call to one of their arguments.
1750 </p>
1751 <p>Procedure calls are also called <em>combinations</em>.
1752 </p>
1753 <a name="index-combination"></a>
1756 <blockquote><p><em>Note:</em> In contrast to other dialects of Lisp, the order of
1757 evaluation is unspecified, and the operator expression and the operand
1758 expressions are always evaluated with the same evaluation rules.
1759 </p></blockquote>
1763 <blockquote><p><em>Note:</em>
1764 Although the order of evaluation is otherwise unspecified, the effect of
1765 any concurrent evaluation of the operator and operand expressions is
1766 constrained to be consistent with some sequential order of evaluation.
1767 The order of evaluation may be chosen differently for each procedure call.
1768 </p></blockquote>
1772 <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
1773 least one subexpression, so <tt>()</tt> is not a syntactically valid
1774 expression.
1775 </p>
1776 </blockquote>
1784 <hr size="1">
1785 <a name="Procedures"></a>
1786 <table cellpadding="1" cellspacing="1" border="0">
1787 <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>
1788 <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>
1789 <td valign="middle" align="left"> &nbsp; </td>
1790 <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>
1791 <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>
1792 <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>
1793 <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>
1794 <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>
1795 <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>
1796 </tr></table>
1797 <a name="Procedures-2"></a>
1798 <h3 class="subsection">4.1.4 Procedures</h3>
1803 <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>
1805 <p><em>Syntax:</em>
1806 <span class="roman">&lt;Formals&gt;</span> should be a formal arguments list as described below,
1807 and <span class="roman">&lt;body&gt;</span> should be a sequence of one or more expressions.
1808 </p>
1809 <p><em>Semantics:</em>
1810 A lambda expression evaluates to a procedure. The environment in
1811 effect when the lambda expression was evaluated is remembered as part of the
1812 procedure. When the procedure is later called with some actual
1813 arguments, the environment in which the lambda expression was evaluated will
1814 be extended by binding the variables in the formal argument list to
1815 fresh locations, the corresponding actual argument values will be stored
1816 in those locations, and the expressions in the body of the lambda expression
1817 will be evaluated sequentially in the extended environment.
1818 The result(s) of the last expression in the body will be returned as
1819 the result(s) of the procedure call.
1820 </p>
1822 <table><tr><td>&nbsp;</td><td><pre class="format">(lambda (x) (+ x x)) ==&gt; <em></em>a procedure
1823 ((lambda (x) (+ x x)) 4) ==&gt; 8
1825 (define reverse-subtract
1826 (lambda (x y) (- y x)))
1827 (reverse-subtract 7 10) ==&gt; 3
1829 (define add4
1830 (let ((x 4))
1831 (lambda (y) (+ x y))))
1832 (add4 6) ==&gt; 10
1833 </pre></td></tr></table>
1836 <p><span class="roman">&lt;Formals&gt;</span> should have one of the following forms:
1837 </p>
1840 <ul>
1841 <li>
1842 <tt>(<span class="roman">&lt;variable1&gt;</span> &hellip;)</tt>:
1843 The procedure takes a fixed number of arguments; when the procedure is
1844 called, the arguments will be stored in the bindings of the
1845 corresponding variables.
1847 </li><li>
1848 <span class="roman">&lt;variable&gt;</span>:
1849 The procedure takes any number of arguments; when the procedure is
1850 called, the sequence of actual arguments is converted into a newly
1851 allocated list, and the list is stored in the binding of the
1852 <span class="roman">&lt;variable&gt;</span>.
1854 </li><li>
1855 <tt>(<span class="roman">&lt;variable1&gt;</span> &hellip; <span class="roman">&lt;variable_n&gt;</span> <b>.</b>
1856 <span class="roman">&lt;variable_n+1&gt;</span>)</tt>:
1857 If a space-delimited period precedes the last variable, then
1858 the procedure takes n or more arguments, where n is the
1859 number of formal arguments before the period (there must
1860 be at least one).
1861 The value stored in the binding of the last variable will be a
1862 newly allocated
1863 list of the actual arguments left over after all the other actual
1864 arguments have been matched up against the other formal arguments.
1866 </li></ul>
1869 <p>It is an error for a <span class="roman">&lt;variable&gt;</span> to appear more than once in
1870 <span class="roman">&lt;formals&gt;</span>.
1871 </p>
1873 <table><tr><td>&nbsp;</td><td><pre class="format">((lambda x x) 3 4 5 6) ==&gt; (3 4 5 6)
1874 ((lambda (x y . z) z)
1875 3 4 5 6) ==&gt; (5 6)
1876 </pre></td></tr></table>
1879 <p>Each procedure created as the result of evaluating a lambda expression is
1880 (conceptually) tagged
1881 with a storage location, in order to make <code>eqv?</code> and
1882 <a name="index-eqv_003f-1"></a>
1883 <code>eq?</code> work on procedures (see section see section <a href="#Equivalence-predicates">Equivalence predicates</a>).
1884 <a name="index-eq_003f"></a>
1885 </p>
1889 <hr size="1">
1890 <a name="Conditionals"></a>
1891 <table cellpadding="1" cellspacing="1" border="0">
1892 <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>
1893 <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>
1894 <td valign="middle" align="left"> &nbsp; </td>
1895 <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>
1896 <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>
1897 <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>
1898 <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>
1899 <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>
1900 <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>
1901 </tr></table>
1902 <a name="Conditionals-1"></a>
1903 <h3 class="subsection">4.1.5 Conditionals</h3>
1907 <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>
1908 <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>
1910 <p><em>Syntax:</em>
1911 <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
1912 expressions.
1913 </p>
1914 <p><em>Semantics:</em>
1915 An <samp>if</samp> expression is evaluated as follows: first,
1916 <span class="roman">&lt;test&gt;</span> is evaluated. If it yields a true value (see
1917 <a name="index-true-1"></a>
1918 section see section <a href="#Booleans">Booleans</a>), then <span class="roman">&lt;consequent&gt;</span> is evaluated and
1919 its value(s) is(are) returned. Otherwise <span class="roman">&lt;alternate&gt;</span> is evaluated and its
1920 value(s) is(are) returned. If <span class="roman">&lt;test&gt;</span> yields a false value and no
1921 <span class="roman">&lt;alternate&gt;</span> is specified, then the result of the expression is
1922 unspecified.
1923 </p>
1925 <table><tr><td>&nbsp;</td><td><pre class="format">(if (&gt; 3 2) 'yes 'no) ==&gt; yes
1926 (if (&gt; 2 3) 'yes 'no) ==&gt; no
1927 (if (&gt; 3 2)
1928 (- 3 2)
1929 (+ 3 2)) ==&gt; 1
1930 </pre></td></tr></table>
1936 <hr size="1">
1937 <a name="Assignments"></a>
1938 <table cellpadding="1" cellspacing="1" border="0">
1939 <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>
1940 <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>
1941 <td valign="middle" align="left"> &nbsp; </td>
1942 <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>
1943 <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>
1944 <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>
1945 <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>
1946 <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>
1947 <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>
1948 </tr></table>
1949 <a name="Assignments-1"></a>
1950 <h3 class="subsection">4.1.6 Assignments</h3>
1955 <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>
1957 <p><span class="roman">&lt;Expression&gt;</span> is evaluated, and the resulting value is stored in
1958 the location to which <span class="roman">&lt;variable&gt;</span> is bound. <span class="roman">&lt;Variable&gt;</span> must
1959 be bound either in some region enclosing the <samp>set!</samp> expression
1960 <a name="index-region-1"></a>
1961 or at top level. The result of the <samp>set!</samp> expression is
1962 unspecified.
1963 </p>
1965 <table><tr><td>&nbsp;</td><td><pre class="format">(define x 2)
1966 (+ x 1) ==&gt; 3
1967 (set! x 4) ==&gt; <em>unspecified</em>
1968 (+ x 1) ==&gt; 5
1969 </pre></td></tr></table>
1975 <hr size="1">
1976 <a name="Derived-expression-types"></a>
1977 <table cellpadding="1" cellspacing="1" border="0">
1978 <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>
1979 <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>
1980 <td valign="middle" align="left"> &nbsp; </td>
1981 <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>
1982 <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>
1983 <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>
1984 <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>
1985 <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>
1986 <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>
1987 </tr></table>
1988 <a name="Derived-expression-types-1"></a>
1989 <h2 class="section">4.2 Derived expression types</h2>
1991 <table class="menu" border="0" cellspacing="0">
1992 <tr><td align="left" valign="top"><a href="#Conditional">4.2.1 Conditionals</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
1993 </td></tr>
1994 <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">
1995 </td></tr>
1996 <tr><td align="left" valign="top"><a href="#Sequencing">4.2.3 Sequencing</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
1997 </td></tr>
1998 <tr><td align="left" valign="top"><a href="#Iteration">4.2.4 Iteration</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
1999 </td></tr>
2000 <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">
2001 </td></tr>
2002 <tr><td align="left" valign="top"><a href="#Quasiquotation">4.2.6 Quasiquotation</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
2003 </td></tr>
2004 </table>
2008 <p>The constructs in this section are hygienic, as discussed in
2009 section <a href="#Macros">Macros</a>.
2010 For reference purposes, section <a href="#Derived-expression-type">Derived expression types</a> gives macro definitions
2011 that will convert most of the constructs described in this section
2012 into the primitive constructs described in the previous section.
2013 </p>
2016 <hr size="1">
2017 <a name="Conditional"></a>
2018 <table cellpadding="1" cellspacing="1" border="0">
2019 <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>
2020 <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>
2021 <td valign="middle" align="left"> &nbsp; </td>
2022 <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>
2023 <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>
2024 <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>
2025 <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>
2026 <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>
2027 <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>
2028 </tr></table>
2029 <a name="Conditionals-2"></a>
2030 <h3 class="subsection">4.2.1 Conditionals</h3>
2034 <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>
2036 <p><em>Syntax:</em>
2037 Each <span class="roman">&lt;clause&gt;</span> should be of the form
2038 </p>
2039 <table><tr><td>&nbsp;</td><td><pre class="format">(<span class="roman">&lt;test&gt;</span> <span class="roman">&lt;expression1&gt;</span> &hellip;)
2040 </pre></td></tr></table>
2042 <p>where <span class="roman">&lt;test&gt;</span> is any expression. Alternatively, a <span class="roman">&lt;clause&gt;</span> may be
2043 of the form
2044 </p>
2045 <table><tr><td>&nbsp;</td><td><pre class="format">(<span class="roman">&lt;test&gt;</span> =&gt; <span class="roman">&lt;expression&gt;</span>)
2046 </pre></td></tr></table>
2048 <p>The last <span class="roman">&lt;clause&gt;</span> may be
2049 an &ldquo;else clause,&rdquo; which has the form
2050 </p>
2051 <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>
2052 </pre></td></tr></table>
2055 <a name="index-else"></a>
2057 <a name="index-_003d_003e"></a>
2059 <p><em>Semantics:</em>
2060 A <samp>cond</samp> expression is evaluated by evaluating the <span class="roman">&lt;test&gt;</span>
2061 expressions of successive <span class="roman">&lt;clause&gt;</span>s in order until one of them
2062 evaluates to a true value (see
2063 <a name="index-true-2"></a>
2064 section see section <a href="#Booleans">Booleans</a>). When a <span class="roman">&lt;test&gt;</span> evaluates to a true
2065 value, then the remaining <span class="roman">&lt;expression&gt;</span>s in its <span class="roman">&lt;clause&gt;</span> are
2066 evaluated in order, and the result(s) of the last <span class="roman">&lt;expression&gt;</span> in the
2067 <span class="roman">&lt;clause&gt;</span> is(are) returned as the result(s) of the entire <samp>cond</samp>
2068 expression. If the selected <span class="roman">&lt;clause&gt;</span> contains only the
2069 <span class="roman">&lt;test&gt;</span> and no <span class="roman">&lt;expression&gt;</span>s, then the value of the
2070 <span class="roman">&lt;test&gt;</span> is returned as the result. If the selected <span class="roman">&lt;clause&gt;</span> uses the
2071 <code>=&gt;</code> alternate form, then the <span class="roman">&lt;expression&gt;</span> is evaluated.
2072 <a name="index-_003d_003e-1"></a>
2073 Its value must be a procedure that accepts one argument; this procedure is then
2074 called on the value of the <span class="roman">&lt;test&gt;</span> and the value(s) returned by this
2075 procedure is(are) returned by the <samp>cond</samp> expression.
2076 If all <span class="roman">&lt;test&gt;</span>s evaluate
2077 to false values, and there is no else clause, then the result of
2078 the conditional expression is unspecified; if there is an else
2079 clause, then its <span class="roman">&lt;expression&gt;</span>s are evaluated, and the value(s) of
2080 the last one is(are) returned.
2081 </p>
2083 <table><tr><td>&nbsp;</td><td><pre class="format">(cond ((&gt; 3 2) 'greater)
2084 ((&lt; 3 2) 'less)) ==&gt; greater
2086 (cond ((&gt; 3 3) 'greater)
2087 ((&lt; 3 3) 'less)
2088 (else 'equal)) ==&gt; equal
2090 (cond ((assv 'b '((a 1) (b 2))) =&gt; cadr)
2091 (else #f)) ==&gt; 2
2092 </pre></td></tr></table>
2100 <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>
2102 <p><em>Syntax:</em>
2103 <span class="roman">&lt;Key&gt;</span> may be any expression. Each <span class="roman">&lt;clause&gt;</span> should have
2104 the form
2105 </p>
2106 <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>
2107 </pre></td></tr></table>
2109 <p>where each <span class="roman">&lt;datum&gt;</span> is an external representation of some object.
2110 All the <span class="roman">&lt;datum&gt;</span>s must be distinct.
2111 The last <span class="roman">&lt;clause&gt;</span> may be an &ldquo;else clause,&rdquo; which has the form
2112 </p>
2113 <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>
2114 </pre></td></tr></table>
2117 <a name="index-else-1"></a>
2119 <p><em>Semantics:</em>
2120 A <samp>case</samp> expression is evaluated as follows. <span class="roman">&lt;Key&gt;</span> is
2121 evaluated and its result is compared against each <span class="roman">&lt;datum&gt;</span>. If the
2122 result of evaluating <span class="roman">&lt;key&gt;</span> is equivalent (in the sense of
2123 <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
2124 expressions in the corresponding <span class="roman">&lt;clause&gt;</span> are evaluated from left
2125 to right and the result(s) of the last expression in the <span class="roman">&lt;clause&gt;</span> is(are)
2126 returned as the result(s) of the <samp>case</samp> expression. If the result of
2127 evaluating <span class="roman">&lt;key&gt;</span> is different from every <span class="roman">&lt;datum&gt;</span>, then if
2128 there is an else clause its expressions are evaluated and the
2129 result(s) of the last is(are) the result(s) of the <samp>case</samp> expression;
2130 otherwise the result of the <samp>case</samp> expression is unspecified.
2131 </p>
2133 <table><tr><td>&nbsp;</td><td><pre class="format">(case (* 2 3)
2134 ((2 3 5 7) 'prime)
2135 ((1 4 6 8 9) 'composite)) ==&gt; composite
2136 (case (car '(c d))
2137 ((a) 'a)
2138 ((b) 'b)) ==&gt; <em>unspecified</em>
2139 (case (car '(c d))
2140 ((a e i o u) 'vowel)
2141 ((w y) 'semivowel)
2142 (else 'consonant)) ==&gt; consonant
2143 </pre></td></tr></table>
2150 <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>
2152 <p>The <span class="roman">&lt;test&gt;</span> expressions are evaluated from left to right, and the
2153 value of the first expression that evaluates to a false value (see
2154 section see section <a href="#Booleans">Booleans</a>) is returned. Any remaining expressions
2155 are not evaluated. If all the expressions evaluate to true values, the
2156 value of the last expression is returned. If there are no expressions
2157 then <tt>#t</tt> is returned.
2158 </p>
2160 <table><tr><td>&nbsp;</td><td><pre class="format">(and (= 2 2) (&gt; 2 1)) ==&gt; #t
2161 (and (= 2 2) (&lt; 2 1)) ==&gt; #f
2162 (and 1 2 'c '(f g)) ==&gt; (f g)
2163 (and) ==&gt; #t
2164 </pre></td></tr></table>
2171 <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>
2173 <p>The <span class="roman">&lt;test&gt;</span> expressions are evaluated from left to right, and the value of the
2174 first expression that evaluates to a true value (see
2175 section see section <a href="#Booleans">Booleans</a>) is returned. Any remaining expressions
2176 are not evaluated. If all expressions evaluate to false values, the
2177 value of the last expression is returned. If there are no
2178 expressions then <tt>#f</tt> is returned.
2179 </p>
2181 <table><tr><td>&nbsp;</td><td><pre class="format">(or (= 2 2) (&gt; 2 1)) ==&gt; #t
2182 (or (= 2 2) (&lt; 2 1)) ==&gt; #t
2183 (or #f #f #f) ==&gt; #f
2184 (or (memq 'b '(a b c))
2185 (/ 3 0)) ==&gt; (b c)
2186 </pre></td></tr></table>
2192 <hr size="1">
2193 <a name="Binding-constructs"></a>
2194 <table cellpadding="1" cellspacing="1" border="0">
2195 <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>
2196 <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>
2197 <td valign="middle" align="left"> &nbsp; </td>
2198 <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>
2199 <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>
2200 <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>
2201 <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>
2202 <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>
2203 <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>
2204 </tr></table>
2205 <a name="Binding-constructs-1"></a>
2206 <h3 class="subsection">4.2.2 Binding constructs</h3>
2209 <p>The three binding constructs <samp>let</samp>, <samp>let*</samp>, and <samp>letrec</samp>
2210 give Scheme a block structure, like Algol 60. The syntax of the three
2211 constructs is identical, but they differ in the regions they establish
2212 <a name="index-region-2"></a>
2213 for their variable bindings. In a <samp>let</samp> expression, the initial
2214 values are computed before any of the variables become bound; in a
2215 <samp>let*</samp> expression, the bindings and evaluations are performed
2216 sequentially; while in a <samp>letrec</samp> expression, all the bindings are in
2217 effect while their initial values are being computed, thus allowing
2218 mutually recursive definitions.
2219 </p>
2221 <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>
2223 <p><em>Syntax:</em>
2224 <span class="roman">&lt;Bindings&gt;</span> should have the form
2225 </p>
2226 <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>
2227 </pre></td></tr></table>
2229 <p>where each <span class="roman">&lt;init&gt;</span> is an expression, and <span class="roman">&lt;body&gt;</span> should be a
2230 sequence of one or more expressions. It is
2231 an error for a <span class="roman">&lt;variable&gt;</span> to appear more than once in the list of variables
2232 being bound.
2233 </p>
2234 <p><em>Semantics:</em>
2235 The <span class="roman">&lt;init&gt;</span>s are evaluated in the current environment (in some
2236 unspecified order), the <span class="roman">&lt;variable&gt;</span>s are bound to fresh locations
2237 holding the results, the <span class="roman">&lt;body&gt;</span> is evaluated in the extended
2238 environment, and the value(s) of the last expression of <span class="roman">&lt;body&gt;</span>
2239 is(are) returned. Each binding of a <span class="roman">&lt;variable&gt;</span> has <span class="roman">&lt;body&gt;</span> as its
2240 region.
2241 <a name="index-region-3"></a>
2242 </p>
2244 <table><tr><td>&nbsp;</td><td><pre class="format">(let ((x 2) (y 3))
2245 (* x y)) ==&gt; 6
2247 (let ((x 2) (y 3))
2248 (let ((x 7)
2249 (z (+ x y)))
2250 (* z x))) ==&gt; 35
2251 </pre></td></tr></table>
2254 <p>See also named <samp>let</samp>, section <a href="#Iteration">Iteration</a>.
2255 </p>
2260 <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>
2263 <p><em>Syntax:</em>
2264 <span class="roman">&lt;Bindings&gt;</span> should have the form
2265 </p>
2266 <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>
2267 </pre></td></tr></table>
2269 <p>and <span class="roman">&lt;body&gt;</span> should be a sequence of
2270 one or more expressions.
2271 </p>
2272 <p><em>Semantics:</em>
2273 <samp>Let*</samp> is similar to <samp>let</samp>, but the bindings are performed
2274 sequentially from left to right, and the region of a binding indicated
2275 <a name="index-region-4"></a>
2276 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>
2277 expression to the right of the binding. Thus the second binding is done
2278 in an environment in which the first binding is visible, and so on.
2279 </p>
2281 <table><tr><td>&nbsp;</td><td><pre class="format">(let ((x 2) (y 3))
2282 (let* ((x 7)
2283 (z (+ x y)))
2284 (* z x))) ==&gt; 70
2285 </pre></td></tr></table>
2292 <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>
2294 <p><em>Syntax:</em>
2295 <span class="roman">&lt;Bindings&gt;</span> should have the form
2296 </p>
2297 <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>
2298 </pre></td></tr></table>
2300 <p>and <span class="roman">&lt;body&gt;</span> should be a sequence of
2301 one or more expressions. It is an error for a <span class="roman">&lt;variable&gt;</span> to appear more
2302 than once in the list of variables being bound.
2303 </p>
2304 <p><em>Semantics:</em>
2305 The <span class="roman">&lt;variable&gt;</span>s are bound to fresh locations holding undefined
2306 values, the <span class="roman">&lt;init&gt;</span>s are evaluated in the resulting environment (in
2307 some unspecified order), each <span class="roman">&lt;variable&gt;</span> is assigned to the result
2308 of the corresponding <span class="roman">&lt;init&gt;</span>, the <span class="roman">&lt;body&gt;</span> is evaluated in the
2309 resulting environment, and the value(s) of the last expression in
2310 <span class="roman">&lt;body&gt;</span> is(are) returned. Each binding of a <span class="roman">&lt;variable&gt;</span> has the
2311 entire <samp>letrec</samp> expression as its region, making it possible to
2312 <a name="index-region-5"></a>
2313 define mutually recursive procedures.
2314 </p>
2316 <table><tr><td>&nbsp;</td><td><pre class="format">(letrec ((even?
2317 (lambda (n)
2318 (if (zero? n)
2320 (odd? (- n 1)))))
2321 (odd?
2322 (lambda (n)
2323 (if (zero? n)
2325 (even? (- n 1))))))
2326 (even? 88))
2327 ==&gt; #t
2328 </pre></td></tr></table>
2331 <p>One restriction on <samp>letrec</samp> is very important: it must be possible
2332 to evaluate each <span class="roman">&lt;init&gt;</span> without assigning or referring to the value of any
2333 <span class="roman">&lt;variable&gt;</span>. If this restriction is violated, then it is an error. The
2334 restriction is necessary because Scheme passes arguments by value rather than by
2335 name. In the most common uses of <samp>letrec</samp>, all the <span class="roman">&lt;init&gt;</span>s are
2336 lambda expressions and the restriction is satisfied automatically.
2337 </p>
2342 <hr size="1">
2343 <a name="Sequencing"></a>
2344 <table cellpadding="1" cellspacing="1" border="0">
2345 <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>
2346 <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>
2347 <td valign="middle" align="left"> &nbsp; </td>
2348 <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>
2349 <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>
2350 <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>
2351 <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>
2352 <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>
2353 <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>
2354 </tr></table>
2355 <a name="Sequencing-1"></a>
2356 <h3 class="subsection">4.2.3 Sequencing</h3>
2360 <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>
2362 <p>The <span class="roman">&lt;expression&gt;</span>s are evaluated sequentially from left to right,
2363 and the value(s) of the last <span class="roman">&lt;expression&gt;</span> is(are) returned. This
2364 expression type is used to sequence side effects such as input and
2365 output.
2366 </p>
2368 <table><tr><td>&nbsp;</td><td><pre class="format">(define x 0)
2370 (begin (set! x 5)
2371 (+ x 1)) ==&gt; 6
2373 (begin (display &quot;4 plus 1 equals &quot;)
2374 (display (+ 4 1))) ==&gt; <em>unspecified</em>
2375 <em>and prints</em> 4 plus 1 equals 5
2376 </pre></td></tr></table>
2382 <hr size="1">
2383 <a name="Iteration"></a>
2384 <table cellpadding="1" cellspacing="1" border="0">
2385 <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>
2386 <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>
2387 <td valign="middle" align="left"> &nbsp; </td>
2388 <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>
2389 <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>
2390 <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>
2391 <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>
2392 <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>
2393 <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>
2394 </tr></table>
2395 <a name="Iteration-1"></a>
2396 <h3 class="subsection">4.2.4 Iteration</h3>
2401 <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>
2402 <a name="index-do-1"></a>
2404 <p><samp>Do</samp> is an iteration construct. It specifies a set of variables to
2405 be bound, how they are to be initialized at the start, and how they are
2406 to be updated on each iteration. When a termination condition is met,
2407 the loop exits after evaluating the <span class="roman">&lt;expression&gt;</span>s.
2408 </p>
2409 <p><samp>Do</samp> expressions are evaluated as follows:
2410 The <span class="roman">&lt;init&gt;</span> expressions are evaluated (in some unspecified order),
2411 the <span class="roman">&lt;variable&gt;</span>s are bound to fresh locations, the results of the
2412 <span class="roman">&lt;init&gt;</span> expressions are stored in the bindings of the
2413 <span class="roman">&lt;variable&gt;</span>s, and then the iteration phase begins.
2414 </p>
2415 <p>Each iteration begins by evaluating <span class="roman">&lt;test&gt;</span>; if the result is
2416 false (see section see section <a href="#Booleans">Booleans</a>), then the <span class="roman">&lt;command&gt;</span>
2417 expressions are evaluated in order for effect, the <span class="roman">&lt;step&gt;</span>
2418 expressions are evaluated in some unspecified order, the
2419 <span class="roman">&lt;variable&gt;</span>s are bound to fresh locations, the results of the
2420 <span class="roman">&lt;step&gt;</span>s are stored in the bindings of the
2421 <span class="roman">&lt;variable&gt;</span>s, and the next iteration begins.
2422 </p>
2423 <p>If <span class="roman">&lt;test&gt;</span> evaluates to a true value, then the
2424 <span class="roman">&lt;expression&gt;</span>s are evaluated from left to right and the value(s) of
2425 the last <span class="roman">&lt;expression&gt;</span> is(are) returned. If no <span class="roman">&lt;expression&gt;</span>s
2426 are present, then the value of the <samp>do</samp> expression is unspecified.
2427 </p>
2428 <p>The region of the binding of a <span class="roman">&lt;variable&gt;</span>
2429 <a name="index-region-6"></a>
2430 consists of the entire <samp>do</samp> expression except for the <span class="roman">&lt;init&gt;</span>s.
2431 It is an error for a <span class="roman">&lt;variable&gt;</span> to appear more than once in the
2432 list of <samp>do</samp> variables.
2433 </p>
2434 <p>A <span class="roman">&lt;step&gt;</span> may be omitted, in which case the effect is the
2435 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
2436 been written instead of <samp>(<span class="roman">&lt;variable&gt;</span> <span class="roman">&lt;init&gt;</span>)</samp>.
2437 </p>
2439 <table><tr><td>&nbsp;</td><td><pre class="format">(do ((vec (make-vector 5))
2440 (i 0 (+ i 1)))
2441 ((= i 5) vec)
2442 (vector-set! vec i i)) ==&gt; #(0 1 2 3 4)
2444 (let ((x '(1 3 5 7 9)))
2445 (do ((x x (cdr x))
2446 (sum 0 (+ sum (car x))))
2447 ((null? x) sum))) ==&gt; 25
2448 </pre></td></tr></table>
2454 <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>
2457 <p>&ldquo;Named <samp>let</samp>&rdquo; is a variant on the syntax of <code>let</code> which provides
2458 <a name="index-let-2"></a>
2459 a more general looping construct than <samp>do</samp> and may also be used to express
2460 recursions.
2461 It has the same syntax and semantics as ordinary <samp>let</samp>
2462 except that <span class="roman">&lt;variable&gt;</span> is bound within <span class="roman">&lt;body&gt;</span> to a procedure
2463 whose formal arguments are the bound variables and whose body is
2464 <span class="roman">&lt;body&gt;</span>. Thus the execution of <span class="roman">&lt;body&gt;</span> may be repeated by
2465 invoking the procedure named by <span class="roman">&lt;variable&gt;</span>.
2466 </p>
2468 <table><tr><td>&nbsp;</td><td><pre class="format">(let loop ((numbers '(3 -2 1 6 -5))
2469 (nonneg '())
2470 (neg '()))
2471 (cond ((null? numbers) (list nonneg neg))
2472 ((&gt;= (car numbers) 0)
2473 (loop (cdr numbers)
2474 (cons (car numbers) nonneg)
2475 neg))
2476 ((&lt; (car numbers) 0)
2477 (loop (cdr numbers)
2478 nonneg
2479 (cons (car numbers) neg)))))
2480 ==&gt; ((6 1 3) (-5 -2))
2481 </pre></td></tr></table>
2487 <hr size="1">
2488 <a name="Delayed-evaluation"></a>
2489 <table cellpadding="1" cellspacing="1" border="0">
2490 <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>
2491 <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>
2492 <td valign="middle" align="left"> &nbsp; </td>
2493 <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>
2494 <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>
2495 <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>
2496 <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>
2497 <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>
2498 <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>
2499 </tr></table>
2500 <a name="Delayed-evaluation-1"></a>
2501 <h3 class="subsection">4.2.5 Delayed evaluation</h3>
2505 <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>
2509 <p>The <samp>delay</samp> construct is used together with the procedure <code>force</code> to
2510 <a name="index-force"></a>
2511 implement <em>lazy evaluation</em> or <em>call by need</em>.
2512 <a name="index-call-by-need"></a>
2513 <a name="index-lazy-evaluation"></a>
2514 <tt>(delay <span class="roman">&lt;expression&gt;</span>)</tt> returns an object called a
2515 <em>promise</em> which at some point in the future may be asked (by
2516 <a name="index-promise"></a>
2517 the <samp>force</samp> procedure)
2518 to evaluate
2519 <span class="roman">&lt;expression&gt;</span>, and deliver the resulting value.
2520 The effect of <span class="roman">&lt;expression&gt;</span> returning multiple values
2521 is unspecified.
2522 </p>
2523 <p>See the description of <samp>force</samp> (section see section <a href="#Control-features">Control features</a>) for a
2524 more complete description of <samp>delay</samp>.
2525 </p>
2529 <hr size="1">
2530 <a name="Quasiquotation"></a>
2531 <table cellpadding="1" cellspacing="1" border="0">
2532 <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>
2533 <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>
2534 <td valign="middle" align="left"> &nbsp; </td>
2535 <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>
2536 <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>
2537 <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>
2538 <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>
2539 <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>
2540 <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>
2541 </tr></table>
2542 <a name="Quasiquotation-1"></a>
2543 <h3 class="subsection">4.2.6 Quasiquotation</h3>
2548 <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>
2549 <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>
2552 <p>&ldquo;Backquote&rdquo; or &ldquo;quasiquote&rdquo; expressions are useful
2553 <a name="index-backquote"></a>
2554 for constructing a list or vector structure when most but not all of the
2555 desired structure is known in advance. If no
2556 commas appear within the <span class="roman">&lt;qq template&gt;</span>, the result of
2557 <a name="index-comma"></a>
2558 evaluating
2559 <tt>&lsquo;</tt><span class="roman">&lt;qq template&gt;</span> is equivalent to the result of evaluating
2560 <tt>'</tt><span class="roman">&lt;qq template&gt;</span>. If a comma appears within the
2561 <a name="index-_002c"></a>
2562 <span class="roman">&lt;qq template&gt;</span>, however, the expression following the comma is
2563 evaluated (&ldquo;unquoted&rdquo;) and its result is inserted into the structure
2564 instead of the comma and the expression. If a comma appears followed
2565 immediately by an at-sign (@), then the following
2566 <a name="index-_002c_0040"></a>
2567 expression must evaluate to a list; the opening and closing parentheses
2568 of the list are then &ldquo;stripped away&rdquo; and the elements of the list are
2569 inserted in place of the comma at-sign expression sequence. A comma
2570 at-sign should only appear within a list or vector <span class="roman">&lt;qq template&gt;</span>.
2571 </p>
2574 <table><tr><td>&nbsp;</td><td><pre class="format">&lsquo;(list ,(+ 1 2) 4) ==&gt; (list 3 4)
2575 (let ((name 'a)) &lsquo;(list ,name ',name))
2576 ==&gt; (list a (quote a))
2577 &lsquo;(a ,(+ 1 2) ,@(map abs '(4 -5 6)) b)
2578 ==&gt; (a 3 4 5 6 b)
2579 &lsquo;((<samp>foo</samp> ,(- 10 3)) ,@(cdr '(c)) . ,(car '(cons)))
2580 ==&gt; ((foo 7) . cons)
2581 &lsquo;#(10 5 ,(sqrt 4) ,@(map sqrt '(16 9)) 8)
2582 ==&gt; #(10 5 2 4 3 8)
2583 </pre></td></tr></table>
2586 <p>Quasiquote forms may be nested. Substitutions are made only for
2587 unquoted components appearing at the same nesting level
2588 as the outermost backquote. The nesting level increases by one inside
2589 each successive quasiquotation, and decreases by one inside each
2590 unquotation.
2591 </p>
2593 <table><tr><td>&nbsp;</td><td><pre class="format">&lsquo;(a &lsquo;(b ,(+ 1 2) ,(foo ,(+ 1 3) d) e) f)
2594 ==&gt; (a &lsquo;(b ,(+ 1 2) ,(foo 4 d) e) f)
2595 (let ((name1 'x)
2596 (name2 'y))
2597 &lsquo;(a &lsquo;(b ,,name1 ,',name2 d) e))
2598 ==&gt; (a &lsquo;(b ,x ,'y d) e)
2599 </pre></td></tr></table>
2602 <p>The two notations
2603 <tt>&lsquo;</tt><span class="roman">&lt;qq template&gt;</span> and <tt>(quasiquote <span class="roman">&lt;qq template&gt;</span>)</tt>
2604 are identical in all respects.
2605 <samp>,<span class="roman">&lt;expression&gt;</span></samp> is identical to <samp>(unquote <span class="roman">&lt;expression&gt;</span>)</samp>,
2607 <samp>,@<span class="roman">&lt;expression&gt;</span></samp> is identical to <samp>(unquote-splicing <span class="roman">&lt;expression&gt;</span>)</samp>.
2608 The external syntax generated by <code>write</code> for two-element lists whose
2609 <a name="index-write"></a>
2610 car is one of these symbols may vary between implementations.
2611 </p>
2612 <a name="index-_0060-1"></a>
2615 <table><tr><td>&nbsp;</td><td><pre class="format">(quasiquote (list (unquote (+ 1 2)) 4))
2616 ==&gt; (list 3 4)
2617 '(quasiquote (list (unquote (+ 1 2)) 4))
2618 ==&gt; &lsquo;(list ,(+ 1 2) 4)
2619 <em></em>i.e., (quasiquote (list (unquote (+ 1 2)) 4))
2620 </pre></td></tr></table>
2623 <p>Unpredictable behavior can result if any of the symbols
2624 <code>quasiquote</code>, <code>unquote</code>, or <code>unquote-splicing</code> appear in
2625 <a name="index-unquote_002dsplicing"></a>
2626 <a name="index-unquote"></a>
2627 <a name="index-quasiquote-1"></a>
2628 positions within a <span class="roman">&lt;qq template&gt;</span> otherwise than as described above.
2629 </p>
2632 <hr size="1">
2633 <a name="Macros"></a>
2634 <table cellpadding="1" cellspacing="1" border="0">
2635 <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>
2636 <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>
2637 <td valign="middle" align="left"> &nbsp; </td>
2638 <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>
2639 <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>
2640 <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>
2641 <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>
2642 <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>
2643 <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>
2644 </tr></table>
2645 <a name="Macros-1"></a>
2646 <h2 class="section">4.3 Macros</h2>
2648 <table class="menu" border="0" cellspacing="0">
2649 <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">
2650 </td></tr>
2651 <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">
2652 </td></tr>
2653 </table>
2657 <p>Scheme programs can define and use new derived expression types,
2658 called <em>macros</em>.
2659 <a name="index-macro"></a>
2660 Program-defined expression types have the syntax
2661 </p>
2662 <table><tr><td>&nbsp;</td><td><pre class="example">
2663 (<span class="roman">&lt;keyword&gt;</span> <span class="roman">&lt;datum&gt;</span> ...)
2664 </pre></td></tr></table>
2666 <p>where <span class="roman">&lt;keyword&gt;</span> is an identifier that uniquely determines the
2667 expression type. This identifier is called the <em>syntactic
2668 keyword</em>, or simply <em>keyword</em>, of the macro. The
2669 <a name="index-macro-keyword"></a>
2670 <a name="index-keyword"></a>
2671 <a name="index-syntactic-keyword-2"></a>
2672 number of the <span class="roman">&lt;datum&gt;</span>s, and their syntax, depends on the
2673 expression type.
2674 </p>
2675 <p>Each instance of a macro is called a <em>use</em>
2676 <a name="index-macro-use"></a>
2677 of the macro.
2678 The set of rules that specifies
2679 how a use of a macro is transcribed into a more primitive expression
2680 is called the <em>transformer</em>
2681 <a name="index-macro-transformer"></a>
2682 of the macro.
2683 </p>
2684 <p>The macro definition facility consists of two parts:
2685 </p>
2688 <ul>
2689 <li>
2690 A set of expressions used to establish that certain identifiers
2691 are macro keywords, associate them with macro transformers, and control
2692 the scope within which a macro is defined, and
2694 </li><li>
2695 a pattern language for specifying macro transformers.
2697 </li></ul>
2700 <p>The syntactic keyword of a macro may shadow variable bindings, and local
2701 variable bindings may shadow keyword bindings. All macros
2702 <a name="index-keyword-1"></a>
2703 defined using the pattern language are &ldquo;hygienic&rdquo; and &ldquo;referentially
2704 transparent&rdquo; and thus preserve Scheme's lexical scoping [Kohlbecker86], [
2705 hygienic], [Bawden88], [macrosthatwork], [syntacticabstraction]:
2706 </p>
2707 <a name="index-hygienic"></a>
2709 <a name="index-referentially-transparent"></a>
2714 <ul>
2715 <li>
2716 If a macro transformer inserts a binding for an identifier
2717 (variable or keyword), the identifier will in effect be renamed
2718 throughout its scope to avoid conflicts with other identifiers.
2719 Note that a <code>define</code> at top level may or may not introduce a binding;
2720 see section <a href="#Definitions">Definitions</a>.
2722 </li><li>
2723 If a macro transformer inserts a free reference to an
2724 identifier, the reference refers to the binding that was visible
2725 where the transformer was specified, regardless of any local
2726 bindings that may surround the use of the macro.
2729 </li></ul>
2731 <a name="index-define"></a>
2735 <hr size="1">
2736 <a name="Binding-constructs-for-syntactic-keywords"></a>
2737 <table cellpadding="1" cellspacing="1" border="0">
2738 <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>
2739 <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>
2740 <td valign="middle" align="left"> &nbsp; </td>
2741 <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>
2742 <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>
2743 <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>
2744 <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>
2745 <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>
2746 <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>
2747 </tr></table>
2748 <a name="Binding-constructs-for-syntactic-keywords-1"></a>
2749 <h3 class="subsection">4.3.1 Binding constructs for syntactic keywords</h3>
2753 <p><samp>Let-syntax</samp> and <samp>letrec-syntax</samp> are
2754 analogous to <samp>let</samp> and <samp>letrec</samp>, but they bind
2755 syntactic keywords to macro transformers instead of binding variables
2756 to locations that contain values. Syntactic keywords may also be
2757 bound at top level; see section <a href="#Syntax-definitions">Syntax definitions</a>.
2758 </p>
2760 <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>
2762 <p><em>Syntax:</em>
2763 <span class="roman">&lt;Bindings&gt;</span> should have the form
2764 </p>
2765 <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;)
2766 </pre></td></tr></table>
2768 <p>Each <span class="roman">&lt;keyword&gt;</span> is an identifier,
2769 each <span class="roman">&lt;transformer spec&gt;</span> is an instance of <samp>syntax-rules</samp>, and
2770 <span class="roman">&lt;body&gt;</span> should be a sequence of one or more expressions. It is an error
2771 for a <span class="roman">&lt;keyword&gt;</span> to appear more than once in the list of keywords
2772 being bound.
2773 </p>
2774 <p><em>Semantics:</em>
2775 The <span class="roman">&lt;body&gt;</span> is expanded in the syntactic environment
2776 obtained by extending the syntactic environment of the
2777 <samp>let-syntax</samp> expression with macros whose keywords are
2778 the <span class="roman">&lt;keyword&gt;</span>s, bound to the specified transformers.
2779 Each binding of a <span class="roman">&lt;keyword&gt;</span> has <span class="roman">&lt;body&gt;</span> as its region.
2780 </p>
2782 <table><tr><td>&nbsp;</td><td><pre class="format">(let-syntax ((when (syntax-rules ()
2783 ((when test stmt1 stmt2 ...)
2784 (if test
2785 (begin stmt1
2786 stmt2 ...))))))
2787 (let ((if #t))
2788 (when if (set! if 'now))
2789 if)) ==&gt; now
2791 (let ((x 'outer))
2792 (let-syntax ((m (syntax-rules () ((m) x))))
2793 (let ((x 'inner))
2794 (m)))) ==&gt; outer
2795 </pre></td></tr></table>
2801 <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>
2803 <p><em>Syntax:</em>
2804 Same as for <samp>let-syntax</samp>.
2805 </p>
2806 <p><em>Semantics:</em>
2807 The <span class="roman">&lt;body&gt;</span> is expanded in the syntactic environment obtained by
2808 extending the syntactic environment of the <samp>letrec-syntax</samp>
2809 expression with macros whose keywords are the
2810 <span class="roman">&lt;keyword&gt;</span>s, bound to the specified transformers.
2811 Each binding of a <span class="roman">&lt;keyword&gt;</span> has the <span class="roman">&lt;bindings&gt;</span>
2812 as well as the <span class="roman">&lt;body&gt;</span> within its region,
2813 so the transformers can
2814 transcribe expressions into uses of the macros
2815 introduced by the <samp>letrec-syntax</samp> expression.
2816 </p>
2818 <table><tr><td>&nbsp;</td><td><pre class="format">(letrec-syntax
2819 ((my-or (syntax-rules ()
2820 ((my-or) #f)
2821 ((my-or e) e)
2822 ((my-or e1 e2 ...)
2823 (let ((temp e1))
2824 (if temp
2825 temp
2826 (my-or e2 ...)))))))
2827 (let ((x #f)
2828 (y 7)
2829 (temp 8)
2830 (let odd?)
2831 (if even?))
2832 (my-or x
2833 (let temp)
2834 (if y)
2835 y))) ==&gt; 7
2836 </pre></td></tr></table>
2841 <hr size="1">
2842 <a name="Pattern-language"></a>
2843 <table cellpadding="1" cellspacing="1" border="0">
2844 <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>
2845 <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>
2846 <td valign="middle" align="left"> &nbsp; </td>
2847 <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>
2848 <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>
2849 <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>
2850 <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>
2851 <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>
2852 <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>
2853 </tr></table>
2854 <a name="Pattern-language-1"></a>
2855 <h3 class="subsection">4.3.2 Pattern language</h3>
2859 <p>A <span class="roman">&lt;transformer spec&gt;</span> has the following form:
2860 </p>
2862 <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>
2864 <p><em>Syntax:</em>
2865 <span class="roman">&lt;Literals&gt;</span> is a list of identifiers and each <span class="roman">&lt;syntax rule&gt;</span>
2866 should be of the form
2867 </p>
2868 <table><tr><td>&nbsp;</td><td><pre class="format">(<span class="roman">&lt;pattern&gt;</span> <span class="roman">&lt;template&gt;</span>)
2869 </pre></td></tr></table>
2871 <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>
2872 that begins with the keyword for the macro.
2873 </p>
2874 <p>A <span class="roman">&lt;pattern&gt;</span> is either an identifier, a constant, or one of the
2875 following
2876 </p>
2877 <table><tr><td>&nbsp;</td><td><pre class="format">(<span class="roman">&lt;pattern&gt;</span> &hellip;)
2878 (<span class="roman">&lt;pattern&gt;</span> <span class="roman">&lt;pattern&gt;</span> &hellip; . <span class="roman">&lt;pattern&gt;</span>)
2879 (<span class="roman">&lt;pattern&gt;</span> &hellip; <span class="roman">&lt;pattern&gt;</span> <span class="roman">&lt;ellipsis&gt;</span>)
2880 #(<span class="roman">&lt;pattern&gt;</span> &hellip;)
2881 #(<span class="roman">&lt;pattern&gt;</span> &hellip; <span class="roman">&lt;pattern&gt;</span> <span class="roman">&lt;ellipsis&gt;</span>)
2882 </pre></td></tr></table>
2884 <p>and a template is either an identifier, a constant, or one of the following
2885 </p>
2886 <table><tr><td>&nbsp;</td><td><pre class="format">(<span class="roman">&lt;element&gt;</span> &hellip;)
2887 (<span class="roman">&lt;element&gt;</span> <span class="roman">&lt;element&gt;</span> &hellip; . <span class="roman">&lt;template&gt;</span>)
2888 #(<span class="roman">&lt;element&gt;</span> &hellip;)
2889 </pre></td></tr></table>
2891 <p>where an <span class="roman">&lt;element&gt;</span> is a <span class="roman">&lt;template&gt;</span> optionally
2892 followed by an <span class="roman">&lt;ellipsis&gt;</span> and
2893 an <span class="roman">&lt;ellipsis&gt;</span> is the identifier &ldquo;<samp>...</samp>&rdquo; (which cannot be used as
2894 an identifier in either a template or a pattern).
2895 <a name="index-_002e_002e_002e-1"></a>
2896 </p>
2897 <p><em>Semantics:</em> An instance of <samp>syntax-rules</samp> produces a new macro
2898 transformer by specifying a sequence of hygienic rewrite rules. A use
2899 of a macro whose keyword is associated with a transformer specified by
2900 <samp>syntax-rules</samp> is matched against the patterns contained in the
2901 <span class="roman">&lt;syntax rule&gt;</span>s, beginning with the leftmost <span class="roman">&lt;syntax rule&gt;</span>.
2902 When a match is found, the macro use is transcribed hygienically
2903 according to the template.
2904 </p>
2905 <p>An identifier that appears in the pattern of a <span class="roman">&lt;syntax rule&gt;</span> is
2906 a <em>pattern variable</em>, unless it is the keyword that begins the pattern,
2907 is listed in <span class="roman">&lt;literals&gt;</span>, or is the identifier &ldquo;<samp>...</samp>&rdquo;.
2908 Pattern variables match arbitrary input elements and
2909 are used to refer to elements of the input in the template. It is an
2910 error for the same pattern variable to appear more than once in a
2911 <span class="roman">&lt;pattern&gt;</span>.
2912 </p>
2913 <p>The keyword at the beginning of the pattern in a
2914 <span class="roman">&lt;syntax rule&gt;</span> is not involved in the matching and
2915 is not considered a pattern variable or literal identifier.
2916 </p>
2918 <blockquote><p><em>Rationale:</em>
2919 The scope of the keyword is determined by the expression or syntax
2920 definition that binds it to the associated macro transformer.
2921 If the keyword were a pattern variable or literal
2922 identifier, then
2923 the template that follows the pattern would be within its scope
2924 regardless of whether the keyword were bound by <samp>let-syntax</samp>
2925 or by <samp>letrec-syntax</samp>.
2926 </p></blockquote>
2929 <p>Identifiers that appear in <span class="roman">&lt;literals&gt;</span> are interpreted as literal
2930 identifiers to be matched against corresponding subforms of the input.
2931 A subform
2932 in the input matches a literal identifier if and only if it is an
2933 identifier
2934 and either both its occurrence in the macro expression and its
2935 occurrence in the macro definition have the same lexical binding, or
2936 the two identifiers are equal and both have no lexical binding.
2937 </p>
2939 <p>A subpattern followed by <samp>...</samp> can match zero or more elements of the
2940 input. It is an error for <samp>...</samp> to appear in <span class="roman">&lt;literals&gt;</span>.
2941 Within a pattern the identifier <samp>...</samp> must follow the last element of
2942 a nonempty sequence of subpatterns.
2943 </p>
2944 <p>More formally, an input form F matches a pattern P if and only if:
2945 </p>
2948 <ul>
2949 <li>
2950 P is a non-literal identifier; or
2952 </li><li>
2953 P is a literal identifier and F is an identifier with the same
2954 binding; or
2956 </li><li>
2957 P is a list <samp>(P_1 &hellip; P_n)</samp> and F is a
2958 list of n
2959 forms that match P_1 through P_n, respectively; or
2961 </li><li>
2962 P is an improper list
2963 <samp>(P_1 P_2 &hellip; P_n . P_n+1)</samp>
2964 and F is a list or
2965 improper list of n or more forms that match P_1 through P_n,
2966 respectively, and whose nth &ldquo;cdr&rdquo; matches P_n+1; or
2968 </li><li>
2969 P is of the form
2970 <samp>(P_1 &hellip; P_n P_n+1 &lt;ellipsis&gt;)</samp>
2971 where &lt;ellipsis&gt; is the identifier <samp>...</samp>
2972 and F is
2973 a proper list of at least n forms, the first n of which match
2974 P_1 through P_n, respectively, and each remaining element of F
2975 matches P_n+1; or
2977 </li><li>
2978 P is a vector of the form <samp>#(P_1 &hellip; P_n)</samp>
2979 and F is a vector
2980 of n forms that match P_1 through P_n; or
2982 </li><li>
2983 P is of the form
2984 <samp>#(P_1 &hellip; P_n P_n+1 &lt;ellipsis&gt;)</samp>
2985 where &lt;ellipsis&gt; is the identifier <samp>...</samp>
2986 and F is a vector of n
2987 or more forms the first n of which match
2988 P_1 through P_n, respectively, and each remaining element of F
2989 matches P_n+1; or
2991 </li><li>
2992 P is a datum and F is equal to P in the sense of
2993 the <samp>equal?</samp> procedure.
2995 </li></ul>
2998 <p>It is an error to use a macro keyword, within the scope of its
2999 binding, in an expression that does not match any of the patterns.
3000 </p>
3001 <p>When a macro use is transcribed according to the template of the
3002 matching <span class="roman">&lt;syntax rule&gt;</span>, pattern variables that occur in the
3003 template are replaced by the subforms they match in the input.
3004 Pattern variables that occur in subpatterns followed by one or more
3005 instances of the identifier
3006 <samp>...</samp> are allowed only in subtemplates that are
3007 followed by as many instances of <samp>...</samp>.
3008 They are replaced in the
3009 output by all of the subforms they match in the input, distributed as
3010 indicated. It is an error if the output cannot be built up as
3011 specified.
3012 </p>
3014 <p>Identifiers that appear in the template but are not pattern variables
3015 or the identifier
3016 <samp>...</samp> are inserted into the output as literal identifiers. If a
3017 literal identifier is inserted as a free identifier then it refers to the
3018 binding of that identifier within whose scope the instance of
3019 <samp>syntax-rules</samp> appears.
3020 If a literal identifier is inserted as a bound identifier then it is
3021 in effect renamed to prevent inadvertent captures of free identifiers.
3022 </p>
3023 <p>As an example, if <code>let</code> and <code>cond</code> are defined as in
3024 <a name="index-cond-1"></a>
3025 <a name="index-let-3"></a>
3026 section <a href="#Derived-expression-type">Derived expression types</a> then they are hygienic (as required) and
3027 the following is not an error.
3028 </p>
3030 <table><tr><td>&nbsp;</td><td><pre class="format">(let ((=&gt; #f))
3031 (cond (#t =&gt; 'ok))) ==&gt; ok
3032 </pre></td></tr></table>
3035 <p>The macro transformer for <samp>cond</samp> recognizes <samp>=&gt;</samp>
3036 as a local variable, and hence an expression, and not as the
3037 top-level identifier <samp>=&gt;</samp>, which the macro transformer treats
3038 as a syntactic keyword. Thus the example expands into
3039 </p>
3041 <table><tr><td>&nbsp;</td><td><pre class="format">(let ((=&gt; #f))
3042 (if #t (begin =&gt; 'ok)))
3043 </pre></td></tr></table>
3046 <p>instead of
3047 </p>
3049 <table><tr><td>&nbsp;</td><td><pre class="format">(let ((=&gt; #f))
3050 (let ((temp #t))
3051 (if temp ('ok temp))))
3052 </pre></td></tr></table>
3055 <p>which would result in an invalid procedure call.
3056 </p>
3062 <hr size="1">
3063 <a name="Program-structure"></a>
3064 <table cellpadding="1" cellspacing="1" border="0">
3065 <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>
3066 <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>
3067 <td valign="middle" align="left"> &nbsp; </td>
3068 <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>
3069 <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>
3070 <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>
3071 <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>
3072 <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>
3073 <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>
3074 </tr></table>
3075 <a name="Program-structure-1"></a>
3076 <h1 class="chapter">5. Program structure</h1>
3078 <table class="menu" border="0" cellspacing="0">
3079 <tr><td align="left" valign="top"><a href="#Programs">5.1 Programs</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
3080 </td></tr>
3081 <tr><td align="left" valign="top"><a href="#Definitions">5.2 Definitions</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
3082 </td></tr>
3083 <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">
3084 </td></tr>
3085 </table>
3089 <hr size="1">
3090 <a name="Programs"></a>
3091 <table cellpadding="1" cellspacing="1" border="0">
3092 <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>
3093 <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>
3094 <td valign="middle" align="left"> &nbsp; </td>
3095 <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>
3096 <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>
3097 <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>
3098 <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>
3099 <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>
3100 <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>
3101 </tr></table>
3102 <a name="Programs-1"></a>
3103 <h2 class="section">5.1 Programs</h2>
3106 <p>A Scheme program consists of a sequence of expressions, definitions,
3107 and syntax definitions.
3108 Expressions are described in chapter <a href="#Expressions">Expressions</a>;
3109 definitions and syntax definitions are the subject of the rest of the
3110 present chapter.
3111 </p>
3112 <p>Programs are typically stored in files or entered interactively to a
3113 running Scheme system, although other paradigms are possible;
3114 questions of user interface lie outside the scope of this report.
3115 (Indeed, Scheme would still be useful as a notation for expressing
3116 computational methods even in the absence of a mechanical
3117 implementation.)
3118 </p>
3119 <p>Definitions and syntax definitions occurring at the top level of a program
3120 can be interpreted
3121 declaratively.
3122 They cause bindings to be created in the top level
3123 environment or modify the value of existing top-level bindings.
3124 Expressions occurring at the top level of a program are
3125 interpreted imperatively; they are executed in order when the program is
3126 invoked or loaded, and typically perform some kind of initialization.
3127 </p>
3128 <p>At the top level of a program <tt>(begin <span class="roman">&lt;form1&gt;</span> &hellip;)</tt> is
3129 equivalent to the sequence of expressions, definitions, and syntax definitions
3130 that form the body of the <code>begin</code>.
3131 <a name="index-begin-1"></a>
3132 </p>
3135 <hr size="1">
3136 <a name="Definitions"></a>
3137 <table cellpadding="1" cellspacing="1" border="0">
3138 <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>
3139 <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>
3140 <td valign="middle" align="left"> &nbsp; </td>
3141 <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>
3142 <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>
3143 <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>
3144 <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>
3145 <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>
3146 <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>
3147 </tr></table>
3148 <a name="Definitions-1"></a>
3149 <h2 class="section">5.2 Definitions</h2>
3151 <table class="menu" border="0" cellspacing="0">
3152 <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">
3153 </td></tr>
3154 <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">
3155 </td></tr>
3156 </table>
3160 <p>Definitions are valid in some, but not all, contexts where expressions
3161 are allowed. They are valid only at the top level of a <span class="roman">&lt;program&gt;</span>
3162 and at the beginning of a <span class="roman">&lt;body&gt;</span>.
3163 </p>
3164 <a name="index-definition"></a>
3166 <p>A definition should have one of the following forms:
3167 <a name="index-define-1"></a>
3168 </p>
3171 <ul>
3172 <li> <tt>(define <span class="roman">&lt;variable&gt;</span> <span class="roman">&lt;expression&gt;</span>)</tt>
3174 </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>
3176 <p><span class="roman">&lt;Formals&gt;</span> should be either a
3177 sequence of zero or more variables, or a sequence of one or more
3178 variables followed by a space-delimited period and another variable (as
3179 in a lambda expression). This form is equivalent to
3180 </p>
3181 <table><tr><td>&nbsp;</td><td><pre class="example">
3182 (define <span class="roman">&lt;variable&gt;</span>
3183 (lambda (<span class="roman">&lt;formals&gt;</span>) <span class="roman">&lt;body&gt;</span>))<span class="roman">.</span>
3184 </pre></td></tr></table>
3187 </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>
3189 <p><span class="roman">&lt;Formal&gt;</span> should be a single
3190 variable. This form is equivalent to
3191 </p>
3192 <table><tr><td>&nbsp;</td><td><pre class="example">
3193 (define <span class="roman">&lt;variable&gt;</span>
3194 (lambda <span class="roman">&lt;formal&gt;</span> <span class="roman">&lt;body&gt;</span>))<span class="roman">.</span>
3195 </pre></td></tr></table>
3199 </li></ul>
3202 <hr size="1">
3203 <a name="Top-level-definitions"></a>
3204 <table cellpadding="1" cellspacing="1" border="0">
3205 <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>
3206 <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>
3207 <td valign="middle" align="left"> &nbsp; </td>
3208 <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>
3209 <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>
3210 <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>
3211 <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>
3212 <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>
3213 <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>
3214 </tr></table>
3215 <a name="Top-level-definitions-1"></a>
3216 <h3 class="subsection">5.2.1 Top level definitions</h3>
3219 <p>At the top level of a program, a definition
3220 </p>
3221 <table><tr><td>&nbsp;</td><td><pre class="example">
3222 (define <span class="roman">&lt;variable&gt;</span> <span class="roman">&lt;expression&gt;</span>)
3223 </pre></td></tr></table>
3225 <p>has essentially the same effect as the assignment expression
3226 </p>
3227 <table><tr><td>&nbsp;</td><td><pre class="example">
3228 (set! <span class="roman">&lt;variable&gt;</span> <span class="roman">&lt;expression&gt;</span>)
3229 </pre></td></tr></table>
3231 <p>if <span class="roman">&lt;variable&gt;</span> is bound. If <span class="roman">&lt;variable&gt;</span> is not bound,
3232 however, then the definition will bind <span class="roman">&lt;variable&gt;</span> to a new
3233 location before performing the assignment, whereas it would be an error
3234 to perform a <samp>set!</samp> on an unbound variable.
3235 <a name="index-unbound-2"></a>
3236 </p>
3238 <table><tr><td>&nbsp;</td><td><pre class="example">
3239 (define add3
3240 (lambda (x) (+ x 3)))
3241 (add3 3) ==&gt; 6
3242 (define first car)
3243 (first '(1 2)) ==&gt; 1
3244 </pre></td></tr></table>
3247 <p>Some implementations of Scheme use an initial environment in
3248 which all possible variables are bound to locations, most of
3249 which contain undefined values. Top level definitions in
3250 such an implementation are truly equivalent to assignments.
3251 </p>
3255 <hr size="1">
3256 <a name="Internal-definitions"></a>
3257 <table cellpadding="1" cellspacing="1" border="0">
3258 <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>
3259 <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>
3260 <td valign="middle" align="left"> &nbsp; </td>
3261 <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>
3262 <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>
3263 <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>
3264 <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>
3265 <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>
3266 <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>
3267 </tr></table>
3268 <a name="Internal-definitions-1"></a>
3269 <h3 class="subsection">5.2.2 Internal definitions</h3>
3273 <p>Definitions may occur at the
3274 beginning of a <span class="roman">&lt;body&gt;</span> (that is, the body of a <code>lambda</code>,
3275 <a name="index-lambda-1"></a>
3276 <code>let</code>, <code>let*</code>, <code>letrec</code>, <code>let-syntax</code>, or <code>letrec-syntax</code>
3277 <a name="index-letrec_002dsyntax-1"></a>
3278 <a name="index-let_002dsyntax-1"></a>
3279 <a name="index-letrec-1"></a>
3280 <a name="index-let_002a-1"></a>
3281 <a name="index-let-4"></a>
3282 expression or that of a definition of an appropriate form).
3283 Such definitions are known as <em>internal definitions</em> as opposed to the top level definitions described above.
3284 <a name="index-internal-definition"></a>
3285 The variable defined by an internal definition is local to the
3286 <span class="roman">&lt;body&gt;</span>. That is, <span class="roman">&lt;variable&gt;</span> is bound rather than assigned,
3287 and the region of the binding is the entire <span class="roman">&lt;body&gt;</span>. For example,
3288 </p>
3290 <table><tr><td>&nbsp;</td><td><pre class="example">
3291 (let ((x 5))
3292 (define foo (lambda (y) (bar x y)))
3293 (define bar (lambda (a b) (+ (* a b) a)))
3294 (foo (+ x 3))) ==&gt; 45
3295 </pre></td></tr></table>
3298 <p>A <span class="roman">&lt;body&gt;</span> containing internal definitions can always be converted
3299 into a completely equivalent <samp>letrec</samp> expression. For example, the
3300 <samp>let</samp> expression in the above example is equivalent to
3301 </p>
3303 <table><tr><td>&nbsp;</td><td><pre class="example">
3304 (let ((x 5))
3305 (letrec ((foo (lambda (y) (bar x y)))
3306 (bar (lambda (a b) (+ (* a b) a))))
3307 (foo (+ x 3))))
3308 </pre></td></tr></table>
3311 <p>Just as for the equivalent <samp>letrec</samp> expression, it must be
3312 possible to evaluate each <span class="roman">&lt;expression&gt;</span> of every internal
3313 definition in a <span class="roman">&lt;body&gt;</span> without assigning or referring to
3314 the value of any <span class="roman">&lt;variable&gt;</span> being defined.
3315 </p>
3316 <p>Wherever an internal definition may occur
3317 <tt>(begin <span class="roman">&lt;definition1&gt;</span> &hellip;)</tt>
3318 is equivalent to the sequence of definitions
3319 that form the body of the <code>begin</code>.
3320 <a name="index-begin-2"></a>
3321 </p>
3322 <hr size="1">
3323 <a name="Syntax-definitions"></a>
3324 <table cellpadding="1" cellspacing="1" border="0">
3325 <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>
3326 <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>
3327 <td valign="middle" align="left"> &nbsp; </td>
3328 <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>
3329 <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>
3330 <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>
3331 <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>
3332 <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>
3333 <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>
3334 </tr></table>
3335 <a name="Syntax-definitions-1"></a>
3336 <h2 class="section">5.3 Syntax definitions</h2>
3339 <p>Syntax definitions are valid only at the top level of a <span class="roman">&lt;program&gt;</span>.
3340 </p>
3341 <a name="index-syntax-definition"></a>
3342 <p>They have the following form:
3343 <a name="index-define_002dsyntax"></a>
3344 </p>
3345 <p><tt>(define-syntax <span class="roman">&lt;keyword&gt;</span> <span class="roman">&lt;transformer spec&gt;</span>)</tt>
3346 </p>
3347 <p><span class="roman">&lt;Keyword&gt;</span> is an identifier, and
3348 the <span class="roman">&lt;transformer spec&gt;</span> should be an instance of <code>syntax-rules</code>.
3349 <a name="index-syntax_002drules-1"></a>
3350 The top-level syntactic environment is extended by binding the
3351 <span class="roman">&lt;keyword&gt;</span> to the specified transformer.
3352 </p>
3353 <p>There is no <samp>define-syntax</samp> analogue of internal definitions.
3354 </p>
3358 <p>Although macros may expand into definitions and syntax definitions in
3359 any context that permits them, it is an error for a definition or syntax
3360 definition to shadow a syntactic keyword whose meaning is needed to
3361 determine whether some form in the group of forms that contains the
3362 shadowing definition is in fact a definition, or, for internal definitions,
3363 is needed to determine the boundary between the group and the expressions
3364 that follow the group. For example, the following are errors:
3365 </p>
3367 <table><tr><td>&nbsp;</td><td><pre class="example">
3368 (define define 3)
3370 (begin (define begin list))
3372 (let-syntax
3373 ((foo (syntax-rules ()
3374 ((foo (proc args ...) body ...)
3375 (define proc
3376 (lambda (args ...)
3377 body ...))))))
3378 (let ((x 3))
3379 (foo (plus x y) (+ x y))
3380 (define foo x)
3381 (plus foo x)))
3382 </pre></td></tr></table>
3389 <hr size="1">
3390 <a name="Standard-procedures"></a>
3391 <table cellpadding="1" cellspacing="1" border="0">
3392 <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>
3393 <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>
3394 <td valign="middle" align="left"> &nbsp; </td>
3395 <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>
3396 <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>
3397 <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>
3398 <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>
3399 <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>
3400 <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>
3401 </tr></table>
3402 <a name="Standard-procedures-1"></a>
3403 <h1 class="chapter">6. Standard procedures</h1>
3405 <table class="menu" border="0" cellspacing="0">
3406 <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">
3407 </td></tr>
3408 <tr><td align="left" valign="top"><a href="#Numbers">6.2 Numbers</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
3409 </td></tr>
3410 <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">
3411 </td></tr>
3412 <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">
3413 </td></tr>
3414 <tr><td align="left" valign="top"><a href="#Eval">6.5 Eval</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
3415 </td></tr>
3416 <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">
3417 </td></tr>
3418 </table>
3424 <a name="index-initial-environment"></a>
3426 <a name="index-top-level-environment-1"></a>
3428 <a name="index-library-procedure"></a>
3430 <p>This chapter describes Scheme's built-in procedures. The initial (or
3431 &ldquo;top level&rdquo;) Scheme environment starts out with a number of variables
3432 bound to locations containing useful values, most of which are primitive
3433 procedures that manipulate data. For example, the variable <samp>abs</samp> is
3434 bound to (a location initially containing) a procedure of one argument
3435 that computes the absolute value of a number, and the variable <samp>+</samp>
3436 is bound to a procedure that computes sums. Built-in procedures that
3437 can easily be written in terms of other built-in procedures are identified as
3438 &ldquo;library procedures&rdquo;.
3439 </p>
3440 <p>A program may use a top-level definition to bind any variable. It may
3441 subsequently alter any such binding by an assignment (see see section <a href="#Assignments">Assignments</a>).
3442 These operations do not modify the behavior of Scheme's built-in
3443 procedures. Altering any top-level binding that has not been introduced by a
3444 definition has an unspecified effect on the behavior of the built-in procedures.
3445 </p>
3446 <hr size="1">
3447 <a name="Equivalence-predicates"></a>
3448 <table cellpadding="1" cellspacing="1" border="0">
3449 <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>
3450 <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>
3451 <td valign="middle" align="left"> &nbsp; </td>
3452 <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>
3453 <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>
3454 <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>
3455 <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>
3456 <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>
3457 <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>
3458 </tr></table>
3459 <a name="Equivalence-predicates-1"></a>
3460 <h2 class="section">6.1 Equivalence predicates</h2>
3464 <p>A <em>predicate</em> is a procedure that always returns a boolean
3465 <a name="index-predicate"></a>
3466 value (<tt>#t</tt> or <tt>#f</tt>). An <em>equivalence predicate</em> is
3467 <a name="index-equivalence-predicate"></a>
3468 the computational analogue of a mathematical equivalence relation (it is
3469 symmetric, reflexive, and transitive). Of the equivalence predicates
3470 described in this section, <samp>eq?</samp> is the finest or most
3471 discriminating, and <samp>equal?</samp> is the coarsest. <samp>Eqv?</samp> is
3472 slightly less discriminating than <samp>eq?</samp>.
3473 </p>
3477 <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>
3479 <p>The <samp>eqv?</samp> procedure defines a useful equivalence relation on objects.
3480 Briefly, it returns <tt>#t</tt> if <var>obj1</var> and <var>obj2</var> should
3481 normally be regarded as the same object. This relation is left slightly
3482 open to interpretation, but the following partial specification of
3483 <samp>eqv?</samp> holds for all implementations of Scheme.
3484 </p>
3485 <p>The <samp>eqv?</samp> procedure returns <tt>#t</tt> if:
3486 </p>
3489 <ul>
3490 <li>
3491 <var>obj1</var> and <var>obj2</var> are both <tt>#t</tt> or both <tt>#f</tt>.
3493 </li><li>
3494 <var>obj1</var> and <var>obj2</var> are both symbols and
3497 <table><tr><td>&nbsp;</td><td><pre class="format">(string=? (symbol-&gt;string obj1)
3498 (symbol-&gt;string obj2))
3499 ==&gt; #t
3500 </pre></td></tr></table>
3504 <blockquote><p><em>Note:</em>
3505 This assumes that neither <var>obj1</var> nor <var>obj2</var> is an &ldquo;uninterned
3506 symbol&rdquo; as alluded to in section <a href="#Symbols">Symbols</a>. This report does
3507 not presume to specify the behavior of <samp>eqv?</samp> on implementation-dependent
3508 extensions.
3509 </p></blockquote>
3512 </li><li>
3513 <var>obj1</var> and <var>obj2</var> are both numbers, are numerically
3514 equal (see <samp>=</samp>, section see section <a href="#Numbers">Numbers</a>), and are either both
3515 exact or both inexact.
3517 </li><li>
3518 <var>obj1</var> and <var>obj2</var> are both characters and are the same
3519 character according to the <samp>char=?</samp> procedure
3520 (section see section <a href="#Characters">Characters</a>).
3522 </li><li>
3523 both <var>obj1</var> and <var>obj2</var> are the empty list.
3525 </li><li>
3526 <var>obj1</var> and <var>obj2</var> are pairs, vectors, or strings that denote the
3527 same locations in the store (section see section <a href="#Storage-model">Storage model</a>).
3529 </li><li>
3530 <var>obj1</var> and <var>obj2</var> are procedures whose location tags are
3531 equal (section see section <a href="#Procedures">Procedures</a>).
3533 </li></ul>
3535 <a name="index-inexact"></a>
3536 <a name="index-exact"></a>
3538 <p>The <samp>eqv?</samp> procedure returns <tt>#f</tt> if:
3539 </p>
3542 <ul>
3543 <li>
3544 <var>obj1</var> and <var>obj2</var> are of different types
3545 (section see section <a href="#Disjointness-of-types">Disjointness of types</a>).
3547 </li><li>
3548 one of <var>obj1</var> and <var>obj2</var> is <tt>#t</tt> but the other is
3549 <tt>#f</tt>.
3551 </li><li>
3552 <var>obj1</var> and <var>obj2</var> are symbols but
3555 <table><tr><td>&nbsp;</td><td><pre class="format">(string=? (symbol-&gt;string <var>obj1</var>)
3556 (symbol-&gt;string <var>obj2</var>))
3557 ==&gt; #f
3558 </pre></td></tr></table>
3561 </li><li>
3562 one of <var>obj1</var> and <var>obj2</var> is an exact number but the other
3563 is an inexact number.
3565 </li><li>
3566 <var>obj1</var> and <var>obj2</var> are numbers for which the <samp>=</samp>
3567 procedure returns <tt>#f</tt>.
3569 </li><li>
3570 <var>obj1</var> and <var>obj2</var> are characters for which the <samp>char=?</samp>
3571 procedure returns <tt>#f</tt>.
3573 </li><li>
3574 one of <var>obj1</var> and <var>obj2</var> is the empty list but the other
3575 is not.
3577 </li><li>
3578 <var>obj1</var> and <var>obj2</var> are pairs, vectors, or strings that denote
3579 distinct locations.
3581 </li><li>
3582 <var>obj1</var> and <var>obj2</var> are procedures that would behave differently
3583 (return different value(s) or have different side effects) for some arguments.
3586 </li></ul>
3590 <table><tr><td>&nbsp;</td><td><pre class="format">(eqv? 'a 'a) ==&gt; #t
3591 (eqv? 'a 'b) ==&gt; #f
3592 (eqv? 2 2) ==&gt; #t
3593 (eqv? '() '()) ==&gt; #t
3594 (eqv? 100000000 100000000) ==&gt; #t
3595 (eqv? (cons 1 2) (cons 1 2)) ==&gt; #f
3596 (eqv? (lambda () 1)
3597 (lambda () 2)) ==&gt; #f
3598 (eqv? #f 'nil) ==&gt; #f
3599 (let ((p (lambda (x) x)))
3600 (eqv? p p)) ==&gt; #t
3601 </pre></td></tr></table>
3604 <p>The following examples illustrate cases in which the above rules do
3605 not fully specify the behavior of <samp>eqv?</samp>. All that can be said
3606 about such cases is that the value returned by <samp>eqv?</samp> must be a
3607 boolean.
3608 </p>
3610 <table><tr><td>&nbsp;</td><td><pre class="format">(eqv? &quot;&quot; &quot;&quot;) ==&gt; <em>unspecified</em>
3611 (eqv? '#() '#()) ==&gt; <em>unspecified</em>
3612 (eqv? (lambda (x) x)
3613 (lambda (x) x)) ==&gt; <em>unspecified</em>
3614 (eqv? (lambda (x) x)
3615 (lambda (y) y)) ==&gt; <em>unspecified</em>
3616 </pre></td></tr></table>
3619 <p>The next set of examples shows the use of <samp>eqv?</samp> with procedures
3620 that have local state. <samp>Gen-counter</samp> must return a distinct
3621 procedure every time, since each procedure has its own internal counter.
3622 <samp>Gen-loser</samp>, however, returns equivalent procedures each time, since
3623 the local state does not affect the value or side effects of the
3624 procedures.
3625 </p>
3627 <table><tr><td>&nbsp;</td><td><pre class="format">(define gen-counter
3628 (lambda ()
3629 (let ((n 0))
3630 (lambda () (set! n (+ n 1)) n))))
3631 (let ((g (gen-counter)))
3632 (eqv? g g)) ==&gt; #t
3633 (eqv? (gen-counter) (gen-counter))
3634 ==&gt; #f
3635 (define gen-loser
3636 (lambda ()
3637 (let ((n 0))
3638 (lambda () (set! n (+ n 1)) 27))))
3639 (let ((g (gen-loser)))
3640 (eqv? g g)) ==&gt; #t
3641 (eqv? (gen-loser) (gen-loser))
3642 ==&gt; <em>unspecified</em>
3644 (letrec ((f (lambda () (if (eqv? f g) 'both 'f)))
3645 (g (lambda () (if (eqv? f g) 'both 'g))))
3646 (eqv? f g))
3647 ==&gt; <em>unspecified</em>
3649 (letrec ((f (lambda () (if (eqv? f g) 'f 'both)))
3650 (g (lambda () (if (eqv? f g) 'g 'both))))
3651 (eqv? f g))
3652 ==&gt; #f
3653 </pre></td></tr></table>
3658 <p>Since it is an error to modify constant objects (those returned by
3659 literal expressions), implementations are permitted, though not
3660 required, to share structure between constants where appropriate. Thus
3661 the value of <samp>eqv?</samp> on constants is sometimes
3662 implementation-dependent.
3663 </p>
3665 <table><tr><td>&nbsp;</td><td><pre class="format">(eqv? '(a) '(a)) ==&gt; <em>unspecified</em>
3666 (eqv? &quot;a&quot; &quot;a&quot;) ==&gt; <em>unspecified</em>
3667 (eqv? '(b) (cdr '(a b))) ==&gt; <em>unspecified</em>
3668 (let ((x '(a)))
3669 (eqv? x x)) ==&gt; #t
3670 </pre></td></tr></table>
3674 <blockquote><p><em>Rationale:</em>
3675 The above definition of <samp>eqv?</samp> allows implementations latitude in
3676 their treatment of procedures and literals: implementations are free
3677 either to detect or to fail to detect that two procedures or two literals
3678 are equivalent to each other, and can decide whether or not to
3679 merge representations of equivalent objects by using the same pointer or
3680 bit pattern to represent both.
3681 </p></blockquote>
3688 <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>
3690 <p><samp>Eq?</samp> is similar to <samp>eqv?</samp> except that in some cases it is
3691 capable of discerning distinctions finer than those detectable by
3692 <samp>eqv?</samp>.
3693 </p>
3694 <p><samp>Eq?</samp> and <samp>eqv?</samp> are guaranteed to have the same
3695 behavior on symbols, booleans, the empty list, pairs, procedures,
3696 and non-empty
3697 strings and vectors. <samp>Eq?</samp>'s behavior on numbers and characters is
3698 implementation-dependent, but it will always return either true or
3699 false, and will return true only when <samp>eqv?</samp> would also return
3700 true. <samp>Eq?</samp> may also behave differently from <samp>eqv?</samp> on empty
3701 vectors and empty strings.
3702 </p>
3704 <table><tr><td>&nbsp;</td><td><pre class="format">(eq? 'a 'a) ==&gt; #t
3705 (eq? '(a) '(a)) ==&gt; <em>unspecified</em>
3706 (eq? (list 'a) (list 'a)) ==&gt; #f
3707 (eq? &quot;a&quot; &quot;a&quot;) ==&gt; <em>unspecified</em>
3708 (eq? &quot;&quot; &quot;&quot;) ==&gt; <em>unspecified</em>
3709 (eq? '() '()) ==&gt; #t
3710 (eq? 2 2) ==&gt; <em>unspecified</em>
3711 (eq? #\A #\A) ==&gt; <em>unspecified</em>
3712 (eq? car car) ==&gt; #t
3713 (let ((n (+ 2 3)))
3714 (eq? n n)) ==&gt; <em>unspecified</em>
3715 (let ((x '(a)))
3716 (eq? x x)) ==&gt; #t
3717 (let ((x '#()))
3718 (eq? x x)) ==&gt; #t
3719 (let ((p (lambda (x) x)))
3720 (eq? p p)) ==&gt; #t
3721 </pre></td></tr></table>
3727 <blockquote><p><em>Rationale:</em> It will usually be possible to implement <samp>eq?</samp> much
3728 more efficiently than <samp>eqv?</samp>, for example, as a simple pointer
3729 comparison instead of as some more complicated operation. One reason is
3730 that it may not be possible to compute <samp>eqv?</samp> of two numbers in
3731 constant time, whereas <samp>eq?</samp> implemented as pointer comparison will
3732 always finish in constant time. <samp>Eq?</samp> may be used like <samp>eqv?</samp>
3733 in applications using procedures to implement objects with state since
3734 it obeys the same constraints as <samp>eqv?</samp>.
3735 </p></blockquote>
3742 <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>
3744 <p><samp>Equal?</samp> recursively compares the contents of pairs, vectors, and
3745 strings, applying <samp>eqv?</samp> on other objects such as numbers and symbols.
3746 A rule of thumb is that objects are generally <samp>equal?</samp> if they print
3747 the same. <samp>Equal?</samp> may fail to terminate if its arguments are
3748 circular data structures.
3749 </p>
3751 <table><tr><td>&nbsp;</td><td><pre class="format">(equal? 'a 'a) ==&gt; #t
3752 (equal? '(a) '(a)) ==&gt; #t
3753 (equal? '(a (b) c)
3754 '(a (b) c)) ==&gt; #t
3755 (equal? &quot;abc&quot; &quot;abc&quot;) ==&gt; #t
3756 (equal? 2 2) ==&gt; #t
3757 (equal? (make-vector 5 'a)
3758 (make-vector 5 'a)) ==&gt; #t
3759 (equal? (lambda (x) x)
3760 (lambda (y) y)) ==&gt; <em>unspecified</em>
3761 </pre></td></tr></table>
3767 <hr size="1">
3768 <a name="Numbers"></a>
3769 <table cellpadding="1" cellspacing="1" border="0">
3770 <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>
3771 <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>
3772 <td valign="middle" align="left"> &nbsp; </td>
3773 <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>
3774 <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>
3775 <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>
3776 <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>
3777 <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>
3778 <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>
3779 </tr></table>
3780 <a name="Numbers-1"></a>
3781 <h2 class="section">6.2 Numbers</h2>
3783 <table class="menu" border="0" cellspacing="0">
3784 <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">
3785 </td></tr>
3786 <tr><td align="left" valign="top"><a href="#Exactness">6.2.2 Exactness</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
3787 </td></tr>
3788 <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">
3789 </td></tr>
3790 <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">
3791 </td></tr>
3792 <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">
3793 </td></tr>
3794 <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">
3795 </td></tr>
3796 </table>
3800 <a name="index-number"></a>
3804 <p>Numerical computation has traditionally been neglected by the Lisp
3805 community. Until Common Lisp there was no carefully thought out
3806 strategy for organizing numerical computation, and with the exception of
3807 the MacLisp system [Pitman83] little effort was made to
3808 execute numerical code efficiently. This report recognizes the excellent work
3809 of the Common Lisp committee and accepts many of their recommendations.
3810 In some ways this report simplifies and generalizes their proposals in a manner
3811 consistent with the purposes of Scheme.
3812 </p>
3813 <p>It is important to distinguish between the mathematical numbers, the
3814 Scheme numbers that attempt to model them, the machine representations
3815 used to implement the Scheme numbers, and notations used to write numbers.
3816 This report uses the types <i>number</i>, <i>complex</i>, <i>real</i>,
3817 <i>rational</i>, and <i>integer</i> to refer to both mathematical numbers
3818 and Scheme numbers. Machine representations such as fixed point and
3819 floating point are referred to by names such as <i>fixnum</i> and
3820 <i>flonum</i>.
3821 </p>
3823 <hr size="1">
3824 <a name="Numerical-types"></a>
3825 <table cellpadding="1" cellspacing="1" border="0">
3826 <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>
3827 <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>
3828 <td valign="middle" align="left"> &nbsp; </td>
3829 <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>
3830 <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>
3831 <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>
3832 <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>
3833 <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>
3834 <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>
3835 </tr></table>
3836 <a name="Numerical-types-1"></a>
3837 <h3 class="subsection">6.2.1 Numerical types</h3>
3841 <a name="index-numerical-types"></a>
3845 <p>Mathematically, numbers may be arranged into a tower of subtypes
3846 in which each level is a subset of the level above it:
3847 </p>
3848 <table><tr><td>&nbsp;</td><td><pre class="format"> <span class="roman">number</span>
3849 <span class="roman">complex</span>
3850 <span class="roman">real</span>
3851 <span class="roman">rational</span>
3852 <span class="roman">integer</span>
3853 </pre></td></tr></table>
3856 <p>For example, 3 is an integer. Therefore 3 is also a rational,
3857 a real, and a complex. The same is true of the Scheme numbers
3858 that model 3. For Scheme numbers, these types are defined by the
3859 predicates <code>number?</code>, <code>complex?</code>, <code>real?</code>, <code>rational?</code>,
3860 <a name="index-rational_003f"></a>
3861 <a name="index-real_003f"></a>
3862 <a name="index-complex_003f"></a>
3863 <a name="index-number_003f-1"></a>
3864 and <code>integer?</code>.
3865 <a name="index-integer_003f"></a>
3866 </p>
3867 <p>There is no simple relationship between a number's type and its
3868 representation inside a computer. Although most implementations of
3869 Scheme will offer at least two different representations of 3, these
3870 different representations denote the same integer.
3871 </p>
3873 <p>Scheme's numerical operations treat numbers as abstract data, as
3874 independent of their representation as possible. Although an implementation
3875 of Scheme may use fixnum, flonum, and perhaps other representations for
3876 numbers, this should not be apparent to a casual programmer writing
3877 simple programs.
3878 </p>
3879 <p>It is necessary, however, to distinguish between numbers that are
3880 represented exactly and those that may not be. For example, indexes
3881 into data structures must be known exactly, as must some polynomial
3882 coefficients in a symbolic algebra system. On the other hand, the
3883 results of measurements are inherently inexact, and irrational numbers
3884 may be approximated by rational and therefore inexact approximations.
3885 In order to catch uses of inexact numbers where exact numbers are
3886 required, Scheme explicitly distinguishes exact from inexact numbers.
3887 This distinction is orthogonal to the dimension of type.
3888 </p>
3889 <hr size="1">
3890 <a name="Exactness"></a>
3891 <table cellpadding="1" cellspacing="1" border="0">
3892 <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>
3893 <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>
3894 <td valign="middle" align="left"> &nbsp; </td>
3895 <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>
3896 <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>
3897 <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>
3898 <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>
3899 <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>
3900 <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>
3901 </tr></table>
3902 <a name="Exactness-1"></a>
3903 <h3 class="subsection">6.2.2 Exactness</h3>
3908 <a name="index-exactness"></a>
3909 <p>Scheme numbers are either <i>exact</i> or <i>inexact</i>. A number is
3910 <span class="roman">exact</span> if it was written as an exact constant or was derived from
3911 <span class="roman">exact</span> numbers using only <span class="roman">exact</span> operations. A number is
3912 <span class="roman">inexact</span> if it was written as an inexact constant,
3913 if it was
3914 derived using <span class="roman">inexact</span> ingredients, or if it was derived using
3915 <span class="roman">inexact</span> operations. Thus <span class="roman">inexact</span>ness is a contagious
3916 property of a number.
3917 </p>
3918 <p>If two implementations produce <span class="roman">exact</span> results for a
3919 computation that did not involve <span class="roman">inexact</span> intermediate results,
3920 the two ultimate results will be mathematically equivalent. This is
3921 generally not true of computations involving <span class="roman">inexact</span> numbers
3922 since approximate methods such as floating point arithmetic may be used,
3923 but it is the duty of each implementation to make the result as close as
3924 practical to the mathematically ideal result.
3925 </p>
3926 <p>Rational operations such as <samp>+</samp> should always produce
3927 <span class="roman">exact</span> results when given <span class="roman">exact</span> arguments.
3928 If the operation is unable to produce an <span class="roman">exact</span> result,
3929 then it may either report the violation of an implementation restriction
3930 or it may silently coerce its
3931 result to an <span class="roman">inexact</span> value.
3932 See section <a href="#Implementation-restrictions">Implementation restrictions</a>.
3933 </p>
3934 <p>With the exception of <code>inexact-&gt;exact</code>, the operations described in
3935 <a name="index-inexact_002d_003eexact"></a>
3936 this section must generally return inexact results when given any inexact
3937 arguments. An operation may, however, return an <span class="roman">exact</span> result if it can
3938 prove that the value of the result is unaffected by the inexactness of its
3939 arguments. For example, multiplication of any number by an <span class="roman">exact</span> zero
3940 may produce an <span class="roman">exact</span> zero result, even if the other argument is
3941 <span class="roman">inexact</span>.
3942 </p>
3943 <hr size="1">
3944 <a name="Implementation-restrictions"></a>
3945 <table cellpadding="1" cellspacing="1" border="0">
3946 <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>
3947 <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>
3948 <td valign="middle" align="left"> &nbsp; </td>
3949 <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>
3950 <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>
3951 <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>
3952 <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>
3953 <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>
3954 <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>
3955 </tr></table>
3956 <a name="Implementation-restrictions-1"></a>
3957 <h3 class="subsection">6.2.3 Implementation restrictions</h3>
3961 <a name="index-implementation-restriction-1"></a>
3963 <p>Implementations of Scheme are not required to implement the whole
3964 tower of subtypes given in section <a href="#Numerical-types">Numerical types</a>,
3965 but they must implement a coherent subset consistent with both the
3966 purposes of the implementation and the spirit of the Scheme language.
3967 For example, an implementation in which all numbers are <span class="roman">real</span>
3968 may still be quite useful.
3969 </p>
3970 <p>Implementations may also support only a limited range of numbers of
3971 any type, subject to the requirements of this section. The supported
3972 range for <span class="roman">exact</span> numbers of any type may be different from the
3973 supported range for <span class="roman">inexact</span> numbers of that type. For example,
3974 an implementation that uses flonums to represent all its
3975 <span class="roman">inexact</span> <span class="roman">real</span> numbers may
3976 support a practically unbounded range of <span class="roman">exact</span> <span class="roman">integer</span>s
3977 and <span class="roman">rational</span>s
3978 while limiting the range of <span class="roman">inexact</span> <span class="roman">real</span>s (and therefore
3979 the range of <span class="roman">inexact</span> <span class="roman">integer</span>s and <span class="roman">rational</span>s)
3980 to the dynamic range of the flonum format.
3981 Furthermore
3982 the gaps between the representable <span class="roman">inexact</span> <span class="roman">integer</span>s and
3983 <span class="roman">rational</span>s are
3984 likely to be very large in such an implementation as the limits of this
3985 range are approached.
3986 </p>
3987 <p>An implementation of Scheme must support exact integers
3988 throughout the range of numbers that may be used for indexes of
3989 lists, vectors, and strings or that may result from computing the length of a
3990 list, vector, or string. The <code>length</code>, <code>vector-length</code>,
3991 <a name="index-vector_002dlength"></a>
3992 <a name="index-length"></a>
3993 and <code>string-length</code> procedures must return an exact
3994 <a name="index-string_002dlength"></a>
3995 integer, and it is an error to use anything but an exact integer as an
3996 index. Furthermore any integer constant within the index range, if
3997 expressed by an exact integer syntax, will indeed be read as an exact
3998 integer, regardless of any implementation restrictions that may apply
3999 outside this range. Finally, the procedures listed below will always
4000 return an exact integer result provided all their arguments are exact integers
4001 and the mathematically expected result is representable as an exact integer
4002 within the implementation:
4003 </p>
4005 <table><tr><td>&nbsp;</td><td><pre class="example">
4006 + - *
4007 quotient remainder modulo
4008 max min abs
4009 numerator denominator gcd
4010 lcm floor ceiling
4011 truncate round rationalize
4012 expt
4013 </pre></td></tr></table>
4016 <p>Implementations are encouraged, but not required, to support
4017 <span class="roman">exact</span> <span class="roman">integer</span>s and <span class="roman">exact</span> <span class="roman">rational</span>s of
4018 practically unlimited size and precision, and to implement the
4019 above procedures and the <samp>/</samp> procedure in
4020 such a way that they always return <span class="roman">exact</span> results when given <span class="roman">exact</span>
4021 arguments. If one of these procedures is unable to deliver an <span class="roman">exact</span>
4022 result when given <span class="roman">exact</span> arguments, then it may either report a
4023 violation of an
4024 implementation restriction or it may silently coerce its result to an
4025 <span class="roman">inexact</span> number. Such a coercion may cause an error later.
4026 </p>
4029 <p>An implementation may use floating point and other approximate
4030 representation strategies for <span class="roman">inexact</span> numbers.
4031 </p>
4033 <p>This report recommends, but does not require, that the IEEE 32-bit
4034 and 64-bit floating point standards be followed by implementations that use
4035 flonum representations, and that implementations using
4036 other representations should match or exceed the precision achievable
4037 using these floating point standards [IEEE].
4038 </p>
4039 <p>In particular, implementations that use flonum representations
4040 must follow these rules: A <span class="roman">flonum</span> result
4041 must be represented with at least as much precision as is used to express any of
4042 the inexact arguments to that operation. It is desirable (but not required) for
4043 potentially inexact operations such as <samp>sqrt</samp>, when applied to <span class="roman">exact</span>
4044 arguments, to produce <span class="roman">exact</span> answers whenever possible (for example the
4045 square root of an <span class="roman">exact</span> 4 ought to be an <span class="roman">exact</span> 2).
4046 If, however, an
4047 <span class="roman">exact</span> number is operated upon so as to produce an <span class="roman">inexact</span> result
4048 (as by <samp>sqrt</samp>), and if the result is represented as a <span class="roman">flonum</span>, then
4049 the most precise <span class="roman">flonum</span> format available must be used; but if the result
4050 is represented in some other way then the representation must have at least as
4051 much precision as the most precise <span class="roman">flonum</span> format available.
4052 </p>
4053 <p>Although Scheme allows a variety of written
4054 notations for
4055 numbers, any particular implementation may support only some of them.
4056 For example, an implementation in which all numbers are <span class="roman">real</span>
4057 need not support the rectangular and polar notations for complex
4058 numbers. If an implementation encounters an <span class="roman">exact</span> numerical constant that
4059 it cannot represent as an <span class="roman">exact</span> number, then it may either report a
4060 violation of an implementation restriction or it may silently represent the
4061 constant by an <span class="roman">inexact</span> number.
4062 </p>
4064 <hr size="1">
4065 <a name="Syntax-of-numerical-constants"></a>
4066 <table cellpadding="1" cellspacing="1" border="0">
4067 <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>
4068 <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>
4069 <td valign="middle" align="left"> &nbsp; </td>
4070 <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>
4071 <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>
4072 <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>
4073 <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>
4074 <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>
4075 <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>
4076 </tr></table>
4077 <a name="Syntax-of-numerical-constants-1"></a>
4078 <h3 class="subsection">6.2.4 Syntax of numerical constants</h3>
4085 <p>The syntax of the written representations for numbers is described formally in
4086 section <a href="#Lexical-structure">Lexical structure</a>. Note that case is not significant in numerical
4087 constants.
4088 </p>
4090 <p>A number may be written in binary, octal, decimal, or
4091 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
4092 <a name="index-_0023x"></a>
4093 <a name="index-_0023d"></a>
4094 <a name="index-_0023o"></a>
4095 <a name="index-_0023b"></a>
4096 no radix prefix, a number is assumed to be expressed in decimal.
4097 </p>
4098 <p>A
4099 numerical constant may be specified to be either <span class="roman">exact</span> or
4100 <span class="roman">inexact</span> by a prefix. The prefixes are <samp>#e</samp>
4101 <a name="index-_0023e"></a>
4102 for <span class="roman">exact</span>, and <samp>#i</samp> for <span class="roman">inexact</span>. An exactness
4103 <a name="index-_0023i"></a>
4104 prefix may appear before or after any radix prefix that is used. If
4105 the written representation of a number has no exactness prefix, the
4106 constant may be either <span class="roman">inexact</span> or <span class="roman">exact</span>. It is
4107 <span class="roman">inexact</span> if it contains a decimal point, an
4108 exponent, or a &ldquo;#&rdquo; character in the place of a digit,
4109 otherwise it is <span class="roman">exact</span>.
4110 </p>
4112 <p>In systems with <span class="roman">inexact</span> numbers
4113 of varying precisions it may be useful to specify
4114 the precision of a constant. For this purpose, numerical constants
4115 may be written with an exponent marker that indicates the
4116 desired precision of the <span class="roman">inexact</span>
4117 representation. The letters <samp>s</samp>, <samp>f</samp>,
4118 <samp>d</samp>, and <samp>l</samp> specify the use of <var>short</var>, <var>single</var>,
4119 <var>double</var>, and <var>long</var> precision, respectively. (When fewer
4120 than four internal
4121 <span class="roman">inexact</span>
4122 representations exist, the four size
4123 specifications are mapped onto those available. For example, an
4124 implementation with two internal representations may map short and
4125 single together and long and double together.) In addition, the
4126 exponent marker <samp>e</samp> specifies the default precision for the
4127 implementation. The default precision has at least as much precision
4128 as <var>double</var>, but
4129 implementations may wish to allow this default to be set by the user.
4130 </p>
4132 <table><tr><td>&nbsp;</td><td><pre class="example">
4133 3.14159265358979F0
4134 <span class="roman">Round to single ---</span> 3.141593
4135 0.6L0
4136 <span class="roman">Extend to long ---</span> .600000000000000
4137 </pre></td></tr></table>
4141 <hr size="1">
4142 <a name="Numerical-operations"></a>
4143 <table cellpadding="1" cellspacing="1" border="0">
4144 <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>
4145 <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>
4146 <td valign="middle" align="left"> &nbsp; </td>
4147 <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>
4148 <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>
4149 <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>
4150 <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>
4151 <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>
4152 <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>
4153 </tr></table>
4154 <a name="Numerical-operations-1"></a>
4155 <h3 class="subsection">6.2.5 Numerical operations</h3>
4158 <p>The reader is referred to section <a href="#Entry-format">Entry format</a> for a summary
4159 of the naming conventions used to specify restrictions on the types of
4160 arguments to numerical routines.
4161 </p>
4162 <p>The examples used in this section assume that any numerical constant written
4163 using an <span class="roman">exact</span> notation is indeed represented as an <span class="roman">exact</span>
4164 number. Some examples also assume that certain numerical constants written
4165 using an <span class="roman">inexact</span> notation can be represented without loss of
4166 accuracy; the <span class="roman">inexact</span> constants were chosen so that this is
4167 likely to be true in implementations that use flonums to represent
4168 inexact numbers.
4169 </p>
4173 <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>
4174 <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>
4175 <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>
4176 <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>
4177 <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>
4179 <p>These numerical type predicates can be applied to any kind of
4180 argument, including non-numbers. They return <tt>#t</tt> if the object is
4181 of the named type, and otherwise they return <tt>#f</tt>.
4182 In general, if a type predicate is true of a number then all higher
4183 type predicates are also true of that number. Consequently, if a type
4184 predicate is false of a number, then all lower type predicates are
4185 also false of that number.
4186 </p>
4187 <p>If <var>z</var> is an inexact complex number, then <samp>(real? <var>z</var>)</samp> is true if
4188 and only if <samp>(zero? (imag-part <var>z</var>))</samp> is true. If <var>x</var> is an inexact
4189 real number, then <samp>(integer? <var>x</var>)</samp> is true if and only if
4190 <samp>(= <var>x</var> (round <var>x</var>))</samp>.
4191 </p>
4193 <table><tr><td>&nbsp;</td><td><pre class="format">(complex? 3+4i) ==&gt; #t
4194 (complex? 3) ==&gt; #t
4195 (real? 3) ==&gt; #t
4196 (real? -2.5+0.0i) ==&gt; #t
4197 (real? #e1e10) ==&gt; #t
4198 (rational? 6/10) ==&gt; #t
4199 (rational? 6/3) ==&gt; #t
4200 (integer? 3+0i) ==&gt; #t
4201 (integer? 3.0) ==&gt; #t
4202 (integer? 8/4) ==&gt; #t
4203 </pre></td></tr></table>
4207 <blockquote><p><em>Note:</em>
4208 The behavior of these type predicates on <span class="roman">inexact</span> numbers
4209 is unreliable, since any inaccuracy may affect the result.
4210 </p></blockquote>
4214 <blockquote><p><em>Note:</em>
4215 In many implementations the <code>rational?</code> procedure will be the same
4216 <a name="index-rational_003f-2"></a>
4217 as <code>real?</code>, and the <code>complex?</code> procedure will be the same as
4218 <a name="index-complex_003f-2"></a>
4219 <a name="index-real_003f-2"></a>
4220 <code>number?</code>, but unusual implementations may be able to represent
4221 <a name="index-number_003f-3"></a>
4222 some irrational numbers exactly or may extend the number system to
4223 support some kind of non-complex numbers.
4224 </p></blockquote>
4230 <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>
4231 <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>
4233 <p>These numerical predicates provide tests for the exactness of a
4234 quantity. For any Scheme number, precisely one of these predicates
4235 is true.
4236 </p>
4241 <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>
4242 <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>
4243 <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>
4244 <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>
4245 <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>
4247 <p>These procedures return <tt>#t</tt> if their arguments are (respectively):
4248 equal, monotonically increasing, monotonically decreasing,
4249 monotonically nondecreasing, or monotonically nonincreasing.
4250 </p>
4251 <p>These predicates are required to be transitive.
4252 </p>
4254 <blockquote><p><em>Note:</em>
4255 The traditional implementations of these predicates in Lisp-like
4256 languages are not transitive.
4257 </p></blockquote>
4261 <blockquote><p><em>Note:</em>
4262 While it is not an error to compare <span class="roman">inexact</span> numbers using these
4263 predicates, the results may be unreliable because a small inaccuracy
4264 may affect the result; this is especially true of <code>=</code> and <code>zero?</code>.
4265 <a name="index-zero_003f"></a>
4266 <a name="index-_003d-1"></a>
4267 When in doubt, consult a numerical analyst.
4268 </p></blockquote>
4274 <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>
4275 <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>
4276 <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>
4277 <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>
4278 <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>
4280 <p>These numerical predicates test a number for a particular property,
4281 returning <tt>#t</tt> or <tt>#f</tt>. See note above.
4282 </p>
4286 <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>
4287 <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>
4289 <p>These procedures return the maximum or minimum of their arguments.
4290 </p>
4292 <table><tr><td>&nbsp;</td><td><pre class="format">(max 3 4) ==&gt; 4 ; exact
4293 (max 3.9 4) ==&gt; 4.0 ; inexact
4294 </pre></td></tr></table>
4298 <blockquote><p><em>Note:</em>
4299 If any argument is inexact, then the result will also be inexact (unless
4300 the procedure can prove that the inaccuracy is not large enough to affect the
4301 result, which is possible only in unusual implementations). If <samp>min</samp> or
4302 <samp>max</samp> is used to compare numbers of mixed exactness, and the numerical
4303 value of the result cannot be represented as an inexact number without loss of
4304 accuracy, then the procedure may report a violation of an implementation
4305 restriction.
4306 </p></blockquote>
4313 <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>
4314 <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>
4316 <p>These procedures return the sum or product of their arguments.
4317 </p>
4319 <table><tr><td>&nbsp;</td><td><pre class="format">(+ 3 4) ==&gt; 7
4320 (+ 3) ==&gt; 3
4321 (+) ==&gt; 0
4322 (* 4) ==&gt; 4
4323 (*) ==&gt; 1
4324 </pre></td></tr></table>
4331 <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>
4332 <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>
4333 <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>
4334 <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>
4335 <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>
4336 <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>
4338 <p>With two or more arguments, these procedures return the difference or
4339 quotient of their arguments, associating to the left. With one argument,
4340 however, they return the additive or multiplicative inverse of their argument.
4341 </p>
4343 <table><tr><td>&nbsp;</td><td><pre class="format">(- 3 4) ==&gt; -1
4344 (- 3 4 5) ==&gt; -6
4345 (- 3) ==&gt; -3
4346 (/ 3 4 5) ==&gt; 3/20
4347 (/ 3) ==&gt; 1/3
4348 </pre></td></tr></table>
4355 <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>
4357 <p><samp>Abs</samp> returns the absolute value of its argument.
4358 </p>
4359 <table><tr><td>&nbsp;</td><td><pre class="format">(abs -7) ==&gt; 7
4360 </pre></td></tr></table>
4366 <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>
4367 <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>
4368 <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>
4370 <p>These procedures implement number-theoretic (integer)
4371 division. <var>n2</var> should be non-zero. All three procedures
4372 return integers. If <var>n1</var>/<var>n2</var> is an integer:
4373 </p>
4374 <table><tr><td>&nbsp;</td><td><pre class="format"> (quotient <var>n1</var> <var>n2</var>) ==&gt; <var>n1</var>/<var>n2</var>
4375 (remainder <var>n1</var> <var>n2</var>) ==&gt; 0
4376 (modulo <var>n1</var> <var>n2</var>) ==&gt; 0
4377 </pre></td></tr></table>
4379 <p>If <var>n1</var>/<var>n2</var> is not an integer:
4380 </p>
4381 <table><tr><td>&nbsp;</td><td><pre class="format"> (quotient <var>n1</var> <var>n2</var>) ==&gt; <var>n_q</var>
4382 (remainder <var>n1</var> <var>n2</var>) ==&gt; <var>n_r</var>
4383 (modulo <var>n1</var> <var>n2</var>) ==&gt; <var>n_m</var>
4384 </pre></td></tr></table>
4386 <p>where <var>n_q</var> is <var>n1</var>/<var>n2</var> rounded towards zero,
4387 0 &lt; |<var>n_r</var>| &lt; |<var>n2</var>|, 0 &lt; |<var>n_m</var>| &lt; |<var>n2</var>|,
4388 <var>n_r</var> and <var>n_m</var> differ from <var>n1</var> by a multiple of <var>n2</var>,
4389 <var>n_r</var> has the same sign as <var>n1</var>, and
4390 <var>n_m</var> has the same sign as <var>n2</var>.
4391 </p>
4392 <p>From this we can conclude that for integers <var>n1</var> and <var>n2</var> with
4393 <var>n2</var> not equal to 0,
4394 </p>
4395 <table><tr><td>&nbsp;</td><td><pre class="format"> (= <var>n1</var> (+ (* <var>n2</var> (quotient <var>n1</var> <var>n2</var>))
4396 (remainder <var>n1</var> <var>n2</var>)))
4397 ==&gt; #t
4398 </pre></td></tr></table>
4400 <p>provided all numbers involved in that computation are exact.
4401 </p>
4403 <table><tr><td>&nbsp;</td><td><pre class="format">(modulo 13 4) ==&gt; 1
4404 (remainder 13 4) ==&gt; 1
4406 (modulo -13 4) ==&gt; 3
4407 (remainder -13 4) ==&gt; -1
4409 (modulo 13 -4) ==&gt; -3
4410 (remainder 13 -4) ==&gt; 1
4412 (modulo -13 -4) ==&gt; -1
4413 (remainder -13 -4) ==&gt; -1
4415 (remainder -13 -4.0) ==&gt; -1.0 ; inexact
4416 </pre></td></tr></table>
4421 <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>
4422 <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>
4424 <p>These procedures return the greatest common divisor or least common
4425 multiple of their arguments. The result is always non-negative.
4426 </p>
4428 <table><tr><td>&nbsp;</td><td><pre class="format">(gcd 32 -36) ==&gt; 4
4429 (gcd) ==&gt; 0
4430 (lcm 32 -36) ==&gt; 288
4431 (lcm 32.0 -36) ==&gt; 288.0 ; inexact
4432 (lcm) ==&gt; 1
4433 </pre></td></tr></table>
4440 <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>
4441 <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>
4443 <p>These procedures return the numerator or denominator of their
4444 argument; the result is computed as if the argument was represented as
4445 a fraction in lowest terms. The denominator is always positive. The
4446 denominator of 0 is defined to be 1.
4447 </p>
4450 <table><tr><td>&nbsp;</td><td><pre class="format">(numerator (/ 6 4)) ==&gt; 3
4451 (denominator (/ 6 4)) ==&gt; 2
4452 (denominator
4453 (exact-&gt;inexact (/ 6 4))) ==&gt; 2.0
4454 </pre></td></tr></table>
4461 <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>
4462 <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>
4463 <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>
4464 <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>
4467 <p>These procedures return integers.
4468 <samp>Floor</samp> returns the largest integer not larger than <var>x</var>.
4469 <samp>Ceiling</samp> returns the smallest integer not smaller than <var>x</var>.
4470 <samp>Truncate</samp> returns the integer closest to <var>x</var> whose absolute
4471 value is not larger than the absolute value of <var>x</var>. <samp>Round</samp> returns the
4472 closest integer to <var>x</var>, rounding to even when <var>x</var> is halfway between two
4473 integers.
4474 </p>
4476 <blockquote><p><em>Rationale:</em>
4477 <samp>Round</samp> rounds to even for consistency with the default rounding
4478 mode specified by the IEEE floating point standard.
4479 </p></blockquote>
4483 <blockquote><p><em>Note:</em>
4484 If the argument to one of these procedures is inexact, then the result
4485 will also be inexact. If an exact value is needed, the
4486 result should be passed to the <samp>inexact-&gt;exact</samp> procedure.
4487 </p></blockquote>
4491 <table><tr><td>&nbsp;</td><td><pre class="format">(floor -4.3) ==&gt; -5.0
4492 (ceiling -4.3) ==&gt; -4.0
4493 (truncate -4.3) ==&gt; -4.0
4494 (round -4.3) ==&gt; -4.0
4496 (floor 3.5) ==&gt; 3.0
4497 (ceiling 3.5) ==&gt; 4.0
4498 (truncate 3.5) ==&gt; 3.0
4499 (round 3.5) ==&gt; 4.0 ; inexact
4501 (round 7/2) ==&gt; 4 ; exact
4502 (round 7) ==&gt; 7
4503 </pre></td></tr></table>
4509 <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>
4512 <p><samp>Rationalize</samp> returns the <em>simplest</em> rational number
4513 differing from <var>x</var> by no more than <var>y</var>. A rational number r_1 is
4514 <em>simpler</em> than another rational number
4515 <a name="index-simplest-rational"></a>
4516 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.
4517 Although not all rationals are comparable in this ordering (consider 2/7
4518 and 3/5) any interval contains a rational number that is simpler than
4519 every other rational number in that interval (the simpler 2/5 lies
4520 between 2/7 and 3/5). Note that 0 = 0/1 is the simplest rational of
4521 all.
4522 </p>
4524 <table><tr><td>&nbsp;</td><td><pre class="format">(rationalize
4525 (inexact-&gt;exact .3) 1/10) ==&gt; 1/3 ; exact
4526 (rationalize .3 1/10) ==&gt; #i1/3 ; inexact
4527 </pre></td></tr></table>
4533 <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>
4534 <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>
4535 <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>
4536 <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>
4537 <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>
4538 <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>
4539 <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>
4540 <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>
4541 <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>
4543 <p>These procedures are part of every implementation that supports
4544 general
4545 real numbers; they compute the usual transcendental functions. <samp>log</samp>
4546 computes the natural logarithm of <var>z</var> (not the base ten logarithm).
4547 <samp>asin</samp>, <samp>acos</samp>, and <samp>atan</samp> compute arcsine (sin^-1),
4548 arccosine (cos^-1), and arctangent (tan^-1), respectively.
4549 The two-argument variant of <samp>atan</samp> computes <tt>(angle
4550 (make-rectangular <var>x</var> <var>y</var>))</tt> (see below), even in implementations
4551 that don't support general complex numbers.
4552 </p>
4553 <p>In general, the mathematical functions log, arcsine, arccosine, and
4554 arctangent are multiply defined.
4555 The value of log z is defined to be the one whose imaginary
4556 part lies in the range from -pi (exclusive) to pi (inclusive).
4557 log 0 is undefined.
4558 With log defined this way, the values of sin^-1 z, cos^-1 z,
4559 and tan^-1 z are according to the following formulae:
4560 </p>
4562 <p align="center"> sin^-1 z = -i log (i z + sqrt(1 - z^2))
4563 </p>
4566 <p align="center"> cos^-1 z = pi / 2 - sin^-1 z
4567 </p>
4570 <p align="center"> tan^-1 z = (log (1 + i z) - log (1 - i z)) / (2 i)
4571 </p>
4573 <p>The above specification follows [CLtL], which in turn
4574 cites [Penfield81]; refer to these sources for more detailed
4575 discussion of branch cuts, boundary conditions, and implementation of
4576 these functions. When it is possible these procedures produce a real
4577 result from a real argument.
4578 </p>
4586 <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>
4588 <p>Returns the principal square root of <var>z</var>. The result will have
4589 either positive real part, or zero real part and non-negative imaginary
4590 part.
4591 </p>
4595 <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>
4597 <p>Returns <var>z1</var> raised to the power <var>z2</var>. For z_1 ~= 0
4598 </p>
4600 <p align="center"> z_1^z_2 = e^z_2 log z_1
4601 </p>
4602 <p>0^z is 1 if z = 0 and 0 otherwise.
4603 </p>
4609 <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>
4610 <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>
4611 <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>
4612 <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>
4613 <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>
4614 <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>
4616 <p>These procedures are part of every implementation that supports
4617 general
4618 complex numbers. Suppose <var>x1</var>, <var>x2</var>, <var>x3</var>, and <var>x4</var> are
4619 real numbers and <var>z</var> is a complex number such that
4620 </p>
4622 <p align="center"> <var>z</var> = <var>x1</var> + <var>x2</var>i = <var>x3</var> . e^i <var>x4</var>
4623 </p>
4624 <p>Then
4625 </p>
4626 <table><tr><td>&nbsp;</td><td><pre class="format">(make-rectangular <var>x1</var> <var>x2</var>) ==&gt; <var>z</var>
4627 (make-polar <var>x3</var> <var>x4</var>) ==&gt; <var>z</var>
4628 (real-part <var>z</var>) ==&gt; <var>x1</var>
4629 (imag-part <var>z</var>) ==&gt; <var>x2</var>
4630 (magnitude <var>z</var>) ==&gt; |<var>x3</var>|
4631 (angle <var>z</var>) ==&gt; x_angle
4632 </pre></td></tr></table>
4634 <p>where -pi &lt; x_angle &lt;= pi with x_angle = <var>x4</var> + 2pi n
4635 for some integer n.
4636 </p>
4638 <blockquote><p><em>Rationale:</em>
4639 <samp>Magnitude</samp> is the same as <code>abs</code> for a real argument,
4640 <a name="index-abs-1"></a>
4641 but <samp>abs</samp> must be present in all implementations, whereas
4642 <samp>magnitude</samp> need only be present in implementations that support
4643 general complex numbers.
4644 </p></blockquote>
4651 <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>
4652 <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>
4654 <p><samp>Exact-&gt;inexact</samp> returns an <span class="roman">inexact</span> representation of <var>z</var>.
4655 The value returned is the
4656 <span class="roman">inexact</span> number that is numerically closest to the argument.
4657 If an <span class="roman">exact</span> argument has no reasonably close <span class="roman">inexact</span> equivalent,
4658 then a violation of an implementation restriction may be reported.
4659 </p>
4660 <p><samp>Inexact-&gt;exact</samp> returns an <span class="roman">exact</span> representation of
4661 <var>z</var>. The value returned is the <span class="roman">exact</span> number that is numerically
4662 closest to the argument.
4663 If an <span class="roman">inexact</span> argument has no reasonably close <span class="roman">exact</span> equivalent,
4664 then a violation of an implementation restriction may be reported.
4665 </p>
4667 <p>These procedures implement the natural one-to-one correspondence between
4668 <span class="roman">exact</span> and <span class="roman">inexact</span> integers throughout an
4669 implementation-dependent range. See section <a href="#Implementation-restrictions">Implementation restrictions</a>.
4670 </p>
4673 <br>
4674 <br>
4675 <br>
4677 <hr size="1">
4678 <a name="Numerical-input-and-output"></a>
4679 <table cellpadding="1" cellspacing="1" border="0">
4680 <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>
4681 <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>
4682 <td valign="middle" align="left"> &nbsp; </td>
4683 <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>
4684 <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>
4685 <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>
4686 <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>
4687 <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>
4688 <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>
4689 </tr></table>
4690 <a name="Numerical-input-and-output-1"></a>
4691 <h3 class="subsection">6.2.6 Numerical input and output</h3>
4695 <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>
4696 <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>
4698 <p><var>Radix</var> must be an exact integer, either 2, 8, 10, or 16. If omitted,
4699 <var>radix</var> defaults to 10.
4700 The procedure <samp>number-&gt;string</samp> takes a
4701 number and a radix and returns as a string an external representation of
4702 the given number in the given radix such that
4703 </p>
4704 <table><tr><td>&nbsp;</td><td><pre class="format">(let ((number <var>number</var>)
4705 (radix <var>radix</var>))
4706 (eqv? number
4707 (string-&gt;number (number-&gt;string number
4708 radix)
4709 radix)))
4710 </pre></td></tr></table>
4712 <p>is true. It is an error if no possible result makes this expression true.
4713 </p>
4714 <p>If <var>z</var> is inexact, the radix is 10, and the above expression
4715 can be satisfied by a result that contains a decimal point,
4716 then the result contains a decimal point and is expressed using the
4717 minimum number of digits (exclusive of exponent and trailing
4718 zeroes) needed to make the above expression
4719 true [howtoprint], [howtoread];
4720 otherwise the format of the result is unspecified.
4721 </p>
4722 <p>The result returned by <samp>number-&gt;string</samp>
4723 never contains an explicit radix prefix.
4724 </p>
4726 <blockquote><p><em>Note:</em>
4727 The error case can occur only when <var>z</var> is not a complex number
4728 or is a complex number with a non-rational real or imaginary part.
4729 </p></blockquote>
4733 <blockquote><p><em>Rationale:</em>
4734 If <var>z</var> is an inexact number represented using flonums, and
4735 the radix is 10, then the above expression is normally satisfied by
4736 a result containing a decimal point. The unspecified case
4737 allows for infinities, NaNs, and non-flonum representations.
4738 </p></blockquote>
4745 <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>
4746 <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>
4749 <p>Returns a number of the maximally precise representation expressed by the
4750 given <var>string</var>. <var>Radix</var> must be an exact integer, either 2, 8, 10,
4751 or 16. If supplied, <var>radix</var> is a default radix that may be overridden
4752 by an explicit radix prefix in <var>string</var> (e.g. <tt>&quot;#o177&quot;</tt>). If <var>radix</var>
4753 is not supplied, then the default radix is 10. If <var>string</var> is not
4754 a syntactically valid notation for a number, then <samp>string-&gt;number</samp>
4755 returns <tt>#f</tt>.
4756 </p>
4758 <table><tr><td>&nbsp;</td><td><pre class="format">(string-&gt;number &quot;100&quot;) ==&gt; 100
4759 (string-&gt;number &quot;100&quot; 16) ==&gt; 256
4760 (string-&gt;number &quot;1e2&quot;) ==&gt; 100.0
4761 (string-&gt;number &quot;15##&quot;) ==&gt; 1500.0
4762 </pre></td></tr></table>
4766 <blockquote><p><em>Note:</em>
4767 The domain of <samp>string-&gt;number</samp> may be restricted by implementations
4768 in the following ways. <samp>String-&gt;number</samp> is permitted to return
4769 <tt>#f</tt> whenever <var>string</var> contains an explicit radix prefix.
4770 If all numbers supported by an implementation are real, then
4771 <samp>string-&gt;number</samp> is permitted to return <tt>#f</tt> whenever
4772 <var>string</var> uses the polar or rectangular notations for complex
4773 numbers. If all numbers are integers, then
4774 <samp>string-&gt;number</samp> may return <tt>#f</tt> whenever
4775 the fractional notation is used. If all numbers are exact, then
4776 <samp>string-&gt;number</samp> may return <tt>#f</tt> whenever
4777 an exponent marker or explicit exactness prefix is used, or if
4778 a <tt>#</tt> appears in place of a digit. If all inexact
4779 numbers are integers, then
4780 <samp>string-&gt;number</samp> may return <tt>#f</tt> whenever
4781 a decimal point is used.
4782 </p></blockquote>
4787 <hr size="1">
4788 <a name="Other-data-types"></a>
4789 <table cellpadding="1" cellspacing="1" border="0">
4790 <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>
4791 <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>
4792 <td valign="middle" align="left"> &nbsp; </td>
4793 <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>
4794 <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>
4795 <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>
4796 <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>
4797 <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>
4798 <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>
4799 </tr></table>
4800 <a name="Other-data-types-1"></a>
4801 <h2 class="section">6.3 Other data types</h2>
4803 <table class="menu" border="0" cellspacing="0">
4804 <tr><td align="left" valign="top"><a href="#Booleans">6.3.1 Booleans</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
4805 </td></tr>
4806 <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">
4807 </td></tr>
4808 <tr><td align="left" valign="top"><a href="#Symbols">6.3.3 Symbols</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
4809 </td></tr>
4810 <tr><td align="left" valign="top"><a href="#Characters">6.3.4 Characters</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
4811 </td></tr>
4812 <tr><td align="left" valign="top"><a href="#Strings">6.3.5 Strings</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
4813 </td></tr>
4814 <tr><td align="left" valign="top"><a href="#Vectors">6.3.6 Vectors</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
4815 </td></tr>
4816 </table>
4819 <p>This section describes operations on some of Scheme's non-numeric data types:
4820 booleans, pairs, lists, symbols, characters, strings and vectors.
4821 </p>
4822 <hr size="1">
4823 <a name="Booleans"></a>
4824 <table cellpadding="1" cellspacing="1" border="0">
4825 <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>
4826 <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>
4827 <td valign="middle" align="left"> &nbsp; </td>
4828 <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>
4829 <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>
4830 <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>
4831 <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>
4832 <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>
4833 <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>
4834 </tr></table>
4835 <a name="Booleans-1"></a>
4836 <h3 class="subsection">6.3.1 Booleans</h3>
4840 <p>The standard boolean objects for true and false are written as
4841 <tt>#t</tt> and <tt>#f</tt>. What really
4842 <a name="index-_0023f"></a>
4843 <a name="index-_0023t"></a>
4844 matters, though, are the objects that the Scheme conditional expressions
4845 (<samp>if</samp>, <samp>cond</samp>, <samp>and</samp>, <samp>or</samp>, <samp>do</samp>) treat as
4846 true or false. The phrase &ldquo;a true value&rdquo;
4847 <a name="index-false-1"></a>
4848 <a name="index-true-3"></a>
4849 (or sometimes just &ldquo;true&rdquo;) means any object treated as true by the
4850 conditional expressions, and the phrase &ldquo;a false value&rdquo; (or
4851 <a name="index-false-2"></a>
4852 &ldquo;false&rdquo;) means any object treated as false by the conditional expressions.
4853 </p>
4854 <p>Of all the standard Scheme values, only <tt>#f</tt>
4855 counts as false in conditional expressions.
4856 Except for <tt>#f</tt>,
4857 all standard Scheme values, including <tt>#t</tt>,
4858 pairs, the empty list, symbols, numbers, strings, vectors, and procedures,
4859 count as true.
4860 </p>
4864 <blockquote><p><em>Note:</em>
4865 Programmers accustomed to other dialects of Lisp should be aware that
4866 Scheme distinguishes both <tt>#f</tt> and the empty list
4867 <a name="index-empty-list-1"></a>
4868 from the symbol <code>nil</code>.
4869 <a name="index-nil"></a>
4870 </p></blockquote>
4873 <p>Boolean constants evaluate to themselves, so they do not need to be quoted
4874 in programs.
4875 </p>
4877 <table><tr><td>&nbsp;</td><td><pre class="example">
4878 #t ==&gt; #t
4879 #f ==&gt; #f
4880 '#f ==&gt; #f
4881 </pre></td></tr></table>
4886 <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>
4888 <p><samp>Not</samp> returns <tt>#t</tt> if <var>obj</var> is false, and returns
4889 <tt>#f</tt> otherwise.
4890 </p>
4892 <table><tr><td>&nbsp;</td><td><pre class="format">(not #t) ==&gt; #f
4893 (not 3) ==&gt; #f
4894 (not (list 3)) ==&gt; #f
4895 (not #f) ==&gt; #t
4896 (not '()) ==&gt; #f
4897 (not (list)) ==&gt; #f
4898 (not 'nil) ==&gt; #f
4899 </pre></td></tr></table>
4906 <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>
4908 <p><samp>Boolean?</samp> returns <tt>#t</tt> if <var>obj</var> is either <tt>#t</tt> or
4909 <tt>#f</tt> and returns <tt>#f</tt> otherwise.
4910 </p>
4912 <table><tr><td>&nbsp;</td><td><pre class="format">(boolean? #f) ==&gt; #t
4913 (boolean? 0) ==&gt; #f
4914 (boolean? '()) ==&gt; #f
4915 </pre></td></tr></table>
4921 <hr size="1">
4922 <a name="Pairs-and-lists"></a>
4923 <table cellpadding="1" cellspacing="1" border="0">
4924 <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>
4925 <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>
4926 <td valign="middle" align="left"> &nbsp; </td>
4927 <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>
4928 <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>
4929 <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>
4930 <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>
4931 <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>
4932 <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>
4933 </tr></table>
4934 <a name="Pairs-and-lists-1"></a>
4935 <h3 class="subsection">6.3.2 Pairs and lists</h3>
4939 <p>A <em>pair</em> (sometimes called a <em>dotted pair</em>) is a
4940 <a name="index-dotted-pair"></a>
4941 <a name="index-pair"></a>
4942 record structure with two fields called the car and cdr fields (for
4943 historical reasons). Pairs are created by the procedure <samp>cons</samp>.
4944 The car and cdr fields are accessed by the procedures <samp>car</samp> and
4945 <samp>cdr</samp>. The car and cdr fields are assigned by the procedures
4946 <samp>set-car!</samp> and <samp>set-cdr!</samp>.
4947 </p>
4948 <p>Pairs are used primarily to represent lists. A list can
4949 be defined recursively as either the empty list or a pair whose
4950 <a name="index-empty-list-2"></a>
4951 cdr is a list. More precisely, the set of lists is defined as the smallest
4952 set <var>X</var> such that
4953 </p>
4956 <ul>
4957 <li>
4958 The empty list is in <var>X</var>.
4959 </li><li>
4960 If <var>list</var> is in <var>X</var>, then any pair whose cdr field contains
4961 <var>list</var> is also in <var>X</var>.
4963 </li></ul>
4966 <p>The objects in the car fields of successive pairs of a list are the
4967 elements of the list. For example, a two-element list is a pair whose car
4968 is the first element and whose cdr is a pair whose car is the second element
4969 and whose cdr is the empty list. The length of a list is the number of
4970 elements, which is the same as the number of pairs.
4971 </p>
4972 <p>The empty list is a special object of its own type
4973 <a name="index-empty-list-3"></a>
4974 (it is not a pair); it has no elements and its length is zero.
4975 </p>
4977 <blockquote><p><em>Note:</em>
4978 The above definitions imply that all lists have finite length and are
4979 terminated by the empty list.
4980 </p></blockquote>
4983 <p>The most general notation (external representation) for Scheme pairs is
4984 the &ldquo;dotted&rdquo; notation <samp>(<var>c1</var> . <var>c2</var>)</samp> where
4985 <var>c1</var> is the value of the car field and <var>c2</var> is the value of the
4986 cdr field. For example <samp>(4 . 5)</samp> is a pair whose car is 4 and whose
4987 cdr is 5. Note that <samp>(4 . 5)</samp> is the external representation of a
4988 pair, not an expression that evaluates to a pair.
4989 </p>
4990 <p>A more streamlined notation can be used for lists: the elements of the
4991 list are simply enclosed in parentheses and separated by spaces. The
4992 empty list is written <tt>()</tt> . For example,
4993 <a name="index-empty-list-4"></a>
4994 </p>
4996 <table><tr><td>&nbsp;</td><td><pre class="example">
4997 (a b c d e)
4998 </pre></td></tr></table>
5001 <p>and
5002 </p>
5004 <table><tr><td>&nbsp;</td><td><pre class="example">
5005 (a . (b . (c . (d . (e . ())))))
5006 </pre></td></tr></table>
5009 <p>are equivalent notations for a list of symbols.
5010 </p>
5011 <p>A chain of pairs not ending in the empty list is called an
5012 <em>improper list</em>. Note that an improper list is not a list.
5013 <a name="index-improper-list"></a>
5014 The list and dotted notations can be combined to represent
5015 improper lists:
5016 </p>
5018 <table><tr><td>&nbsp;</td><td><pre class="example">
5019 (a b c . d)
5020 </pre></td></tr></table>
5023 <p>is equivalent to
5024 </p>
5026 <table><tr><td>&nbsp;</td><td><pre class="example">
5027 (a . (b . (c . d)))
5028 </pre></td></tr></table>
5031 <p>Whether a given pair is a list depends upon what is stored in the cdr
5032 field. When the <code>set-cdr!</code> procedure is used, an object can be a
5033 <a name="index-set_002dcdr_0021"></a>
5034 list one moment and not the next:
5035 </p>
5037 <table><tr><td>&nbsp;</td><td><pre class="example">
5038 (define x (list 'a 'b 'c))
5039 (define y x)
5040 y ==&gt; (a b c)
5041 (list? y) ==&gt; #t
5042 (set-cdr! x 4) ==&gt; <em>unspecified</em>
5043 x ==&gt; (a . 4)
5044 (eqv? x y) ==&gt; #t
5045 y ==&gt; (a . 4)
5046 (list? y) ==&gt; #f
5047 (set-cdr! x x) ==&gt; <em>unspecified</em>
5048 (list? x) ==&gt; #f
5049 </pre></td></tr></table>
5054 <p>Within literal expressions and representations of objects read by the
5055 <code>read</code> procedure, the forms <tt>'</tt><span class="roman">&lt;datum&gt;</span>,
5056 <a name="index-_0027-2"></a>
5057 <a name="index-read"></a>
5058 <tt>&lsquo;</tt><span class="roman">&lt;datum&gt;</span>, <tt>,</tt><span class="roman">&lt;datum&gt;</span>, and
5059 <a name="index-_002c-1"></a>
5060 <tt>,@</tt><span class="roman">&lt;datum&gt;</span> denote two-element lists whose first elements are
5061 the symbols <code>quote</code>, <code>quasiquote</code>, <code>unquote</code>, and
5062 <a name="index-unquote-1"></a>
5063 <a name="index-quasiquote-2"></a>
5064 <a name="index-quote-1"></a>
5065 <code>unquote-splicing</code>, respectively. The second element in each case
5066 <a name="index-unquote_002dsplicing-1"></a>
5067 is <span class="roman">&lt;datum&gt;</span>. This convention is supported so that arbitrary Scheme
5068 programs may be represented as lists.
5069 That is, according to Scheme's grammar, every
5070 &lt;expression&gt; is also a &lt;datum&gt; (see section see section <a href="#External-representation">External representations</a>).
5071 Among other things, this permits the use of the <samp>read</samp> procedure to
5072 parse Scheme programs. See section <a href="#External-representations">External representations</a>.
5073 </p>
5076 <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>
5078 <p><samp>Pair?</samp> returns <tt>#t</tt> if <var>obj</var> is a pair, and otherwise
5079 returns <tt>#f</tt>.
5080 </p>
5082 <table><tr><td>&nbsp;</td><td><pre class="format">(pair? '(a . b)) ==&gt; #t
5083 (pair? '(a b c)) ==&gt; #t
5084 (pair? '()) ==&gt; #f
5085 (pair? '#(a b)) ==&gt; #f
5086 </pre></td></tr></table>
5092 <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>
5094 <p>Returns a newly allocated pair whose car is <var>obj1</var> and whose cdr is
5095 <var>obj2</var>. The pair is guaranteed to be different (in the sense of
5096 <samp>eqv?</samp>) from every existing object.
5097 </p>
5099 <table><tr><td>&nbsp;</td><td><pre class="format">(cons 'a '()) ==&gt; (a)
5100 (cons '(a) '(b c d)) ==&gt; ((a) b c d)
5101 (cons &quot;a&quot; '(b c)) ==&gt; (&quot;a&quot; b c)
5102 (cons 'a 3) ==&gt; (a . 3)
5103 (cons '(a b) 'c) ==&gt; ((a b) . c)
5104 </pre></td></tr></table>
5110 <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>
5113 <p>Returns the contents of the car field of <var>pair</var>. Note that it is an
5114 error to take the car of the empty list.
5115 <a name="index-empty-list-5"></a>
5116 </p>
5118 <table><tr><td>&nbsp;</td><td><pre class="format">(car '(a b c)) ==&gt; a
5119 (car '((a) b c d)) ==&gt; (a)
5120 (car '(1 . 2)) ==&gt; 1
5121 (car '()) ==&gt; <em>error</em>
5122 </pre></td></tr></table>
5129 <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>
5132 <p>Returns the contents of the cdr field of <var>pair</var>.
5133 Note that it is an error to take the cdr of the empty list.
5134 </p>
5136 <table><tr><td>&nbsp;</td><td><pre class="format">(cdr '((a) b c d)) ==&gt; (b c d)
5137 (cdr '(1 . 2)) ==&gt; 2
5138 (cdr '()) ==&gt; <em>error</em>
5139 </pre></td></tr></table>
5146 <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>
5149 <p>Stores <var>obj</var> in the car field of <var>pair</var>.
5150 The value returned by <samp>set-car!</samp> is unspecified.
5151 </p>
5153 <table><tr><td>&nbsp;</td><td><pre class="format">(define (f) (list 'not-a-constant-list))
5154 (define (g) '(constant-list))
5155 (set-car! (f) 3) ==&gt; <em>unspecified</em>
5156 (set-car! (g) 3) ==&gt; <em>error</em>
5157 </pre></td></tr></table>
5164 <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>
5167 <p>Stores <var>obj</var> in the cdr field of <var>pair</var>.
5168 The value returned by <samp>set-cdr!</samp> is unspecified.
5169 </p>
5177 <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>
5178 <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>
5179 <table width="100%"><tr><td align="left"> <code><b>&hellip;</b></code></td><td align="right">&hellip;</td></tr></table>
5180 <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>
5181 <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>
5183 <p>These procedures are compositions of <samp>car</samp> and <samp>cdr</samp>, where
5184 for example <samp>caddr</samp> could be defined by
5185 </p>
5187 <table><tr><td>&nbsp;</td><td><pre class="format">(define caddr (lambda (x) (car (cdr (cdr x)))))<span class="roman">.</span>
5188 </pre></td></tr></table>
5191 <p>Arbitrary compositions, up to four deep, are provided. There are
5192 twenty-eight of these procedures in all.
5193 </p>
5198 <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>
5200 <p>Returns <tt>#t</tt> if <var>obj</var> is the empty list,
5201 <a name="index-empty-list-6"></a>
5202 otherwise returns <tt>#f</tt>.
5203 </p>
5208 <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>
5210 <p>Returns <tt>#t</tt> if <var>obj</var> is a list, otherwise returns <tt>#f</tt>.
5211 By definition, all lists have finite length and are terminated by
5212 the empty list.
5213 </p>
5215 <table><tr><td>&nbsp;</td><td><pre class="format"> (list? '(a b c)) ==&gt; #t
5216 (list? '()) ==&gt; #t
5217 (list? '(a . b)) ==&gt; #f
5218 (let ((x (list 'a)))
5219 (set-cdr! x x)
5220 (list? x)) ==&gt; #f
5221 </pre></td></tr></table>
5227 <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>
5229 <p>Returns a newly allocated list of its arguments.
5230 </p>
5232 <table><tr><td>&nbsp;</td><td><pre class="format">(list 'a (+ 3 4) 'c) ==&gt; (a 7 c)
5233 (list) ==&gt; ()
5234 </pre></td></tr></table>
5240 <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>
5243 <p>Returns the length of <var>list</var>.
5244 </p>
5246 <table><tr><td>&nbsp;</td><td><pre class="format">(length '(a b c)) ==&gt; 3
5247 (length '(a (b) (c d e))) ==&gt; 3
5248 (length '()) ==&gt; 0
5249 </pre></td></tr></table>
5255 <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>
5258 <p>Returns a list consisting of the elements of the first <var>list</var>
5259 followed by the elements of the other <var>list</var>s.
5260 </p>
5262 <table><tr><td>&nbsp;</td><td><pre class="format">(append '(x) '(y)) ==&gt; (x y)
5263 (append '(a) '(b c d)) ==&gt; (a b c d)
5264 (append '(a (b)) '((c))) ==&gt; (a (b) (c))
5265 </pre></td></tr></table>
5268 <p>The resulting list is always newly allocated, except that it shares
5269 structure with the last <var>list</var> argument. The last argument may
5270 actually be any object; an improper list results if the last argument is not a
5271 proper list.
5272 </p>
5275 <table><tr><td>&nbsp;</td><td><pre class="format">(append '(a b) '(c . d)) ==&gt; (a b c . d)
5276 (append '() 'a) ==&gt; a
5277 </pre></td></tr></table>
5283 <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>
5286 <p>Returns a newly allocated list consisting of the elements of <var>list</var>
5287 in reverse order.
5288 </p>
5290 <table><tr><td>&nbsp;</td><td><pre class="format">(reverse '(a b c)) ==&gt; (c b a)
5291 (reverse '(a (b c) d (e (f))))
5292 ==&gt; ((e (f)) d (b c) a)
5293 </pre></td></tr></table>
5299 <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>
5301 <p>Returns the sublist of <var>list</var> obtained by omitting the first <var>k</var>
5302 elements. It is an error if <var>list</var> has fewer than <var>k</var> elements.
5303 <samp>List-tail</samp> could be defined by
5304 </p>
5306 <table><tr><td>&nbsp;</td><td><pre class="format">(define list-tail
5307 (lambda (x k)
5308 (if (zero? k)
5310 (list-tail (cdr x) (- k 1)))))
5311 </pre></td></tr></table>
5317 <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>
5319 <p>Returns the <var>k</var>th element of <var>list</var>. (This is the same
5320 as the car of <tt>(list-tail <var>list</var> <var>k</var>)</tt>.)
5321 It is an error if <var>list</var> has fewer than <var>k</var> elements.
5322 </p>
5324 <table><tr><td>&nbsp;</td><td><pre class="format">(list-ref '(a b c d) 2) ==&gt; c
5325 (list-ref '(a b c d)
5326 (inexact-&gt;exact (round 1.8)))
5327 ==&gt; c
5328 </pre></td></tr></table>
5339 <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>
5340 <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>
5341 <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>
5343 <p>These procedures return the first sublist of <var>list</var> whose car is
5344 <var>obj</var>, where the sublists of <var>list</var> are the non-empty lists
5345 returned by <tt>(list-tail <var>list</var> <var>k</var>)</tt> for <var>k</var> less
5346 than the length of <var>list</var>. If
5347 <var>obj</var> does not occur in <var>list</var>, then <tt>#f</tt> (not the empty list) is
5348 returned. <samp>Memq</samp> uses <samp>eq?</samp> to compare <var>obj</var> with the elements of
5349 <var>list</var>, while <samp>memv</samp> uses <samp>eqv?</samp> and <samp>member</samp> uses <samp>equal?</samp>.
5350 </p>
5352 <table><tr><td>&nbsp;</td><td><pre class="format">(memq 'a '(a b c)) ==&gt; (a b c)
5353 (memq 'b '(a b c)) ==&gt; (b c)
5354 (memq 'a '(b c d)) ==&gt; #f
5355 (memq (list 'a) '(b (a) c)) ==&gt; #f
5356 (member (list 'a)
5357 '(b (a) c)) ==&gt; ((a) c)
5358 (memq 101 '(100 101 102)) ==&gt; <em>unspecified</em>
5359 (memv 101 '(100 101 102)) ==&gt; (101 102)
5360 </pre></td></tr></table>
5367 <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>
5368 <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>
5369 <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>
5371 <p><var>Alist</var> (for &ldquo;association list&rdquo;) must be a list of
5372 pairs. These procedures find the first pair in <var>alist</var> whose car field is <var>obj</var>,
5373 and returns that pair. If no pair in <var>alist</var> has <var>obj</var> as its
5374 car, then <tt>#f</tt> (not the empty list) is returned. <samp>Assq</samp> uses
5375 <samp>eq?</samp> to compare <var>obj</var> with the car fields of the pairs in <var>alist</var>,
5376 while <samp>assv</samp> uses <samp>eqv?</samp> and <samp>assoc</samp> uses <samp>equal?</samp>.
5377 </p>
5379 <table><tr><td>&nbsp;</td><td><pre class="format">(define e '((a 1) (b 2) (c 3)))
5380 (assq 'a e) ==&gt; (a 1)
5381 (assq 'b e) ==&gt; (b 2)
5382 (assq 'd e) ==&gt; #f
5383 (assq (list 'a) '(((a)) ((b)) ((c))))
5384 ==&gt; #f
5385 (assoc (list 'a) '(((a)) ((b)) ((c))))
5386 ==&gt; ((a))
5387 (assq 5 '((2 3) (5 7) (11 13)))
5388 ==&gt; <em>unspecified</em>
5389 (assv 5 '((2 3) (5 7) (11 13)))
5390 ==&gt; (5 7)
5391 </pre></td></tr></table>
5396 <blockquote><p><em>Rationale:</em>
5397 Although they are ordinarily used as predicates,
5398 <samp>memq</samp>, <samp>memv</samp>, <samp>member</samp>, <samp>assq</samp>, <samp>assv</samp>, and <samp>assoc</samp> do not
5399 have question marks in their names because they return useful values rather
5400 than just <tt>#t</tt> or <tt>#f</tt>.
5401 </p></blockquote>
5406 <hr size="1">
5407 <a name="Symbols"></a>
5408 <table cellpadding="1" cellspacing="1" border="0">
5409 <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>
5410 <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>
5411 <td valign="middle" align="left"> &nbsp; </td>
5412 <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>
5413 <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>
5414 <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>
5415 <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>
5416 <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>
5417 <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>
5418 </tr></table>
5419 <a name="Symbols-1"></a>
5420 <h3 class="subsection">6.3.3 Symbols</h3>
5424 <p>Symbols are objects whose usefulness rests on the fact that two
5425 symbols are identical (in the sense of <samp>eqv?</samp>) if and only if their
5426 names are spelled the same way. This is exactly the property needed to
5427 represent identifiers in programs, and so most
5428 <a name="index-identifier-2"></a>
5429 implementations of Scheme use them internally for that purpose. Symbols
5430 are useful for many other applications; for instance, they may be used
5431 the way enumerated values are used in Pascal.
5432 </p>
5433 <p>The rules for writing a symbol are exactly the same as the rules for
5434 writing an identifier; see sections <a href="#Identifiers">Identifiers</a>
5435 and <a href="#Lexical-structure">Lexical structure</a>.
5436 </p>
5437 <p>It is guaranteed that any symbol that has been returned as part of
5438 a literal expression, or read using the <samp>read</samp> procedure, and
5439 subsequently written out using the <samp>write</samp> procedure, will read back
5440 in as the identical symbol (in the sense of <samp>eqv?</samp>). The
5441 <samp>string-&gt;symbol</samp> procedure, however, can create symbols for
5442 which this write/read invariance may not hold because their names
5443 contain special characters or letters in the non-standard case.
5444 </p>
5446 <blockquote><p><em>Note:</em>
5447 Some implementations of Scheme have a feature known as &ldquo;slashification&rdquo;
5448 in order to guarantee write/read invariance for all symbols, but
5449 historically the most important use of this feature has been to
5450 compensate for the lack of a string data type.
5451 </p>
5452 <p>Some implementations also have &ldquo;uninterned symbols&rdquo;, which
5453 defeat write/read invariance even in implementations with slashification,
5454 and also generate exceptions to the rule that two symbols are the same
5455 if and only if their names are spelled the same.
5456 </p></blockquote>
5461 <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>
5463 <p>Returns <tt>#t</tt> if <var>obj</var> is a symbol, otherwise returns <tt>#f</tt>.
5464 </p>
5466 <table><tr><td>&nbsp;</td><td><pre class="format">(symbol? 'foo) ==&gt; #t
5467 (symbol? (car '(a b))) ==&gt; #t
5468 (symbol? &quot;bar&quot;) ==&gt; #f
5469 (symbol? 'nil) ==&gt; #t
5470 (symbol? '()) ==&gt; #f
5471 (symbol? #f) ==&gt; #f
5472 </pre></td></tr></table>
5478 <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>
5480 <p>Returns the name of <var>symbol</var> as a string. If the symbol was part of
5481 an object returned as the value of a literal expression
5482 (section see section <a href="#Literal-expressions">Literal expressions</a>) or by a call to the <samp>read</samp> procedure,
5483 and its name contains alphabetic characters, then the string returned
5484 will contain characters in the implementation's preferred standard
5485 case&mdash;some implementations will prefer upper case, others lower case.
5486 If the symbol was returned by <samp>string-&gt;symbol</samp>, the case of
5487 characters in the string returned will be the same as the case in the
5488 string that was passed to <samp>string-&gt;symbol</samp>. It is an error
5489 to apply mutation procedures like <code>string-set!</code> to strings returned
5490 <a name="index-string_002dset_0021"></a>
5491 by this procedure.
5492 </p>
5493 <p>The following examples assume that the implementation's standard case is
5494 lower case:
5495 </p>
5497 <table><tr><td>&nbsp;</td><td><pre class="format">(symbol-&gt;string 'flying-fish)
5498 ==&gt; &quot;flying-fish&quot;
5499 (symbol-&gt;string 'Martin) ==&gt; &quot;martin&quot;
5500 (symbol-&gt;string
5501 (string-&gt;symbol &quot;Malvina&quot;))
5502 ==&gt; &quot;Malvina&quot;
5503 </pre></td></tr></table>
5509 <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>
5511 <p>Returns the symbol whose name is <var>string</var>. This procedure can
5512 create symbols with names containing special characters or letters in
5513 the non-standard case, but it is usually a bad idea to create such
5514 symbols because in some implementations of Scheme they cannot be read as
5515 themselves. See <samp>symbol-&gt;string</samp>.
5516 </p>
5517 <p>The following examples assume that the implementation's standard case is
5518 lower case:
5519 </p>
5521 <table><tr><td>&nbsp;</td><td><pre class="format">(eq? 'mISSISSIppi 'mississippi)
5522 ==&gt; #t
5523 (string-&gt;symbol &quot;mISSISSIppi&quot;)
5524 ==&gt;
5525 <span class="roman"></span>the symbol with name &quot;mISSISSIppi&quot;
5526 (eq? 'bitBlt (string-&gt;symbol &quot;bitBlt&quot;))
5527 ==&gt; #f
5528 (eq? 'JollyWog
5529 (string-&gt;symbol
5530 (symbol-&gt;string 'JollyWog)))
5531 ==&gt; #t
5532 (string=? &quot;K. Harper, M.D.&quot;
5533 (symbol-&gt;string
5534 (string-&gt;symbol &quot;K. Harper, M.D.&quot;)))
5535 ==&gt; #t
5536 </pre></td></tr></table>
5542 <hr size="1">
5543 <a name="Characters"></a>
5544 <table cellpadding="1" cellspacing="1" border="0">
5545 <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>
5546 <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>
5547 <td valign="middle" align="left"> &nbsp; </td>
5548 <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>
5549 <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>
5550 <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>
5551 <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>
5552 <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>
5553 <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>
5554 </tr></table>
5555 <a name="Characters-1"></a>
5556 <h3 class="subsection">6.3.4 Characters</h3>
5560 <p>Characters are objects that represent printed characters such as
5561 letters and digits.
5562 Characters are written using the notation #\<span class="roman">&lt;character&gt;</span>
5563 or #\<span class="roman">&lt;character name&gt;</span>.
5564 For example:
5565 </p>
5568 <blockquote><dl compact="compact">
5569 <dt> <tt>#\a</tt></dt>
5570 </dl>
5571 </blockquote>
5572 <p>; lower case letter
5573 </p> <tt>#\A</tt>
5574 <p>; upper case letter
5575 </p> <tt>#\(</tt>
5576 <p>; left parenthesis
5577 </p> <tt>#\ </tt>
5578 <p>; the space character
5579 </p> <tt>#\space</tt>
5580 <p>; the preferred way to write a space
5581 </p> <tt>#\newline</tt>
5582 <p>; the newline character
5583 </p>
5588 <p>Case is significant in #\<span class="roman">&lt;character&gt;</span>, but not in
5589 #\<span class="roman">&lt;character name&gt;</span>.
5590 </p>
5591 <p>If <span class="roman">&lt;character&gt;</span> in
5592 #\<span class="roman">&lt;character&gt;</span> is alphabetic, then the character
5593 following <span class="roman">&lt;character&gt;</span> must be a delimiter character such as a
5594 space or parenthesis. This rule resolves the ambiguous case where, for
5595 example, the sequence of characters &ldquo;<tt>#\ space</tt>&rdquo;
5596 could be taken to be either a representation of the space character or a
5597 representation of the character &ldquo;<tt>#\ s</tt>&rdquo; followed
5598 by a representation of the symbol &ldquo;<tt>pace</tt>.&rdquo;
5599 </p>
5601 <p>Characters written in the #\ notation are self-evaluating.
5602 That is, they do not have to be quoted in programs.
5603 </p>
5604 <p>Some of the procedures that operate on characters ignore the
5605 difference between upper case and lower case. The procedures that
5606 ignore case have &ldquo;<tt>-ci</tt>&rdquo; (for &ldquo;case
5607 insensitive&rdquo;) embedded in their names.
5608 </p>
5611 <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>
5613 <p>Returns <tt>#t</tt> if <var>obj</var> is a character, otherwise returns <tt>#f</tt>.
5614 </p>
5619 <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>
5620 <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>
5621 <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>
5622 <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>
5623 <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>
5627 <p>These procedures impose a total ordering on the set of characters. It
5628 is guaranteed that under this ordering:
5629 </p>
5632 <ul>
5633 <li>
5634 The upper case characters are in order. For example, <samp>(char&lt;? #\A #\B)</samp> returns <tt>#t</tt>.
5635 </li><li>
5636 The lower case characters are in order. For example, <samp>(char&lt;? #\a #\b)</samp> returns <tt>#t</tt>.
5637 </li><li>
5638 The digits are in order. For example, <samp>(char&lt;? #\0 #\9)</samp> returns <tt>#t</tt>.
5639 </li><li>
5640 Either all the digits precede all the upper case letters, or vice versa.
5641 </li><li>
5642 Either all the digits precede all the lower case letters, or vice versa.
5644 </li></ul>
5647 <p>Some implementations may generalize these procedures to take more than
5648 two arguments, as with the corresponding numerical predicates.
5649 </p>
5654 <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>
5655 <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>
5656 <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>
5657 <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>
5658 <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>
5661 <p>These procedures are similar to <samp>char=?</samp> et cetera, but they treat
5662 upper case and lower case letters as the same. For example, <samp>(char-ci=? #\A #\a)</samp> returns <tt>#t</tt>. Some
5663 implementations may generalize these procedures to take more than two
5664 arguments, as with the corresponding numerical predicates.
5665 </p>
5670 <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>
5671 <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>
5672 <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>
5673 <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>
5674 <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>
5676 <p>These procedures return <tt>#t</tt> if their arguments are alphabetic,
5677 numeric, whitespace, upper case, or lower case characters, respectively,
5678 otherwise they return <tt>#f</tt>. The following remarks, which are specific to
5679 the ASCII character set, are intended only as a guide: The alphabetic characters
5680 are the 52 upper and lower case letters. The numeric characters are the
5681 ten decimal digits. The whitespace characters are space, tab, line
5682 feed, form feed, and carriage return.
5683 </p>
5690 <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>
5691 <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>
5693 <p>Given a character, <samp>char-&gt;integer</samp> returns an exact integer
5694 representation of the character. Given an exact integer that is the image of
5695 a character under <samp>char-&gt;integer</samp>, <samp>integer-&gt;char</samp>
5696 returns that character. These procedures implement order-preserving isomorphisms
5697 between the set of characters under the <code>char&lt;=?</code> ordering and some
5698 <a name="index-char_003c_003d_003f-1"></a>
5699 subset of the integers under the <samp>&lt;=</samp> ordering. That is, if
5700 </p>
5702 <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
5703 </pre></td></tr></table>
5707 <p> and <var>x</var> and <var>y</var> are in the domain of
5708 <samp>integer-&gt;char</samp>, then
5709 </p>
5711 <table><tr><td>&nbsp;</td><td><pre class="format">(&lt;= (char-&gt;integer <var>a</var>)
5712 (char-&gt;integer <var>b</var>)) ==&gt; #t
5714 (char&lt;=? (integer-&gt;char <var>x</var>)
5715 (integer-&gt;char <var>y</var>)) ==&gt; #t
5716 </pre></td></tr></table>
5723 <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>
5724 <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>
5727 <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
5728 alphabetic, then the result of <samp>char-upcase</samp> is upper case and the
5729 result of <samp>char-downcase</samp> is lower case.
5730 </p>
5734 <hr size="1">
5735 <a name="Strings"></a>
5736 <table cellpadding="1" cellspacing="1" border="0">
5737 <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>
5738 <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>
5739 <td valign="middle" align="left"> &nbsp; </td>
5740 <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>
5741 <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>
5742 <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>
5743 <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>
5744 <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>
5745 <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>
5746 </tr></table>
5747 <a name="Strings-1"></a>
5748 <h3 class="subsection">6.3.5 Strings</h3>
5752 <p>Strings are sequences of characters.
5753 Strings are written as sequences of characters enclosed within doublequotes
5754 (<samp>&quot;</samp>). A doublequote can be written inside a string only by escaping
5755 it with a backslash (\), as in
5756 </p>
5758 <table><tr><td>&nbsp;</td><td><pre class="example">
5759 &quot;The word \&quot;recursion\&quot; has many meanings.&quot;
5760 </pre></td></tr></table>
5763 <p>A backslash can be written inside a string only by escaping it with another
5764 backslash. Scheme does not specify the effect of a backslash within a
5765 string that is not followed by a doublequote or backslash.
5766 </p>
5767 <p>A string constant may continue from one line to the next, but
5768 the exact contents of such a string are unspecified.
5769 </p>
5770 <p>The <em>length</em> of a string is the number of characters that it
5771 contains. This number is an exact, non-negative integer that is fixed when the
5772 string is created. The <em>valid indexes</em> of a string are the
5773 <a name="index-valid-indexes"></a>
5774 exact non-negative integers less than the length of the string. The first
5775 character of a string has index 0, the second has index 1, and so on.
5776 </p>
5777 <p>In phrases such as &ldquo;the characters of <var>string</var> beginning with
5778 index <var>start</var> and ending with index <var>end</var>,&rdquo; it is understood
5779 that the index <var>start</var> is inclusive and the index <var>end</var> is
5780 exclusive. Thus if <var>start</var> and <var>end</var> are the same index, a null
5781 substring is referred to, and if <var>start</var> is zero and <var>end</var> is
5782 the length of <var>string</var>, then the entire string is referred to.
5783 </p>
5784 <p>Some of the procedures that operate on strings ignore the
5785 difference between upper and lower case. The versions that ignore case
5786 have &ldquo;<samp>-ci</samp>&rdquo; (for &ldquo;case insensitive&rdquo;) embedded in their
5787 names.
5788 </p>
5791 <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>
5793 <p>Returns <tt>#t</tt> if <var>obj</var> is a string, otherwise returns <tt>#f</tt>.
5794 </p>
5798 <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>
5799 <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>
5801 <p><samp>Make-string</samp> returns a newly allocated string of
5802 length <var>k</var>. If <var>char</var> is given, then all elements of the string
5803 are initialized to <var>char</var>, otherwise the contents of the
5804 <var>string</var> are unspecified.
5805 </p>
5809 <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>
5811 <p>Returns a newly allocated string composed of the arguments.
5812 </p>
5816 <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>
5818 <p>Returns the number of characters in the given <var>string</var>.
5819 </p>
5823 <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>
5825 <p><var>k</var> must be a valid index of <var>string</var>.
5826 <samp>String-ref</samp> returns character <var>k</var> of <var>string</var> using zero-origin indexing.
5827 </p>
5831 <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>
5834 <p><var>k</var> must be a valid index of <var>string</var>
5836 <samp>String-set!</samp> stores <var>char</var> in element <var>k</var> of <var>string</var>
5837 and returns an unspecified value.
5838 </p>
5840 <table><tr><td>&nbsp;</td><td><pre class="format">(define (f) (make-string 3 #\*))
5841 (define (g) &quot;***&quot;)
5842 (string-set! (f) 0 #\?) ==&gt; <em>unspecified</em>
5843 (string-set! (g) 0 #\?) ==&gt; <em>error</em>
5844 (string-set! (symbol-&gt;string 'immutable)
5846 #\?) ==&gt; <em>error</em>
5847 </pre></td></tr></table>
5854 <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>
5855 <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>
5857 <p>Returns <tt>#t</tt> if the two strings are the same length and contain the same
5858 characters in the same positions, otherwise returns <tt>#f</tt>.
5859 <samp>String-ci=?</samp> treats
5860 upper and lower case letters as though they were the same character, but
5861 <samp>string=?</samp> treats upper and lower case as distinct characters.
5862 </p>
5867 <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>
5868 <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>
5869 <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>
5870 <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>
5871 <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>
5872 <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>
5873 <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>
5874 <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>
5876 <p>These procedures are the lexicographic extensions to strings of the
5877 corresponding orderings on characters. For example, <samp>string&lt;?</samp> is
5878 the lexicographic ordering on strings induced by the ordering
5879 <samp>char&lt;?</samp> on characters. If two strings differ in length but
5880 are the same up to the length of the shorter string, the shorter string
5881 is considered to be lexicographically less than the longer string.
5882 </p>
5883 <p>Implementations may generalize these and the <samp>string=?</samp> and
5884 <samp>string-ci=?</samp> procedures to take more than two arguments, as with
5885 the corresponding numerical predicates.
5886 </p>
5891 <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>
5893 <p><var>String</var> must be a string, and <var>start</var> and <var>end</var>
5894 must be exact integers satisfying
5895 </p>
5897 <p align="center"> 0 &lt;= <var>start</var> &lt;= <var>end</var> &lt;= <tt>(string-length <var>string</var>)<span class="roman">.</span></tt>
5898 </p>
5899 <p><samp>Substring</samp> returns a newly allocated string formed from the characters of
5900 <var>string</var> beginning with index <var>start</var> (inclusive) and ending with index
5901 <var>end</var> (exclusive).
5902 </p>
5906 <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>
5908 <p>Returns a newly allocated string whose characters form the concatenation of the
5909 given strings.
5910 </p>
5915 <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>
5916 <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>
5918 <p><samp>String-&gt;list</samp> returns a newly allocated list of the
5919 characters that make up the given string. <samp>List-&gt;string</samp>
5920 returns a newly allocated string formed from the characters in the list
5921 <var>list</var>, which must be a list of characters. <samp>String-&gt;list</samp>
5922 and <samp>list-&gt;string</samp> are
5923 inverses so far as <samp>equal?</samp> is concerned.
5924 </p>
5929 <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>
5931 <p>Returns a newly allocated copy of the given <var>string</var>.
5932 </p>
5937 <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>
5939 <p>Stores <var>char</var> in every element of the given <var>string</var> and returns an
5940 unspecified value.
5941 </p>
5945 <hr size="1">
5946 <a name="Vectors"></a>
5947 <table cellpadding="1" cellspacing="1" border="0">
5948 <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>
5949 <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>
5950 <td valign="middle" align="left"> &nbsp; </td>
5951 <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>
5952 <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>
5953 <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>
5954 <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>
5955 <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>
5956 <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>
5957 </tr></table>
5958 <a name="Vectors-1"></a>
5959 <h3 class="subsection">6.3.6 Vectors</h3>
5963 <p>Vectors are heterogeneous structures whose elements are indexed
5964 by integers. A vector typically occupies less space than a list
5965 of the same length, and the average time required to access a randomly
5966 chosen element is typically less for the vector than for the list.
5967 </p>
5968 <p>The <em>length</em> of a vector is the number of elements that it
5969 contains. This number is a non-negative integer that is fixed when the
5970 vector is created. The <em>valid indexes</em> of a
5971 <a name="index-valid-indexes-1"></a>
5972 vector are the exact non-negative integers less than the length of the
5973 vector. The first element in a vector is indexed by zero, and the last
5974 element is indexed by one less than the length of the vector.
5975 </p>
5976 <p>Vectors are written using the notation <tt>#(<var>obj</var> &hellip;)</tt>.
5977 For example, a vector of length 3 containing the number zero in element
5978 0, the list <samp>(2 2 2 2)</samp> in element 1, and the string <samp>&quot;Anna&quot;</samp> in
5979 element 2 can be written as following:
5980 </p>
5982 <table><tr><td>&nbsp;</td><td><pre class="example">
5983 #(0 (2 2 2 2) &quot;Anna&quot;)
5984 </pre></td></tr></table>
5987 <p>Note that this is the external representation of a vector, not an
5988 expression evaluating to a vector. Like list constants, vector
5989 constants must be quoted:
5990 </p>
5992 <table><tr><td>&nbsp;</td><td><pre class="example">
5993 '#(0 (2 2 2 2) &quot;Anna&quot;)
5994 ==&gt; #(0 (2 2 2 2) &quot;Anna&quot;)
5996 </pre></td></tr></table>
6003 <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>
6005 <p>Returns <tt>#t</tt> if <var>obj</var> is a vector, otherwise returns <tt>#f</tt>.
6006 </p>
6010 <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>
6011 <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>
6013 <p>Returns a newly allocated vector of <var>k</var> elements. If a second
6014 argument is given, then each element is initialized to <var>fill</var>.
6015 Otherwise the initial contents of each element is unspecified.
6016 </p>
6021 <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>
6023 <p>Returns a newly allocated vector whose elements contain the given
6024 arguments. Analogous to <samp>list</samp>.
6025 </p>
6027 <table><tr><td>&nbsp;</td><td><pre class="format">(vector 'a 'b 'c) ==&gt; #(a b c)
6028 </pre></td></tr></table>
6034 <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>
6036 <p>Returns the number of elements in <var>vector</var> as an exact integer.
6037 </p>
6041 <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>
6043 <p><var>k</var> must be a valid index of <var>vector</var>.
6044 <samp>Vector-ref</samp> returns the contents of element <var>k</var> of
6045 <var>vector</var>.
6046 </p>
6048 <table><tr><td>&nbsp;</td><td><pre class="format">(vector-ref '#(1 1 2 3 5 8 13 21)
6050 ==&gt; 8
6051 (vector-ref '#(1 1 2 3 5 8 13 21)
6052 (let ((i (round (* 2 (acos -1)))))
6053 (if (inexact? i)
6054 (inexact-&gt;exact i)
6055 i)))
6056 ==&gt; 13
6057 </pre></td></tr></table>
6063 <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>
6065 <p><var>k</var> must be a valid index of <var>vector</var>.
6066 <samp>Vector-set!</samp> stores <var>obj</var> in element <var>k</var> of <var>vector</var>.
6067 The value returned by <samp>vector-set!</samp> is unspecified.
6068 </p>
6070 <table><tr><td>&nbsp;</td><td><pre class="format">(let ((vec (vector 0 '(2 2 2 2) &quot;Anna&quot;)))
6071 (vector-set! vec 1 '(&quot;Sue&quot; &quot;Sue&quot;))
6072 vec)
6073 ==&gt; #(0 (&quot;Sue&quot; &quot;Sue&quot;) &quot;Anna&quot;)
6075 (vector-set! '#(0 1 2) 1 &quot;doe&quot;)
6076 ==&gt; <em>error</em> ; constant vector
6077 </pre></td></tr></table>
6083 <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>
6084 <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>
6086 <p><samp>Vector-&gt;list</samp> returns a newly allocated list of the objects contained
6087 in the elements of <var>vector</var>. <samp>List-&gt;vector</samp> returns a newly
6088 created vector initialized to the elements of the list <var>list</var>.
6089 </p>
6091 <table><tr><td>&nbsp;</td><td><pre class="format">(vector-&gt;list '#(dah dah didah))
6092 ==&gt; (dah dah didah)
6093 (list-&gt;vector '(dididit dah))
6094 ==&gt; #(dididit dah)
6095 </pre></td></tr></table>
6101 <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>
6103 <p>Stores <var>fill</var> in every element of <var>vector</var>.
6104 The value returned by <samp>vector-fill!</samp> is unspecified.
6105 </p>
6109 <hr size="1">
6110 <a name="Control-features"></a>
6111 <table cellpadding="1" cellspacing="1" border="0">
6112 <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>
6113 <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>
6114 <td valign="middle" align="left"> &nbsp; </td>
6115 <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>
6116 <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>
6117 <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>
6118 <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>
6119 <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>
6120 <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>
6121 </tr></table>
6122 <a name="Control-features-1"></a>
6123 <h2 class="section">6.4 Control features</h2>
6128 <p>This chapter describes various primitive procedures which control the
6129 flow of program execution in special ways.
6130 The <samp>procedure?</samp> predicate is also described here.
6131 </p>
6135 <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>
6137 <p>Returns <tt>#t</tt> if <var>obj</var> is a procedure, otherwise returns <tt>#f</tt>.
6138 </p>
6140 <table><tr><td>&nbsp;</td><td><pre class="format">(procedure? car) ==&gt; #t
6141 (procedure? 'car) ==&gt; #f
6142 (procedure? (lambda (x) (* x x)))
6143 ==&gt; #t
6144 (procedure? '(lambda (x) (* x x)))
6145 ==&gt; #f
6146 (call-with-current-continuation procedure?)
6147 ==&gt; #t
6148 </pre></td></tr></table>
6155 <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>
6157 <p><var>Proc</var> must be a procedure and <var>args</var> must be a list.
6158 Calls <var>proc</var> with the elements of the list
6159 <samp>(append (list <var>arg1</var> &hellip;) <var>args</var>)</samp> as the actual
6160 arguments.
6161 </p>
6163 <table><tr><td>&nbsp;</td><td><pre class="format">(apply + (list 3 4)) ==&gt; 7
6165 (define compose
6166 (lambda (f g)
6167 (lambda args
6168 (f (apply g args)))))
6170 ((compose sqrt *) 12 75) ==&gt; 30
6171 </pre></td></tr></table>
6177 <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>
6179 <p>The <var>list</var>s must be lists, and <var>proc</var> must be a
6180 procedure taking as many arguments as there are <i>list</i>s
6181 and returning a single value. If more
6182 than one <var>list</var> is given, then they must all be the same length.
6183 <samp>Map</samp> applies <var>proc</var> element-wise to the elements of the
6184 <var>list</var>s and returns a list of the results, in order.
6185 The dynamic order in which <var>proc</var> is applied to the elements of the
6186 <var>list</var>s is unspecified.
6187 </p>
6189 <table><tr><td>&nbsp;</td><td><pre class="format">(map cadr '((a b) (d e) (g h)))
6190 ==&gt; (b e h)
6192 (map (lambda (n) (expt n n))
6193 '(1 2 3 4 5))
6194 ==&gt; (1 4 27 256 3125)
6196 (map + '(1 2 3) '(4 5 6)) ==&gt; (5 7 9)
6198 (let ((count 0))
6199 (map (lambda (ignored)
6200 (set! count (+ count 1))
6201 count)
6202 '(a b))) ==&gt; (1 2) <var>or</var> (2 1)
6203 </pre></td></tr></table>
6210 <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>
6212 <p>The arguments to <samp>for-each</samp> are like the arguments to <samp>map</samp>, but
6213 <samp>for-each</samp> calls <var>proc</var> for its side effects rather than for its
6214 values. Unlike <samp>map</samp>, <samp>for-each</samp> is guaranteed to call <var>proc</var> on
6215 the elements of the <var>list</var>s in order from the first element(s) to the
6216 last, and the value returned by <samp>for-each</samp> is unspecified.
6217 </p>
6219 <table><tr><td>&nbsp;</td><td><pre class="format">(let ((v (make-vector 5)))
6220 (for-each (lambda (i)
6221 (vector-set! v i (* i i)))
6222 '(0 1 2 3 4))
6223 v) ==&gt; #(0 1 4 9 16)
6224 </pre></td></tr></table>
6231 <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>
6233 <p>Forces the value of <var>promise</var> (see <code>delay</code>,
6234 <a name="index-delay-1"></a>
6235 section see section <a href="#Delayed-evaluation">Delayed evaluation</a>). If no value has been computed for
6236 <a name="index-promise-1"></a>
6237 the promise, then a value is computed and returned. The value of the
6238 promise is cached (or &ldquo;memoized&rdquo;) so that if it is forced a second
6239 time, the previously computed value is returned.
6240 </p>
6242 <table><tr><td>&nbsp;</td><td><pre class="format">(force (delay (+ 1 2))) ==&gt; 3
6243 (let ((p (delay (+ 1 2))))
6244 (list (force p) (force p)))
6245 ==&gt; (3 3)
6247 (define a-stream
6248 (letrec ((next
6249 (lambda (n)
6250 (cons n (delay (next (+ n 1)))))))
6251 (next 0)))
6252 (define head car)
6253 (define tail
6254 (lambda (stream) (force (cdr stream))))
6256 (head (tail (tail a-stream)))
6257 ==&gt; 2
6258 </pre></td></tr></table>
6261 <p><samp>Force</samp> and <samp>delay</samp> are mainly intended for programs written in
6262 functional style. The following examples should not be considered to
6263 illustrate good programming style, but they illustrate the property that
6264 only one value is computed for a promise, no matter how many times it is
6265 forced.
6266 </p>
6268 <table><tr><td>&nbsp;</td><td><pre class="format">(define count 0)
6269 (define p
6270 (delay (begin (set! count (+ count 1))
6271 (if (&gt; count x)
6272 count
6273 (force p)))))
6274 (define x 5)
6275 p ==&gt; <i></i>a promise
6276 (force p) ==&gt; 6
6277 p ==&gt; <i></i>a promise, still
6278 (begin (set! x 10)
6279 (force p)) ==&gt; 6
6280 </pre></td></tr></table>
6283 <p>Here is a possible implementation of <samp>delay</samp> and <samp>force</samp>.
6284 Promises are implemented here as procedures of no arguments,
6285 and <samp>force</samp> simply calls its argument:
6286 </p>
6288 <table><tr><td>&nbsp;</td><td><pre class="format">(define force
6289 (lambda (object)
6290 (object)))
6291 </pre></td></tr></table>
6294 <p>We define the expression
6295 </p>
6297 <table><tr><td>&nbsp;</td><td><pre class="format">(delay <span class="roman">&lt;expression&gt;</span>)
6298 </pre></td></tr></table>
6301 <p>to have the same meaning as the procedure call
6302 </p>
6304 <table><tr><td>&nbsp;</td><td><pre class="format">(make-promise (lambda () <span class="roman">&lt;expression&gt;</span>))<span class="roman"></span>
6305 </pre></td></tr></table>
6308 <p>as follows
6309 </p>
6311 <table><tr><td>&nbsp;</td><td><pre class="format">(define-syntax delay
6312 (syntax-rules ()
6313 ((delay expression)
6314 (make-promise (lambda () expression))))),
6315 </pre></td></tr></table>
6318 <p>where <samp>make-promise</samp> is defined as follows:
6319 </p>
6322 <table><tr><td>&nbsp;</td><td><pre class="format">(define make-promise
6323 (lambda (proc)
6324 (let ((result-ready? #f)
6325 (result #f))
6326 (lambda ()
6327 (if result-ready?
6328 result
6329 (let ((x (proc)))
6330 (if result-ready?
6331 result
6332 (begin (set! result-ready? #t)
6333 (set! result x)
6334 result))))))))
6335 </pre></td></tr></table>
6339 <blockquote><p><em>Rationale:</em>
6340 A promise may refer to its own value, as in the last example above.
6341 Forcing such a promise may cause the promise to be forced a second time
6342 before the value of the first force has been computed.
6343 This complicates the definition of <samp>make-promise</samp>.
6344 </p></blockquote>
6347 <p>Various extensions to this semantics of <samp>delay</samp> and <samp>force</samp>
6348 are supported in some implementations:
6349 </p>
6352 <ul>
6353 <li>
6354 Calling <samp>force</samp> on an object that is not a promise may simply
6355 return the object.
6357 </li><li>
6358 It may be the case that there is no means by which a promise can be
6359 operationally distinguished from its forced value. That is, expressions
6360 like the following may evaluate to either <tt>#t</tt> or to <tt>#f</tt>,
6361 depending on the implementation:
6364 <table><tr><td>&nbsp;</td><td><pre class="format">(eqv? (delay 1) 1) ==&gt; <em>unspecified</em>
6365 (pair? (delay (cons 1 2))) ==&gt; <em>unspecified</em>
6366 </pre></td></tr></table>
6369 </li><li>
6370 Some implementations may implement &ldquo;implicit forcing,&rdquo; where
6371 the value of a promise is forced by primitive procedures like <samp>cdr</samp>
6372 and <samp>+</samp>:
6375 <table><tr><td>&nbsp;</td><td><pre class="format">(+ (delay (* 3 7)) 13) ==&gt; 34
6376 </pre></td></tr></table>
6379 </li></ul>
6384 <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>
6386 <p> <var>Proc</var> must be a procedure of one
6387 argument. The procedure <samp>call-with-current-continuation</samp> packages
6388 up the current continuation (see the rationale below) as an &ldquo;escape
6389 procedure&rdquo; and passes it as an argument to
6390 <a name="index-escape-procedure"></a>
6391 <var>proc</var>. The escape procedure is a Scheme procedure that, if it is
6392 later called, will abandon whatever continuation is in effect at that later
6393 time and will instead use the continuation that was in effect
6394 when the escape procedure was created. Calling the escape procedure
6395 may cause the invocation of <var>before</var> and <var>after</var> thunks installed using
6396 <code>dynamic-wind</code>.
6397 <a name="index-dynamic_002dwind"></a>
6398 </p>
6399 <p>The escape procedure accepts the same number of arguments as the continuation to
6400 the original call to <tt>call-with-current-continuation</tt>.
6401 Except for continuations created by the <samp>call-with-values</samp>
6402 procedure, all continuations take exactly one value. The
6403 effect of passing no value or more than one value to continuations
6404 that were not created by <tt>call-with-values</tt> is unspecified.
6405 </p>
6406 <p>The escape procedure that is passed to <var>proc</var> has
6407 unlimited extent just like any other procedure in Scheme. It may be stored
6408 in variables or data structures and may be called as many times as desired.
6409 </p>
6410 <p>The following examples show only the most common ways in which
6411 <samp>call-with-current-continuation</samp> is used. If all real uses were as
6412 simple as these examples, there would be no need for a procedure with
6413 the power of <samp>call-with-current-continuation</samp>.
6414 </p>
6416 <table><tr><td>&nbsp;</td><td><pre class="format">(call-with-current-continuation
6417 (lambda (exit)
6418 (for-each (lambda (x)
6419 (if (negative? x)
6420 (exit x)))
6421 '(54 0 37 -3 245 19))
6422 #t)) ==&gt; -3
6424 (define list-length
6425 (lambda (obj)
6426 (call-with-current-continuation
6427 (lambda (return)
6428 (letrec ((r
6429 (lambda (obj)
6430 (cond ((null? obj) 0)
6431 ((pair? obj)
6432 (+ (r (cdr obj)) 1))
6433 (else (return #f))))))
6434 (r obj))))))
6436 (list-length '(1 2 3 4)) ==&gt; 4
6438 (list-length '(a b . c)) ==&gt; #f
6439 </pre></td></tr></table>
6443 <blockquote><p><em>Rationale:</em>
6444 </p>
6445 <p>A common use of <samp>call-with-current-continuation</samp> is for
6446 structured, non-local exits from loops or procedure bodies, but in fact
6447 <samp>call-with-current-continuation</samp> is extremely useful for implementing a
6448 wide variety of advanced control structures.
6449 </p>
6450 <p>Whenever a Scheme expression is evaluated there is a
6451 <em>continuation</em> wanting the result of the expression. The continuation
6452 <a name="index-continuation"></a>
6453 represents an entire (default) future for the computation. If the expression is
6454 evaluated at top level, for example, then the continuation might take the
6455 result, print it on the screen, prompt for the next input, evaluate it, and
6456 so on forever. Most of the time the continuation includes actions
6457 specified by user code, as in a continuation that will take the result,
6458 multiply it by the value stored in a local variable, add seven, and give
6459 the answer to the top level continuation to be printed. Normally these
6460 ubiquitous continuations are hidden behind the scenes and programmers do not
6461 think much about them. On rare occasions, however, a programmer may
6462 need to deal with continuations explicitly.
6463 <samp>Call-with-current-continuation</samp> allows Scheme programmers to do
6464 that by creating a procedure that acts just like the current
6465 continuation.
6466 </p>
6467 <p>Most programming languages incorporate one or more special-purpose
6468 escape constructs with names like <tt>exit</tt>, <samp>return</samp>, or
6469 even <tt>goto</tt>. In 1965, however, Peter Landin [Landin65]
6470 invented a general purpose escape operator called the J-operator. John
6471 Reynolds [Reynolds72] described a simpler but equally powerful
6472 construct in 1972. The <samp>catch</samp> special form described by Sussman
6473 and Steele in the 1975 report on Scheme is exactly the same as
6474 Reynolds's construct, though its name came from a less general construct
6475 in MacLisp. Several Scheme implementors noticed that the full power of the
6476 <code>catch</code> construct could be provided by a procedure instead of by a
6477 <a name="index-catch"></a>
6478 special syntactic construct, and the name
6479 <samp>call-with-current-continuation</samp> was coined in 1982. This name is
6480 descriptive, but opinions differ on the merits of such a long name, and
6481 some people use the name <code>call/cc</code> instead.
6482 <a name="index-call_002fcc"></a>
6483 </p></blockquote>
6489 <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>
6491 <p>Delivers all of its arguments to its continuation.
6492 Except for continuations created by the <code>call-with-values</code>
6493 <a name="index-call_002dwith_002dvalues-1"></a>
6494 procedure, all continuations take exactly one value.
6495 <tt>Values</tt> might be defined as follows:
6496 </p>
6497 <table><tr><td>&nbsp;</td><td><pre class="format">(define (values . things)
6498 (call-with-current-continuation
6499 (lambda (cont) (apply cont things))))
6500 </pre></td></tr></table>
6506 <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>
6508 <p>Calls its <var>producer</var> argument with no values and
6509 a continuation that, when passed some values, calls the
6510 <var>consumer</var> procedure with those values as arguments.
6511 The continuation for the call to <var>consumer</var> is the
6512 continuation of the call to <tt>call-with-values</tt>.
6513 </p>
6515 <table><tr><td>&nbsp;</td><td><pre class="format">(call-with-values (lambda () (values 4 5))
6516 (lambda (a b) b))
6517 ==&gt; 5
6519 (call-with-values * -) ==&gt; -1
6520 </pre></td></tr></table>
6526 <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>
6528 <p>Calls <var>thunk</var> without arguments, returning the result(s) of this call.
6529 <var>Before</var> and <var>after</var> are called, also without arguments, as required
6530 by the following rules (note that in the absence of calls to continuations
6531 captured using <code>call-with-current-continuation</code> the three arguments are
6532 <a name="index-call_002dwith_002dcurrent_002dcontinuation-2"></a>
6533 called once each, in order). <var>Before</var> is called whenever execution
6534 enters the dynamic extent of the call to <var>thunk</var> and <var>after</var> is called
6535 whenever it exits that dynamic extent. The dynamic extent of a procedure
6536 call is the period between when the call is initiated and when it
6537 returns. In Scheme, because of <samp>call-with-current-continuation</samp>, the
6538 dynamic extent of a call may not be a single, connected time period.
6539 It is defined as follows:
6540 </p>
6542 <ul>
6543 <li>
6544 The dynamic extent is entered when execution of the body of the
6545 called procedure begins.
6547 </li><li>
6548 The dynamic extent is also entered when execution is not within
6549 the dynamic extent and a continuation is invoked that was captured
6550 (using <samp>call-with-current-continuation</samp>) during the dynamic extent.
6552 </li><li>
6553 It is exited when the called procedure returns.
6555 </li><li>
6556 It is also exited when execution is within the dynamic extent and
6557 a continuation is invoked that was captured while not within the
6558 dynamic extent.
6560 </li></ul>
6563 <p>If a second call to <samp>dynamic-wind</samp> occurs within the dynamic extent of the
6564 call to <var>thunk</var> and then a continuation is invoked in such a way that the
6565 <var>after</var>s from these two invocations of <samp>dynamic-wind</samp> are both to be
6566 called, then the <var>after</var> associated with the second (inner) call to
6567 <samp>dynamic-wind</samp> is called first.
6568 </p>
6569 <p>If a second call to <samp>dynamic-wind</samp> occurs within the dynamic extent of the
6570 call to <var>thunk</var> and then a continuation is invoked in such a way that the
6571 <var>before</var>s from these two invocations of <samp>dynamic-wind</samp> are both to be
6572 called, then the <var>before</var> associated with the first (outer) call to
6573 <samp>dynamic-wind</samp> is called first.
6574 </p>
6575 <p>If invoking a continuation requires calling the <var>before</var> from one call
6576 to <samp>dynamic-wind</samp> and the <var>after</var> from another, then the <var>after</var>
6577 is called first.
6578 </p>
6579 <p>The effect of using a captured continuation to enter or exit the dynamic
6580 extent of a call to <var>before</var> or <var>after</var> is undefined.
6581 </p>
6583 <table><tr><td>&nbsp;</td><td><pre class="format">(let ((path '())
6584 (c #f))
6585 (let ((add (lambda (s)
6586 (set! path (cons s path)))))
6587 (dynamic-wind
6588 (lambda () (add 'connect))
6589 (lambda ()
6590 (add (call-with-current-continuation
6591 (lambda (c0)
6592 (set! c c0)
6593 'talk1))))
6594 (lambda () (add 'disconnect)))
6595 (if (&lt; (length path) 4)
6596 (c 'talk2)
6597 (reverse path))))
6599 ==&gt; (connect talk1 disconnect
6600 connect talk2 disconnect)
6601 </pre></td></tr></table>
6605 <hr size="1">
6606 <a name="Eval"></a>
6607 <table cellpadding="1" cellspacing="1" border="0">
6608 <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>
6609 <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>
6610 <td valign="middle" align="left"> &nbsp; </td>
6611 <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>
6612 <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>
6613 <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>
6614 <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>
6615 <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>
6616 <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>
6617 </tr></table>
6618 <a name="Eval-1"></a>
6619 <h2 class="section">6.5 Eval</h2>
6623 <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>
6625 <p>Evaluates <var>expression</var> in the specified environment and returns its value.
6626 <var>Expression</var> must be a valid Scheme expression represented as data,
6627 and <var>environment-specifier</var> must be a value returned by one of the
6628 three procedures described below.
6629 Implementations may extend <samp>eval</samp> to allow non-expression programs
6630 (definitions) as the first argument and to allow other
6631 values as environments, with the restriction that <samp>eval</samp> is not
6632 allowed to create new bindings in the environments associated with
6633 <samp>null-environment</samp> or <samp>scheme-report-environment</samp>.
6634 </p>
6636 <table><tr><td>&nbsp;</td><td><pre class="format">(eval '(* 7 3) (scheme-report-environment 5))
6637 ==&gt; 21
6639 (let ((f (eval '(lambda (f x) (f x x))
6640 (null-environment 5))))
6641 (f + 10))
6642 ==&gt; 20
6643 </pre></td></tr></table>
6649 <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>
6650 <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>
6652 <p><var>Version</var> must be the exact integer <samp>5</samp>,
6653 corresponding to this revision of the Scheme report (the
6654 Revised^5 Report on Scheme).
6655 <samp>Scheme-report-environment</samp> returns a specifier for an
6656 environment that is empty except for all bindings defined in
6657 this report that are either required or both optional and
6658 supported by the implementation. <samp>Null-environment</samp> returns
6659 a specifier for an environment that is empty except for the
6660 (syntactic) bindings for all syntactic keywords defined in
6661 this report that are either required or both optional and
6662 supported by the implementation.
6663 </p>
6664 <p>Other values of <var>version</var> can be used to specify environments
6665 matching past revisions of this report, but their support is not
6666 required. An implementation will signal an error if <var>version</var>
6667 is neither <samp>5</samp> nor another value supported by
6668 the implementation.
6669 </p>
6670 <p>The effect of assigning (through the use of <samp>eval</samp>) a variable
6671 bound in a <samp>scheme-report-environment</samp>
6672 (for example <samp>car</samp>) is unspecified. Thus the environments specified
6673 by <samp>scheme-report-environment</samp> may be immutable.
6674 </p>
6678 <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>
6680 <p>This procedure returns a specifier for the environment that
6681 contains implementation-defined bindings, typically a superset of
6682 those listed in the report. The intent is that this procedure
6683 will return the environment in which the implementation would evaluate
6684 expressions dynamically typed by the user.
6685 </p>
6688 <hr size="1">
6689 <a name="Input-and-output"></a>
6690 <table cellpadding="1" cellspacing="1" border="0">
6691 <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>
6692 <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>
6693 <td valign="middle" align="left"> &nbsp; </td>
6694 <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>
6695 <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>
6696 <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>
6697 <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>
6698 <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>
6699 <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>
6700 </tr></table>
6701 <a name="Input-and-output-1"></a>
6702 <h2 class="section">6.6 Input and output</h2>
6704 <table class="menu" border="0" cellspacing="0">
6705 <tr><td align="left" valign="top"><a href="#Ports">6.6.1 Ports</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
6706 </td></tr>
6707 <tr><td align="left" valign="top"><a href="#Input">6.6.2 Input</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
6708 </td></tr>
6709 <tr><td align="left" valign="top"><a href="#Output">6.6.3 Output</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
6710 </td></tr>
6711 <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">
6712 </td></tr>
6713 </table>
6716 <hr size="1">
6717 <a name="Ports"></a>
6718 <table cellpadding="1" cellspacing="1" border="0">
6719 <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>
6720 <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>
6721 <td valign="middle" align="left"> &nbsp; </td>
6722 <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>
6723 <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>
6724 <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>
6725 <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>
6726 <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>
6727 <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>
6728 </tr></table>
6729 <a name="Ports-1"></a>
6730 <h3 class="subsection">6.6.1 Ports</h3>
6734 <p>Ports represent input and output devices. To Scheme, an input port is a
6735 Scheme object that can deliver characters upon command, while an output port
6736 is a Scheme object that can accept characters.
6737 <a name="index-port"></a>
6738 </p>
6742 <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>
6743 <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>
6745 <p><var>String</var> should be a string naming a file, and
6746 <var>proc</var> should be a procedure that accepts one argument.
6747 For <samp>call-with-input-file</samp>,
6748 the file should already exist; for
6749 <samp>call-with-output-file</samp>,
6750 the effect is unspecified if the file
6751 already exists. These procedures call <var>proc</var> with one argument: the
6752 port obtained by opening the named file for input or output. If the
6753 file cannot be opened, an error is signalled. If <var>proc</var> returns,
6754 then the port is closed automatically and the value(s) yielded by the
6755 <var>proc</var> is(are) returned. If <var>proc</var> does not return, then
6756 the port will not be closed automatically unless it is possible to
6757 prove that the port will never again be used for a read or write
6758 operation.
6759 </p>
6761 <blockquote><p><em>Rationale:</em>
6762 Because Scheme's escape procedures have unlimited extent, it is
6763 possible to escape from the current continuation but later to escape back in.
6764 If implementations were permitted to close the port on any escape from the
6765 current continuation, then it would be impossible to write portable code using
6766 both <samp>call-with-current-continuation</samp> and <samp>call-with-input-file</samp> or
6767 <samp>call-with-output-file</samp>.
6768 </p>
6769 </blockquote>
6775 <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>
6776 <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>
6778 <p>Returns <tt>#t</tt> if <var>obj</var> is an input port or output port
6779 respectively, otherwise returns <tt>#f</tt>.
6780 </p>
6787 <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>
6788 <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>
6790 <p>Returns the current default input or output port.
6791 </p>
6796 <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>
6797 <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>
6799 <p><var>String</var> should be a string naming a file, and
6800 <var>proc</var> should be a procedure of no arguments.
6801 For <samp>with-input-from-file</samp>,
6802 the file should already exist; for
6803 <samp>with-output-to-file</samp>,
6804 the effect is unspecified if the file
6805 already exists.
6806 The file is opened for input or output, an input or output port
6807 connected to it is made the default value returned by
6808 <samp>current-input-port</samp> or <samp>current-output-port</samp>
6809 (and is used by <tt>(read)</tt>, <tt>(write <var>obj</var>)</tt>, and so forth),
6810 and the
6811 <var>thunk</var> is called with no arguments. When the <var>thunk</var> returns,
6812 the port is closed and the previous default is restored.
6813 <samp>With-input-from-file</samp> and <samp>with-output-to-file</samp> return(s) the
6814 value(s) yielded by <var>thunk</var>.
6815 If an escape procedure
6816 is used to escape from the continuation of these procedures, their
6817 behavior is implementation dependent.
6818 </p>
6828 <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>
6830 <p>Takes a string naming an existing file and returns an input port capable of
6831 delivering characters from the file. If the file cannot be opened, an error is
6832 signalled.
6833 </p>
6838 <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>
6840 <p>Takes a string naming an output file to be created and returns an output
6841 port capable of writing characters to a new file by that name. If the file
6842 cannot be opened, an error is signalled. If a file with the given name
6843 already exists, the effect is unspecified.
6844 </p>
6849 <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>
6850 <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>
6852 <p>Closes the file associated with <var>port</var>, rendering the <var>port</var>
6853 incapable of delivering or accepting characters.
6854 </p>
6855 <p>These routines have no effect if the file has already been closed.
6856 The value returned is unspecified.
6857 </p>
6865 <hr size="1">
6866 <a name="Input"></a>
6867 <table cellpadding="1" cellspacing="1" border="0">
6868 <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>
6869 <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>
6870 <td valign="middle" align="left"> &nbsp; </td>
6871 <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>
6872 <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>
6873 <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>
6874 <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>
6875 <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>
6876 <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>
6877 </tr></table>
6878 <a name="Input-1"></a>
6879 <h3 class="subsection">6.6.2 Input</h3>
6884 <p>
6885 <br>
6886 <br>
6887 <br>
6888 <br>
6889 <br>
6890 </p>
6893 <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>
6894 <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>
6896 <p><samp>Read</samp> converts external representations of Scheme objects into the
6897 objects themselves. That is, it is a parser for the nonterminal
6898 &lt;datum&gt; (see sections see section <a href="#External-representation">External representations</a> and
6899 see section <a href="#Pairs-and-lists">Pairs and lists</a>). <samp>Read</samp> returns the next
6900 object parsable from the given input <var>port</var>, updating <var>port</var> to point to
6901 the first character past the end of the external representation of the object.
6902 </p>
6903 <p>If an end of file is encountered in the input before any
6904 characters are found that can begin an object, then an end of file
6905 object is returned.
6906 The port remains open, and further attempts
6907 to read will also return an end of file object. If an end of file is
6908 encountered after the beginning of an object's external representation,
6909 but the external representation is incomplete and therefore not parsable,
6910 an error is signalled.
6911 </p>
6912 <p>The <var>port</var> argument may be omitted, in which case it defaults to the
6913 value returned by <samp>current-input-port</samp>. It is an error to read from
6914 a closed port.
6915 </p>
6918 <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>
6919 <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>
6921 <p>Returns the next character available from the input <var>port</var>, updating
6922 the <var>port</var> to point to the following character. If no more characters
6923 are available, an end of file object is returned. <var>Port</var> may be
6924 omitted, in which case it defaults to the value returned by <samp>current-input-port</samp>.
6925 </p>
6930 <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>
6931 <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>
6933 <p>Returns the next character available from the input <var>port</var>,
6934 <em>without</em> updating
6935 the <var>port</var> to point to the following character. If no more characters
6936 are available, an end of file object is returned. <var>Port</var> may be
6937 omitted, in which case it defaults to the value returned by <samp>current-input-port</samp>.
6938 </p>
6940 <blockquote><p><em>Note:</em>
6941 The value returned by a call to <samp>peek-char</samp> is the same as the
6942 value that would have been returned by a call to <samp>read-char</samp> with the
6943 same <var>port</var>. The only difference is that the very next call to
6944 <samp>read-char</samp> or <samp>peek-char</samp> on that <var>port</var> will return the
6945 value returned by the preceding call to <samp>peek-char</samp>. In particular, a call
6946 to <samp>peek-char</samp> on an interactive port will hang waiting for input
6947 whenever a call to <samp>read-char</samp> would have hung.
6948 </p></blockquote>
6955 <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>
6957 <p>Returns <tt>#t</tt> if <var>obj</var> is an end of file object, otherwise returns
6958 <tt>#f</tt>. The precise set of end of file objects will vary among
6959 implementations, but in any case no end of file object will ever be an object
6960 that can be read in using <samp>read</samp>.
6961 </p>
6966 <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>
6967 <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>
6969 <p>Returns <tt>#t</tt> if a character is ready on the input <var>port</var> and
6970 returns <tt>#f</tt> otherwise. If <samp>char-ready</samp> returns <tt>#t</tt> then
6971 the next <samp>read-char</samp> operation on the given <var>port</var> is guaranteed
6972 not to hang. If the <var>port</var> is at end of file then <samp>char-ready?</samp>
6973 returns <tt>#t</tt>. <var>Port</var> may be omitted, in which case it defaults to
6974 the value returned by <samp>current-input-port</samp>.
6975 </p>
6977 <blockquote><p><em>Rationale:</em>
6978 <samp>Char-ready?</samp> exists to make it possible for a program to
6979 accept characters from interactive ports without getting stuck waiting for
6980 input. Any input editors associated with such ports must ensure that
6981 characters whose existence has been asserted by <samp>char-ready?</samp> cannot
6982 be rubbed out. If <samp>char-ready?</samp> were to return <tt>#f</tt> at end of
6983 file, a port at end of file would be indistinguishable from an interactive
6984 port that has no ready characters.
6985 </p></blockquote>
6990 <hr size="1">
6991 <a name="Output"></a>
6992 <table cellpadding="1" cellspacing="1" border="0">
6993 <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>
6994 <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>
6995 <td valign="middle" align="left"> &nbsp; </td>
6996 <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>
6997 <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>
6998 <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>
6999 <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>
7000 <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>
7001 <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>
7002 </tr></table>
7003 <a name="Output-1"></a>
7004 <h3 class="subsection">6.6.3 Output</h3>
7009 <p>
7010 <br>
7011 <br>
7012 <br>
7013 <br>
7014 <br>
7015 </p>
7017 <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>
7018 <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>
7020 <p>Writes a written representation of <var>obj</var> to the given <var>port</var>. Strings
7021 that appear in the written representation are enclosed in doublequotes, and
7022 within those strings backslash and doublequote characters are
7023 escaped by backslashes.
7024 Character objects are written using the <samp>#\</samp> notation.
7025 <samp>Write</samp> returns an unspecified value. The
7026 <var>port</var> argument may be omitted, in which case it defaults to the value
7027 returned by <samp>current-output-port</samp>.
7028 </p>
7033 <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>
7034 <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>
7036 <p>Writes a representation of <var>obj</var> to the given <var>port</var>. Strings
7037 that appear in the written representation are not enclosed in
7038 doublequotes, and no characters are escaped within those strings. Character
7039 objects appear in the representation as if written by <samp>write-char</samp>
7040 instead of by <samp>write</samp>. <samp>Display</samp> returns an unspecified value.
7041 The <var>port</var> argument may be omitted, in which case it defaults to the
7042 value returned by <samp>current-output-port</samp>.
7043 </p>
7045 <blockquote><p><em>Rationale:</em>
7046 <samp>Write</samp> is intended
7047 for producing machine-readable output and <samp>display</samp> is for producing
7048 human-readable output. Implementations that allow &ldquo;slashification&rdquo;
7049 within symbols will probably want <samp>write</samp> but not <samp>display</samp> to
7050 slashify funny characters in symbols.
7051 </p></blockquote>
7057 <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>
7058 <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>
7060 <p>Writes an end of line to <var>port</var>. Exactly how this is done differs
7061 from one operating system to another. Returns an unspecified value.
7062 The <var>port</var> argument may be omitted, in which case it defaults to the
7063 value returned by <samp>current-output-port</samp>.
7064 </p>
7069 <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>
7070 <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>
7072 <p>Writes the character <var>char</var> (not an external representation of the
7073 character) to the given <var>port</var> and returns an unspecified value. The
7074 <var>port</var> argument may be omitted, in which case it defaults to the value
7075 returned by <samp>current-output-port</samp>.
7076 </p>
7080 <hr size="1">
7081 <a name="System-interface"></a>
7082 <table cellpadding="1" cellspacing="1" border="0">
7083 <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>
7084 <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>
7085 <td valign="middle" align="left"> &nbsp; </td>
7086 <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>
7087 <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>
7088 <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>
7089 <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>
7090 <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>
7091 <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>
7092 </tr></table>
7093 <a name="System-interface-1"></a>
7094 <h3 class="subsection">6.6.4 System interface</h3>
7097 <p>Questions of system interface generally fall outside of the domain of this
7098 report. However, the following operations are important enough to
7099 deserve description here.
7100 </p>
7103 <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>
7107 <p><var>Filename</var> should be a string naming an existing file
7108 containing Scheme source code. The <samp>load</samp> procedure reads
7109 expressions and definitions from the file and evaluates them
7110 sequentially. It is unspecified whether the results of the expressions
7111 are printed. The <samp>load</samp> procedure does not affect the values
7112 returned by <samp>current-input-port</samp> and <samp>current-output-port</samp>.
7113 <samp>Load</samp> returns an unspecified value.
7114 </p>
7116 <blockquote><p><em>Rationale:</em>
7117 For portability, <samp>load</samp> must operate on source files.
7118 Its operation on other kinds of files necessarily varies among
7119 implementations.
7120 </p></blockquote>
7126 <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>
7127 <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>
7129 <p><var>Filename</var> must be a string naming an output file to be
7130 created. The effect of <samp>transcript-on</samp> is to open the named file
7131 for output, and to cause a transcript of subsequent interaction between
7132 the user and the Scheme system to be written to the file. The
7133 transcript is ended by a call to <samp>transcript-off</samp>, which closes the
7134 transcript file. Only one transcript may be in progress at any time,
7135 though some implementations may relax this restriction. The values
7136 returned by these procedures are unspecified.
7137 </p>
7142 <hr size="1">
7143 <a name="Formal-syntax-and-semantics"></a>
7144 <table cellpadding="1" cellspacing="1" border="0">
7145 <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>
7146 <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>
7147 <td valign="middle" align="left"> &nbsp; </td>
7148 <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>
7149 <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>
7150 <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>
7151 <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>
7152 <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>
7153 <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>
7154 </tr></table>
7155 <a name="Formal-syntax-and-semantics-1"></a>
7156 <h1 class="chapter">7. Formal syntax and semantics</h1>
7158 <table class="menu" border="0" cellspacing="0">
7159 <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">
7160 </td></tr>
7161 <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">
7162 </td></tr>
7163 <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">
7164 </td></tr>
7165 </table>
7169 <p>This chapter provides formal descriptions of what has already been
7170 described informally in previous chapters of this report.
7171 </p>
7175 <hr size="1">
7176 <a name="Formal-syntax"></a>
7177 <table cellpadding="1" cellspacing="1" border="0">
7178 <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>
7179 <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>
7180 <td valign="middle" align="left"> &nbsp; </td>
7181 <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>
7182 <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>
7183 <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>
7184 <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>
7185 <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>
7186 <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>
7187 </tr></table>
7188 <a name="Formal-syntax-1"></a>
7189 <h2 class="section">7.1 Formal syntax</h2>
7191 <table class="menu" border="0" cellspacing="0">
7192 <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">
7193 </td></tr>
7194 <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">
7195 </td></tr>
7196 <tr><td align="left" valign="top"><a href="#Expression">7.1.3 Expressions</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
7197 </td></tr>
7198 <tr><td align="left" valign="top"><a href="#Quasiquotations">7.1.4 Quasiquotations</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
7199 </td></tr>
7200 <tr><td align="left" valign="top"><a href="#Transformers">7.1.5 Transformers</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
7201 </td></tr>
7202 <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">
7203 </td></tr>
7204 </table>
7208 <p>This section provides a formal syntax for Scheme written in an extended
7209 BNF.
7210 </p>
7211 <p>All spaces in the grammar are for legibility. Case is insignificant;
7212 for example, <samp>#x1A</samp> and <samp>#X1a</samp> are equivalent. &lt;empty&gt;
7213 stands for the empty string.
7214 </p>
7215 <p>The following extensions to BNF are used to make the description more
7216 concise: &lt;thing&gt;* means zero or more occurrences of
7217 &lt;thing&gt;; and &lt;thing&gt;+ means at least one
7218 &lt;thing&gt;.
7219 </p>
7221 <hr size="1">
7222 <a name="Lexical-structure"></a>
7223 <table cellpadding="1" cellspacing="1" border="0">
7224 <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>
7225 <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>
7226 <td valign="middle" align="left"> &nbsp; </td>
7227 <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>
7228 <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>
7229 <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>
7230 <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>
7231 <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>
7232 <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>
7233 </tr></table>
7234 <a name="Lexical-structure-1"></a>
7235 <h3 class="subsection">7.1.1 Lexical structure</h3>
7238 <p>This section describes how individual tokens (identifiers,
7239 <a name="index-token"></a>
7240 numbers, etc.) are formed from sequences of characters. The following
7241 sections describe how expressions and programs are formed from sequences
7242 of tokens.
7243 </p>
7244 <p>&lt;Intertoken space&gt; may occur on either side of any token, but not
7245 within a token.
7246 </p>
7247 <p>Tokens which require implicit termination (identifiers, numbers,
7248 characters, and dot) may be terminated by any &lt;delimiter&gt;, but not
7249 necessarily by anything else.
7250 </p>
7251 <p>The following five characters are reserved for future extensions to the
7252 language: <tt>[ ] { } |</tt>
7253 </p>
7255 <table><tr><td>&nbsp;</td><td><pre class="format">&lt;token&gt; &ndash;&gt; &lt;identifier&gt; | &lt;boolean&gt; | &lt;number&gt;
7256 <a name="index-identifier-3"></a> | &lt;character&gt; | &lt;string&gt;
7257 | ( | ) | #( | <tt>'</tt> | <tt>&lsquo;</tt> | , | ,@ | <b>.</b>
7258 &lt;delimiter&gt; &ndash;&gt; &lt;whitespace&gt; | ( | ) | &quot; | ;
7259 &lt;whitespace&gt; &ndash;&gt; &lt;space or newline&gt;
7260 &lt;comment&gt; &ndash;&gt; ; &lt;<span class="roman">all subsequent characters up to a</span>
7261 <span class="roman">line break&gt;</span>
7262 <a name="index-comment-1"></a>&lt;atmosphere&gt; &ndash;&gt; &lt;whitespace&gt; | &lt;comment&gt;
7263 &lt;intertoken space&gt; &ndash;&gt; &lt;atmosphere&gt;*
7264 </pre></td></tr></table>
7274 <table><tr><td>&nbsp;</td><td><pre class="format">&lt;identifier&gt; &ndash;&gt; &lt;initial&gt; &lt;subsequent&gt;*
7275 | &lt;peculiar identifier&gt;
7276 &lt;initial&gt; &ndash;&gt; &lt;letter&gt; | &lt;special initial&gt;
7277 &lt;letter&gt; &ndash;&gt; a | b | c | ... | z
7279 &lt;special initial&gt; &ndash;&gt; ! | $ | % | &amp; | * | / | : | &lt; | =
7280 | &gt; | ? | ^ | _ | ~
7281 &lt;subsequent&gt; &ndash;&gt; &lt;initial&gt; | &lt;digit&gt;
7282 | &lt;special subsequent&gt;
7283 &lt;digit&gt; &ndash;&gt; 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
7284 &lt;special subsequent&gt; &ndash;&gt; + | - | . | @
7285 &lt;peculiar identifier&gt; &ndash;&gt; + | - | ...
7286 &lt;syntactic keyword&gt; &ndash;&gt; &lt;expression keyword&gt;
7287 <a name="index-syntactic-keyword-3"></a><a name="index-keyword-2"></a> | else | =&gt; | define
7288 | unquote | unquote-splicing
7289 &lt;expression keyword&gt; &ndash;&gt; quote | lambda | if
7290 | set! | begin | cond | and | or | case
7291 | let | let* | letrec | do | delay
7292 | quasiquote
7294 <samp>&lt;variable&gt; &rArr; &lt;</samp><span class="roman">any &lt;identifier&gt; that isn't</span>
7295 <a name="index-variable-3"></a> <span class="roman">also a &lt;syntactic keyword&gt;&gt;</span>
7297 &lt;boolean&gt; &ndash;&gt; #t | #f
7298 &lt;character&gt; &ndash;&gt; #\ &lt;any character&gt;
7299 | #\ &lt;character name&gt;
7300 &lt;character name&gt; &ndash;&gt; space | newline
7302 &lt;string&gt; &ndash;&gt; &quot; &lt;string element&gt;* &quot;
7303 &lt;string element&gt; &ndash;&gt; &lt;any character other than &quot; or \&gt;
7304 | \&quot; | \\
7305 </pre></td></tr></table>
7313 <table><tr><td>&nbsp;</td><td><pre class="format">&lt;number&gt; &ndash;&gt; &lt;num 2&gt;| &lt;num 8&gt;
7314 | &lt;num 10&gt;| &lt;num 16&gt;
7315 </pre></td></tr></table>
7319 <p>The following rules for &lt;num R&gt;, &lt;complex R&gt;, &lt;real
7320 R&gt;, &lt;ureal R&gt;, &lt;uinteger R&gt;, and &lt;prefix R&gt;
7321 should be replicated for R = 2, 8, 10,
7322 and 16. There are no rules for &lt;decimal 2&gt;, &lt;decimal
7323 8&gt;, and &lt;decimal 16&gt;, which means that numbers containing
7324 decimal points or exponents must be in decimal radix.
7325 </p>
7328 <table><tr><td>&nbsp;</td><td><pre class="format">&lt;num R&gt; &ndash;&gt; &lt;prefix R&gt; &lt;complex R&gt;
7329 &lt;complex R&gt; &ndash;&gt; &lt;real R&gt; | &lt;real R&gt; @ &lt;real R&gt;
7330 | &lt;real R&gt; + &lt;ureal R&gt; i | &lt;real R&gt; - &lt;ureal R&gt; i
7331 | &lt;real R&gt; + i | &lt;real R&gt; - i
7332 | + &lt;ureal R&gt; i | - &lt;ureal R&gt; i | + i | - i
7333 &lt;real R&gt; &ndash;&gt; &lt;sign&gt; &lt;ureal R&gt;
7334 &lt;ureal R&gt; &ndash;&gt; &lt;uinteger R&gt;
7335 | &lt;uinteger R&gt; / &lt;uinteger R&gt;
7336 | &lt;decimal R&gt;
7337 &lt;decimal 10&gt; &ndash;&gt; &lt;uinteger 10&gt; &lt;suffix&gt;
7338 | . &lt;digit 10&gt;+ #* &lt;suffix&gt;
7339 | &lt;digit 10&gt;+ . &lt;digit 10&gt;* #* &lt;suffix&gt;
7340 | &lt;digit 10&gt;+ #+ . #* &lt;suffix&gt;
7341 &lt;uinteger R&gt; &ndash;&gt; &lt;digit R&gt;+ #*
7342 &lt;prefix R&gt; &ndash;&gt; &lt;radix R&gt; &lt;exactness&gt;
7343 | &lt;exactness&gt; &lt;radix R&gt;
7344 </pre></td></tr></table>
7349 <table><tr><td>&nbsp;</td><td><pre class="format">&lt;suffix&gt; &ndash;&gt; &lt;empty&gt;
7350 | &lt;exponent marker&gt; &lt;sign&gt; &lt;digit 10&gt;+
7351 &lt;exponent marker&gt; &ndash;&gt; e | s | f | d | l
7352 &lt;sign&gt; &ndash;&gt; &lt;empty&gt; | + | -
7353 &lt;exactness&gt; &ndash;&gt; &lt;empty&gt; | #i | #e
7354 <a name="index-_0023e-1"></a><a name="index-_0023i-1"></a>&lt;radix 2&gt; &ndash;&gt; #b
7355 <a name="index-_0023b-1"></a>&lt;radix 8&gt; &ndash;&gt; #o
7356 <a name="index-_0023o-1"></a>&lt;radix 10&gt; &ndash;&gt; &lt;empty&gt; | #d
7357 &lt;radix 16&gt; &ndash;&gt; #x
7358 <a name="index-_0023x-1"></a>&lt;digit 2&gt; &ndash;&gt; 0 | 1
7359 &lt;digit 8&gt; &ndash;&gt; 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7
7360 &lt;digit 10&gt; &ndash;&gt; &lt;digit&gt;
7361 &lt;digit 16&gt; &ndash;&gt; &lt;digit 10&gt; | a | b | c | d | e | f
7362 </pre></td></tr></table>
7369 <hr size="1">
7370 <a name="External-representation"></a>
7371 <table cellpadding="1" cellspacing="1" border="0">
7372 <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>
7373 <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>
7374 <td valign="middle" align="left"> &nbsp; </td>
7375 <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>
7376 <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>
7377 <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>
7378 <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>
7379 <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>
7380 <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>
7381 </tr></table>
7382 <a name="External-representations-1"></a>
7383 <h3 class="subsection">7.1.2 External representations</h3>
7387 <p>&lt;Datum&gt; is what the <code>read</code> procedure (section see section <a href="#Input">Input</a>)
7388 <a name="index-read-3"></a>
7389 successfully parses. Note that any string that parses as an
7390 &lt;expression&gt; will also parse as a &lt;datum&gt;.
7391 </p>
7393 <table><tr><td>&nbsp;</td><td><pre class="format">&lt;datum&gt; &ndash;&gt; &lt;simple datum&gt; | &lt;compound datum&gt;
7394 &lt;simple datum&gt; &ndash;&gt; &lt;boolean&gt; | &lt;number&gt;
7395 | &lt;character&gt; | &lt;string&gt; | &lt;symbol&gt;
7396 &lt;symbol&gt; &ndash;&gt; &lt;identifier&gt;
7397 &lt;compound datum&gt; &ndash;&gt; &lt;list&gt; | &lt;vector&gt;
7398 &lt;list&gt; &ndash;&gt; (&lt;datum&gt;*) | (&lt;datum&gt;+ . &lt;datum&gt;)
7399 | &lt;abbreviation&gt;
7400 &lt;abbreviation&gt; &ndash;&gt; &lt;abbrev prefix&gt; &lt;datum&gt;
7401 &lt;abbrev prefix&gt; &ndash;&gt; ' | &lsquo; | , | ,@
7402 &lt;vector&gt; &ndash;&gt; #(&lt;datum&gt;*)
7403 </pre></td></tr></table>
7408 <hr size="1">
7409 <a name="Expression"></a>
7410 <table cellpadding="1" cellspacing="1" border="0">
7411 <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>
7412 <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>
7413 <td valign="middle" align="left"> &nbsp; </td>
7414 <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>
7415 <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>
7416 <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>
7417 <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>
7418 <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>
7419 <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>
7420 </tr></table>
7421 <a name="Expressions-1"></a>
7422 <h3 class="subsection">7.1.3 Expressions</h3>
7426 <table><tr><td>&nbsp;</td><td><pre class="format">&lt;expression&gt; &ndash;&gt; &lt;variable&gt;
7427 | &lt;literal&gt;
7428 | &lt;procedure call&gt;
7429 | &lt;lambda expression&gt;
7430 | &lt;conditional&gt;
7431 | &lt;assignment&gt;
7432 | &lt;derived expression&gt;
7433 | &lt;macro use&gt;
7434 | &lt;macro block&gt;
7436 &lt;literal&gt; &ndash;&gt; &lt;quotation&gt; | &lt;self-evaluating&gt;
7437 &lt;self-evaluating&gt; &ndash;&gt; &lt;boolean&gt; | &lt;number&gt;
7438 | &lt;character&gt; | &lt;string&gt;
7439 &lt;quotation&gt; &ndash;&gt; '&lt;datum&gt; | (quote &lt;datum&gt;)
7440 &lt;procedure call&gt; &ndash;&gt; (&lt;operator&gt; &lt;operand&gt;*)
7441 &lt;operator&gt; &ndash;&gt; &lt;expression&gt;
7442 &lt;operand&gt; &ndash;&gt; &lt;expression&gt;
7444 &lt;lambda expression&gt; &ndash;&gt; (lambda &lt;formals&gt; &lt;body&gt;)
7445 &lt;formals&gt; &ndash;&gt; (&lt;variable&gt;*) | &lt;variable&gt;
7446 | (&lt;variable&gt;+ . &lt;variable&gt;)
7447 &lt;body&gt; &ndash;&gt; &lt;definition&gt;* &lt;sequence&gt;
7448 &lt;sequence&gt; &ndash;&gt; &lt;command&gt;* &lt;expression&gt;
7449 &lt;command&gt; &ndash;&gt; &lt;expression&gt;
7451 &lt;conditional&gt; &ndash;&gt; (if &lt;test&gt; &lt;consequent&gt; &lt;alternate&gt;)
7452 &lt;test&gt; &ndash;&gt; &lt;expression&gt;
7453 &lt;consequent&gt; &ndash;&gt; &lt;expression&gt;
7454 &lt;alternate&gt; &ndash;&gt; &lt;expression&gt; | &lt;empty&gt;
7456 &lt;assignment&gt; &ndash;&gt; (set! &lt;variable&gt; &lt;expression&gt;)
7458 &lt;derived expression&gt; &ndash;&gt;
7459 (cond &lt;cond clause&gt;+)
7460 | (cond &lt;cond clause&gt;* (else &lt;sequence&gt;))
7461 | (case &lt;expression&gt;
7462 &lt;case clause&gt;+)
7463 | (case &lt;expression&gt;
7464 &lt;case clause&gt;*
7465 (else &lt;sequence&gt;))
7466 | (and &lt;test&gt;*)
7467 | (or &lt;test&gt;*)
7468 | (let (&lt;binding spec&gt;*) &lt;body&gt;)
7469 | (let &lt;variable&gt; (&lt;binding spec&gt;*) &lt;body&gt;)
7470 | (let* (&lt;binding spec&gt;*) &lt;body&gt;)
7471 | (letrec (&lt;binding spec&gt;*) &lt;body&gt;)
7472 | (begin &lt;sequence&gt;)
7473 | (do (&lt;iteration spec&gt;*)
7474 (&lt;test&gt; &lt;do result&gt;)
7475 &lt;command&gt;*)
7476 | (delay &lt;expression&gt;)
7477 | &lt;quasiquotation&gt;
7479 &lt;cond clause&gt; &ndash;&gt; (&lt;test&gt; &lt;sequence&gt;)
7480 | (&lt;test&gt;)
7481 | (&lt;test&gt; =&gt; &lt;recipient&gt;)
7482 &lt;recipient&gt; &ndash;&gt; &lt;expression&gt;
7483 &lt;case clause&gt; &ndash;&gt; ((&lt;datum&gt;*) &lt;sequence&gt;)
7484 &lt;binding spec&gt; &ndash;&gt; (&lt;variable&gt; &lt;expression&gt;)
7485 &lt;iteration spec&gt; &ndash;&gt; (&lt;variable&gt; &lt;init&gt; &lt;step&gt;)
7486 | (&lt;variable&gt; &lt;init&gt;)
7487 &lt;init&gt; &ndash;&gt; &lt;expression&gt;
7488 &lt;step&gt; &ndash;&gt; &lt;expression&gt;
7489 &lt;do result&gt; &ndash;&gt; &lt;sequence&gt; | &lt;empty&gt;
7491 &lt;macro use&gt; &ndash;&gt; (&lt;keyword&gt; &lt;datum&gt;*)
7492 &lt;keyword&gt; &ndash;&gt; &lt;identifier&gt;
7494 &lt;macro block&gt; &ndash;&gt;
7495 (let-syntax (&lt;syntax spec&gt;*) &lt;body&gt;)
7496 | (letrec-syntax (&lt;syntax spec&gt;*) &lt;body&gt;)
7497 &lt;syntax spec&gt; &ndash;&gt; (&lt;keyword&gt; &lt;transformer spec&gt;)
7498 </pre></td></tr></table>
7502 <hr size="1">
7503 <a name="Quasiquotations"></a>
7504 <table cellpadding="1" cellspacing="1" border="0">
7505 <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>
7506 <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>
7507 <td valign="middle" align="left"> &nbsp; </td>
7508 <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>
7509 <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>
7510 <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>
7511 <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>
7512 <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>
7513 <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>
7514 </tr></table>
7515 <a name="Quasiquotations-1"></a>
7516 <h3 class="subsection">7.1.4 Quasiquotations</h3>
7519 <p>The following grammar for quasiquote expressions is not context-free.
7520 It is presented as a recipe for generating an infinite number of
7521 production rules. Imagine a copy of the following rules for D = 1, 2,3, &hellip;. D keeps track of the nesting depth.
7522 </p>
7524 <table><tr><td>&nbsp;</td><td><pre class="format">&lt;quasiquotation&gt; &ndash;&gt; &lt;quasiquotation 1&gt;
7525 &lt;qq template 0&gt; &ndash;&gt; &lt;expression&gt;
7526 &lt;quasiquotation D&gt; &ndash;&gt; &lsquo;&lt;qq template D&gt;
7527 | (quasiquote &lt;qq template D&gt;)
7528 &lt;qq template D&gt; &ndash;&gt; &lt;simple datum&gt;
7529 | &lt;list qq template D&gt;
7530 | &lt;vector qq template D&gt;
7531 | &lt;unquotation D&gt;
7532 &lt;list qq template D&gt; &ndash;&gt; (&lt;qq template or splice D&gt;*)
7533 | (&lt;qq template or splice D&gt;+ . &lt;qq template D&gt;)
7534 | '&lt;qq template D&gt;
7535 | &lt;quasiquotation D+1&gt;
7536 &lt;vector qq template D&gt; &ndash;&gt; #(&lt;qq template or splice D&gt;*)
7537 &lt;unquotation D&gt; &ndash;&gt; ,&lt;qq template D-1&gt;
7538 | (unquote &lt;qq template D-1&gt;)
7539 &lt;qq template or splice D&gt; &ndash;&gt; &lt;qq template D&gt;
7540 | &lt;splicing unquotation D&gt;
7541 &lt;splicing unquotation D&gt; &ndash;&gt; ,@&lt;qq template D-1&gt;
7542 | (unquote-splicing &lt;qq template D-1&gt;)
7543 </pre></td></tr></table>
7547 <p>In &lt;quasiquotation&gt;s, a &lt;list qq template D&gt; can sometimes
7548 be confused with either an &lt;unquotation D&gt; or a &lt;splicing
7549 unquotation D&gt;. The interpretation as an
7550 &lt;unquotation&gt; or &lt;splicing
7551 unquotation D&gt; takes precedence.
7552 </p>
7553 <hr size="1">
7554 <a name="Transformers"></a>
7555 <table cellpadding="1" cellspacing="1" border="0">
7556 <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>
7557 <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>
7558 <td valign="middle" align="left"> &nbsp; </td>
7559 <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>
7560 <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>
7561 <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>
7562 <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>
7563 <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>
7564 <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>
7565 </tr></table>
7566 <a name="Transformers-1"></a>
7567 <h3 class="subsection">7.1.5 Transformers</h3>
7571 <table><tr><td>&nbsp;</td><td><pre class="format">&lt;transformer spec&gt; &ndash;&gt;
7572 (syntax-rules (&lt;identifier&gt;*) &lt;syntax rule&gt;*)
7573 &lt;syntax rule&gt; &ndash;&gt; (&lt;pattern&gt; &lt;template&gt;)
7574 &lt;pattern&gt; &ndash;&gt; &lt;pattern identifier&gt;
7575 | (&lt;pattern&gt;*)
7576 | (&lt;pattern&gt;+ . &lt;pattern&gt;)
7577 | (&lt;pattern&gt;* &lt;pattern&gt; &lt;ellipsis&gt;)
7578 | #(&lt;pattern&gt;*)
7579 | #(&lt;pattern&gt;* &lt;pattern&gt; &lt;ellipsis&gt;)
7580 | &lt;pattern datum&gt;
7581 &lt;pattern datum&gt; &ndash;&gt; &lt;string&gt;
7582 | &lt;character&gt;
7583 | &lt;boolean&gt;
7584 | &lt;number&gt;
7585 &lt;template&gt; &ndash;&gt; &lt;pattern identifier&gt;
7586 | (&lt;template element&gt;*)
7587 | (&lt;template element&gt;+ . &lt;template&gt;)
7588 | #(&lt;template element&gt;*)
7589 | &lt;template datum&gt;
7590 &lt;template element&gt; &ndash;&gt; &lt;template&gt;
7591 | &lt;template&gt; &lt;ellipsis&gt;
7592 &lt;template datum&gt; &ndash;&gt; &lt;pattern datum&gt;
7593 &lt;pattern identifier&gt; &ndash;&gt; &lt;any identifier except <samp>...</samp>&gt;
7594 &lt;ellipsis&gt; &ndash;&gt; &lt;the identifier <samp>...</samp>&gt;
7595 </pre></td></tr></table>
7599 <hr size="1">
7600 <a name="Programs-and-definitions"></a>
7601 <table cellpadding="1" cellspacing="1" border="0">
7602 <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>
7603 <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>
7604 <td valign="middle" align="left"> &nbsp; </td>
7605 <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>
7606 <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>
7607 <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>
7608 <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>
7609 <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>
7610 <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>
7611 </tr></table>
7612 <a name="Programs-and-definitions-1"></a>
7613 <h3 class="subsection">7.1.6 Programs and definitions</h3>
7617 <table><tr><td>&nbsp;</td><td><pre class="format">&lt;program&gt; &ndash;&gt; &lt;command or definition&gt;*
7618 &lt;command or definition&gt; &ndash;&gt; &lt;command&gt;
7619 | &lt;definition&gt;
7620 | &lt;syntax definition&gt;
7621 | (begin &lt;command or definition&gt;+)
7622 &lt;definition&gt; &ndash;&gt; (define &lt;variable&gt; &lt;expression&gt;)
7623 | (define (&lt;variable&gt; &lt;def formals&gt;) &lt;body&gt;)
7624 | (begin &lt;definition&gt;*)
7625 &lt;def formals&gt; &ndash;&gt; &lt;variable&gt;*
7626 | &lt;variable&gt;* . &lt;variable&gt;
7627 &lt;syntax definition&gt; &ndash;&gt;
7628 (define-syntax &lt;keyword&gt; &lt;transformer spec&gt;)
7629 </pre></td></tr></table>
7633 <hr size="1">
7634 <a name="Formal-semantics"></a>
7635 <table cellpadding="1" cellspacing="1" border="0">
7636 <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>
7637 <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>
7638 <td valign="middle" align="left"> &nbsp; </td>
7639 <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>
7640 <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>
7641 <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>
7642 <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>
7643 <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>
7644 <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>
7645 </tr></table>
7646 <a name="Formal-semantics-1"></a>
7647 <h2 class="section">7.2 Formal semantics</h2>
7650 <p>This section provides a formal denotational semantics for the primitive
7651 expressions of Scheme and selected built-in procedures. The concepts
7652 and notation used here are described in <small>[STOY77]</small>.
7653 </p>
7654 <blockquote><p><em>Note:</em> The formal semantics section was written in LaTeX which
7655 is incompatible with TeXinfo. See the Formal semantics section of
7656 the original document from which this was derived.
7657 </p></blockquote>
7660 <hr size="1">
7661 <a name="Derived-expression-type"></a>
7662 <table cellpadding="1" cellspacing="1" border="0">
7663 <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>
7664 <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>
7665 <td valign="middle" align="left"> &nbsp; </td>
7666 <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>
7667 <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>
7668 <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>
7669 <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>
7670 <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>
7671 <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>
7672 </tr></table>
7673 <a name="Derived-expression-types-2"></a>
7674 <h2 class="section">7.3 Derived expression types</h2>
7678 <p>This section gives macro definitions for the derived expression types in
7679 terms of the primitive expression types (literal, variable, call, <samp>lambda</samp>,
7680 <samp>if</samp>, <samp>set!</samp>). See section <a href="#Control-features">Control features</a> for a possible
7681 definition of <samp>delay</samp>.
7682 </p>
7684 <table><tr><td>&nbsp;</td><td><pre class="example">
7685 (define-syntax cond
7686 (syntax-rules (else =&gt;)
7687 ((cond (else result1 result2 ...))
7688 (begin result1 result2 ...))
7689 ((cond (test =&gt; result))
7690 (let ((temp test))
7691 (if temp (result temp))))
7692 ((cond (test =&gt; result) clause1 clause2 ...)
7693 (let ((temp test))
7694 (if temp
7695 (result temp)
7696 (cond clause1 clause2 ...))))
7697 ((cond (test)) test)
7698 ((cond (test) clause1 clause2 ...)
7699 (let ((temp test))
7700 (if temp
7701 temp
7702 (cond clause1 clause2 ...))))
7703 ((cond (test result1 result2 ...))
7704 (if test (begin result1 result2 ...)))
7705 ((cond (test result1 result2 ...)
7706 clause1 clause2 ...)
7707 (if test
7708 (begin result1 result2 ...)
7709 (cond clause1 clause2 ...)))))
7710 </pre></td></tr></table>
7714 <table><tr><td>&nbsp;</td><td><pre class="example">
7715 (define-syntax case
7716 (syntax-rules (else)
7717 ((case (key ...)
7718 clauses ...)
7719 (let ((atom-key (key ...)))
7720 (case atom-key clauses ...)))
7721 ((case key
7722 (else result1 result2 ...))
7723 (begin result1 result2 ...))
7724 ((case key
7725 ((atoms ...) result1 result2 ...))
7726 (if (memv key '(atoms ...))
7727 (begin result1 result2 ...)))
7728 ((case key
7729 ((atoms ...) result1 result2 ...)
7730 clause clauses ...)
7731 (if (memv key '(atoms ...))
7732 (begin result1 result2 ...)
7733 (case key clause clauses ...)))))
7734 </pre></td></tr></table>
7738 <table><tr><td>&nbsp;</td><td><pre class="example">
7739 (define-syntax and
7740 (syntax-rules ()
7741 ((and) #t)
7742 ((and test) test)
7743 ((and test1 test2 ...)
7744 (if test1 (and test2 ...) #f))))
7745 </pre></td></tr></table>
7749 <table><tr><td>&nbsp;</td><td><pre class="example">
7750 (define-syntax or
7751 (syntax-rules ()
7752 ((or) #f)
7753 ((or test) test)
7754 ((or test1 test2 ...)
7755 (let ((x test1))
7756 (if x x (or test2 ...))))))
7757 </pre></td></tr></table>
7761 <table><tr><td>&nbsp;</td><td><pre class="example">
7762 (define-syntax let
7763 (syntax-rules ()
7764 ((let ((name val) ...) body1 body2 ...)
7765 ((lambda (name ...) body1 body2 ...)
7766 val ...))
7767 ((let tag ((name val) ...) body1 body2 ...)
7768 ((letrec ((tag (lambda (name ...)
7769 body1 body2 ...)))
7770 tag)
7771 val ...))))
7772 </pre></td></tr></table>
7776 <table><tr><td>&nbsp;</td><td><pre class="example">
7777 (define-syntax let*
7778 (syntax-rules ()
7779 ((let* () body1 body2 ...)
7780 (let () body1 body2 ...))
7781 ((let* ((name1 val1) (name2 val2) ...)
7782 body1 body2 ...)
7783 (let ((name1 val1))
7784 (let* ((name2 val2) ...)
7785 body1 body2 ...)))))
7786 </pre></td></tr></table>
7789 <p>The following <samp>letrec</samp> macro uses the symbol <samp>&lt;undefined&gt;</samp>
7790 in place of an expression which returns something that when stored in
7791 a location makes it an error to try to obtain the value stored in the
7792 location (no such expression is defined in Scheme).
7793 A trick is used to generate the temporary names needed to avoid
7794 specifying the order in which the values are evaluated.
7795 This could also be accomplished by using an auxiliary macro.
7796 </p>
7798 <table><tr><td>&nbsp;</td><td><pre class="example">
7799 (define-syntax letrec
7800 (syntax-rules ()
7801 ((letrec ((var1 init1) ...) body ...)
7802 (letrec &quot;generate temp names&quot;
7803 (var1 ...)
7805 ((var1 init1) ...)
7806 body ...))
7807 ((letrec &quot;generate temp names&quot;
7809 (temp1 ...)
7810 ((var1 init1) ...)
7811 body ...)
7812 (let ((var1 &lt;undefined&gt;) ...)
7813 (let ((temp1 init1) ...)
7814 (set! var1 temp1)
7816 body ...)))
7817 ((letrec &quot;generate temp names&quot;
7818 (x y ...)
7819 (temp ...)
7820 ((var1 init1) ...)
7821 body ...)
7822 (letrec &quot;generate temp names&quot;
7823 (y ...)
7824 (newtemp temp ...)
7825 ((var1 init1) ...)
7826 body ...))))
7827 </pre></td></tr></table>
7831 <table><tr><td>&nbsp;</td><td><pre class="example">
7832 (define-syntax begin
7833 (syntax-rules ()
7834 ((begin exp ...)
7835 ((lambda () exp ...)))))
7836 </pre></td></tr></table>
7839 <p>The following alternative expansion for <samp>begin</samp> does not make use of
7840 the ability to write more than one expression in the body of a lambda
7841 expression. In any case, note that these rules apply only if the body
7842 of the <samp>begin</samp> contains no definitions.
7843 </p>
7845 <table><tr><td>&nbsp;</td><td><pre class="example">
7846 (define-syntax begin
7847 (syntax-rules ()
7848 ((begin exp)
7849 exp)
7850 ((begin exp1 exp2 ...)
7851 (let ((x exp1))
7852 (begin exp2 ...)))))
7853 </pre></td></tr></table>
7856 <p>The following definition
7857 of <samp>do</samp> uses a trick to expand the variable clauses.
7858 As with <samp>letrec</samp> above, an auxiliary macro would also work.
7859 The expression <samp>(if #f #f)</samp> is used to obtain an unspecific
7860 value.
7861 </p>
7863 <table><tr><td>&nbsp;</td><td><pre class="example">
7864 (define-syntax do
7865 (syntax-rules ()
7866 ((do ((var init step ...) ...)
7867 (test expr ...)
7868 command ...)
7869 (letrec
7870 ((loop
7871 (lambda (var ...)
7872 (if test
7873 (begin
7874 (if #f #f)
7875 expr ...)
7876 (begin
7877 command
7879 (loop (do &quot;step&quot; var step ...)
7880 ...))))))
7881 (loop init ...)))
7882 ((do &quot;step&quot; x)
7884 ((do &quot;step&quot; x y)
7885 y)))
7886 </pre></td></tr></table>
7892 <hr size="1">
7893 <a name="Notes"></a>
7894 <table cellpadding="1" cellspacing="1" border="0">
7895 <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>
7896 <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>
7897 <td valign="middle" align="left"> &nbsp; </td>
7898 <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>
7899 <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>
7900 <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>
7901 <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>
7902 <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>
7903 <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>
7904 </tr></table>
7905 <a name="Notes-1"></a>
7906 <h1 class="unnumbered">Notes</h1>
7908 <table class="menu" border="0" cellspacing="0">
7909 <tr><td align="left" valign="top"><a href="#Language-changes">Language changes</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
7910 </td></tr>
7911 </table>
7917 <hr size="1">
7918 <a name="Language-changes"></a>
7919 <table cellpadding="1" cellspacing="1" border="0">
7920 <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>
7921 <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>
7922 <td valign="middle" align="left"> &nbsp; </td>
7923 <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>
7924 <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>
7925 <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>
7926 <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>
7927 <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>
7928 <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>
7929 </tr></table>
7930 <a name="Language-changes-1"></a>
7931 <h2 class="unnumberedsec">Language changes</h2>
7935 <p>This section enumerates the changes that have been made to Scheme since
7936 the &ldquo;Revised^4 report&rdquo; [R4RS] was published.
7937 </p>
7940 <ul>
7941 <li>
7942 The report is now a superset of the IEEE standard for Scheme
7943 [IEEEScheme]: implementations that conform to the report will
7944 also conform to the standard. This required the following changes:
7947 <ul>
7948 <li>
7949 The empty list is now required to count as true.
7951 </li><li>
7952 The classification of features as essential or inessential has been
7953 removed. There are now three classes of built-in procedures: primitive,
7954 library, and optional. The optional procedures are <samp>load</samp>,
7955 <samp>with-input-from-file</samp>, <samp>with-output-to-file</samp>,
7956 <samp>transcript-on</samp>, <samp>transcript-off</samp>, and
7957 <samp>interaction-environment</samp>,
7958 and <samp>-</samp> and <samp>/</samp> with more than two arguments.
7959 None of these are in the IEEE standard.
7961 </li><li>
7962 Programs are allowed to redefine built-in procedures. Doing so
7963 will not change the behavior of other built-in procedures.
7965 </li></ul>
7968 </li><li>
7969 <em>Port</em> has been added to the list of disjoint types.
7971 </li><li>
7972 The macro appendix has been removed. High-level macros are now part
7973 of the main body of the report. The rewrite rules for derived expressions
7974 have been replaced with macro definitions. There are no reserved identifiers.
7976 </li><li>
7977 <samp>Syntax-rules</samp> now allows vector patterns.
7979 </li><li>
7980 Multiple-value returns, <samp>eval</samp>, and <samp>dynamic-wind</samp> have
7981 been added.
7983 </li><li>
7984 The calls that are required to be implemented in a properly tail-recursive
7985 fashion are defined explicitly.
7987 </li><li>
7988 &lsquo;<samp>@</samp>' can be used within identifiers. &lsquo;<samp>|</samp>' is reserved
7989 for possible future extensions.
7992 </li></ul>
8008 <hr size="1">
8009 <a name="Additional-material"></a>
8010 <table cellpadding="1" cellspacing="1" border="0">
8011 <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>
8012 <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>
8013 <td valign="middle" align="left"> &nbsp; </td>
8014 <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>
8015 <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>
8016 <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>
8017 <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>
8018 <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>
8019 <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>
8020 </tr></table>
8021 <a name="Additional-material-1"></a>
8022 <h1 class="unnumbered">Additional material</h1>
8025 <p>The Internet Scheme Repository at
8026 </p>
8028 <p align="center"> <a href="http://www.cs.indiana.edu/scheme-repository/">http://www.cs.indiana.edu/scheme-repository/</a>
8029 </p>
8031 <p>contains an extensive Scheme bibliography, as well as papers,
8032 programs, implementations, and other material related to Scheme.
8033 </p>
8037 <hr size="1">
8038 <a name="Example"></a>
8039 <table cellpadding="1" cellspacing="1" border="0">
8040 <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>
8041 <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>
8042 <td valign="middle" align="left"> &nbsp; </td>
8043 <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>
8044 <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>
8045 <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>
8046 <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>
8047 <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>
8048 <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>
8049 </tr></table>
8050 <a name="Example-1"></a>
8051 <h1 class="unnumbered">Example</h1>
8055 <p><samp>Integrate-system</samp> integrates the system
8056 </p>
8058 <p align="center"> y_k^^ = f_k(y_1, y_2, &hellip; y_n), k = 1, &hellip; n
8059 </p>
8060 <p>of differential equations with the method of Runge-Kutta.
8061 </p>
8062 <p>The parameter <tt>system-derivative</tt> is a function that takes a system
8063 state (a vector of values for the state variables y_1, &hellip; y_n)
8064 and produces a system derivative (the values y_1^^, &hellip;y_n^^). The parameter <tt>initial-state</tt> provides an initial
8065 system state, and <tt>h</tt> is an initial guess for the length of the
8066 integration step.
8067 </p>
8068 <p>The value returned by <samp>integrate-system</samp> is an infinite stream of
8069 system states.
8070 </p>
8072 <table><tr><td>&nbsp;</td><td><pre class="example">
8073 (define integrate-system
8074 (lambda (system-derivative initial-state h)
8075 (let ((next (runge-kutta-4 system-derivative h)))
8076 (letrec ((states
8077 (cons initial-state
8078 (delay (map-streams next
8079 states)))))
8080 states))))
8081 </pre></td></tr></table>
8084 <p><samp>Runge-Kutta-4</samp> takes a function, <tt>f</tt>, that produces a
8085 system derivative from a system state. <samp>Runge-Kutta-4</samp>
8086 produces a function that takes a system state and
8087 produces a new system state.
8088 </p>
8090 <table><tr><td>&nbsp;</td><td><pre class="example">
8091 (define runge-kutta-4
8092 (lambda (f h)
8093 (let ((*h (scale-vector h))
8094 (*2 (scale-vector 2))
8095 (*1/2 (scale-vector (/ 1 2)))
8096 (*1/6 (scale-vector (/ 1 6))))
8097 (lambda (y)
8098 ;; y <span class="roman"></span>is a system state
8099 (let* ((k0 (*h (f y)))
8100 (k1 (*h (f (add-vectors y (*1/2 k0)))))
8101 (k2 (*h (f (add-vectors y (*1/2 k1)))))
8102 (k3 (*h (f (add-vectors y k2)))))
8103 (add-vectors y
8104 (*1/6 (add-vectors k0
8105 (*2 k1)
8106 (*2 k2)
8107 k3))))))))
8109 (define elementwise
8110 (lambda (f)
8111 (lambda vectors
8112 (generate-vector
8113 (vector-length (car vectors))
8114 (lambda (i)
8115 (apply f
8116 (map (lambda (v) (vector-ref v i))
8117 vectors)))))))
8119 (define generate-vector
8120 (lambda (size proc)
8121 (let ((ans (make-vector size)))
8122 (letrec ((loop
8123 (lambda (i)
8124 (cond ((= i size) ans)
8125 (else
8126 (vector-set! ans i (proc i))
8127 (loop (+ i 1)))))))
8128 (loop 0)))))
8130 (define add-vectors (elementwise +))
8132 (define scale-vector
8133 (lambda (s)
8134 (elementwise (lambda (x) (* x s)))))
8135 </pre></td></tr></table>
8138 <p><samp>Map-streams</samp> is analogous to <samp>map</samp>: it applies its first
8139 argument (a procedure) to all the elements of its second argument (a
8140 stream).
8141 </p>
8143 <table><tr><td>&nbsp;</td><td><pre class="example">
8144 (define map-streams
8145 (lambda (f s)
8146 (cons (f (head s))
8147 (delay (map-streams f (tail s))))))
8148 </pre></td></tr></table>
8151 <p>Infinite streams are implemented as pairs whose car holds the first
8152 element of the stream and whose cdr holds a promise to deliver the rest
8153 of the stream.
8154 </p>
8156 <table><tr><td>&nbsp;</td><td><pre class="example">
8157 (define head car)
8158 (define tail
8159 (lambda (stream) (force (cdr stream))))
8160 </pre></td></tr></table>
8163 <br>
8164 <br>
8165 <br>
8166 <br>
8167 <br>
8168 <br>
8169 <p>The following illustrates the use of <samp>integrate-system</samp> in
8170 integrating the system
8171 </p>
8173 <p align="center"> C dv_C / dt = -i_L - v_C / R
8174 </p>
8177 <p align="center"> L di_L / dt = v_C
8178 </p>
8179 <p>which models a damped oscillator.
8180 </p>
8182 <table><tr><td>&nbsp;</td><td><pre class="example">
8183 (define damped-oscillator
8184 (lambda (R L C)
8185 (lambda (state)
8186 (let ((Vc (vector-ref state 0))
8187 (Il (vector-ref state 1)))
8188 (vector (- 0 (+ (/ Vc (* R C)) (/ Il C)))
8189 (/ Vc L))))))
8191 (define the-states
8192 (integrate-system
8193 (damped-oscillator 10000 1000 .001)
8194 '#(1 0)
8195 .01))
8196 </pre></td></tr></table>
8210 <hr size="1">
8211 <a name="Bibliography"></a>
8212 <table cellpadding="1" cellspacing="1" border="0">
8213 <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>
8214 <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>
8215 <td valign="middle" align="left"> &nbsp; </td>
8216 <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>
8217 <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>
8218 <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>
8219 <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>
8220 <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>
8221 <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>
8222 </tr></table>
8223 <a name="Bibliography-1"></a>
8224 <h1 class="unnumbered">Bibliography</h1>
8227 <ul>
8228 <li> [SICP]
8229 <a name="index-SICP"></a>
8230 Harold Abelson and Gerald Jay Sussman with Julie Sussman.
8231 <em>Structure and Interpretation of Computer Programs, second edition.</em>
8232 MIT Press, Cambridge, 1996.
8234 </li><li> [Bawden88]
8235 Alan Bawden and Jonathan Rees.
8236 <a name="index-Bawden88"></a>
8237 Syntactic closures.
8238 In <em>Proceedings of the 1988 ACM Symposium on Lisp and
8239 Functional Programming</em>, pages 86&ndash;95.
8241 </li><li> [howtoprint]
8242 <a name="index-howtoprint"></a>
8243 Robert G. Burger and R. Kent Dybvig.
8244 Printing floating-point numbers quickly and accurately.
8245 In <em>Proceedings of the ACM SIGPLAN '96 Conference
8246 on Programming Language Design and Implementation</em>, pages 108&ndash;116.
8248 </li><li> [RRRS]
8249 <a name="index-RRRS"></a>
8250 William Clinger, editor.
8251 The revised revised report on Scheme, or an uncommon Lisp.
8252 MIT Artificial Intelligence Memo 848, August 1985.
8253 Also published as Computer Science Department Technical Report 174,
8254 Indiana University, June 1985.
8256 </li><li> [howtoread]
8257 William Clinger.
8258 <a name="index-howtoread"></a>
8259 How to read floating point numbers accurately.
8260 In <em>Proceedings of the ACM SIGPLAN '90 Conference
8261 on Programming Language Design and Implementation</em>, pages 92&ndash;101.
8262 Proceedings published as <em>SIGPLAN Notices</em> 25(6), June 1990.
8264 </li><li> [R4RS]
8265 <a name="index-R4RS"></a>
8266 William Clinger and Jonathan Rees, editors.
8267 The revised^4 report on the algorithmic language Scheme.
8268 In <em>ACM Lisp Pointers</em> 4(3), pages 1&ndash;55, 1991.
8270 </li><li> [macrosthatwork]
8271 William Clinger and Jonathan Rees.
8272 <a name="index-macrosthatwork"></a>
8273 Macros that work.
8274 In <em>Proceedings of the 1991 ACM Conference on Principles of
8275 Programming Languages</em>, pages 155&ndash;162.
8277 </li><li> [propertailrecursion]
8278 William Clinger.
8279 <a name="index-propertailrecursion"></a>
8280 Proper Tail Recursion and Space Efficiency.
8281 To appear in <em>Proceedings of the 1998 ACM Conference on Programming
8282 Language Design and Implementation</em>, June 1998.
8284 </li><li> [syntacticabstraction]
8285 <a name="index-syntacticabstraction"></a>
8286 R. Kent Dybvig, Robert Hieb, and Carl Bruggeman.
8287 Syntactic abstraction in Scheme.
8288 <em>Lisp and Symbolic Computation</em> 5(4):295&ndash;326, 1993.
8290 </li><li> [Scheme311]
8291 <a name="index-Scheme311"></a>
8292 Carol Fessenden, William Clinger, Daniel P. Friedman, and Christopher Haynes.
8293 Scheme 311 version 4 reference manual.
8294 Indiana University Computer Science Technical Report 137, February 1983.
8295 Superseded by [Scheme84].
8297 </li><li> [Scheme84]
8298 <a name="index-Scheme84"></a>
8299 D. Friedman, C. Haynes, E. Kohlbecker, and M. Wand.
8300 Scheme 84 interim reference manual.
8301 Indiana University Computer Science Technical Report 153, January 1985.
8303 </li><li> [IEEE]
8304 <a name="index-IEEE"></a>
8305 <em>IEEE Standard 754-1985. IEEE Standard for Binary Floating-Point
8306 Arithmetic.</em> IEEE, New York, 1985.
8308 </li><li> [IEEEScheme]
8309 <a name="index-IEEEScheme"></a>
8310 <em>IEEE Standard 1178-1990. IEEE Standard for the Scheme
8311 Programming Language.</em> IEEE, New York, 1991.
8313 </li><li> [Kohlbecker86]
8314 <a name="index-Kohlbecker86"></a>
8315 Eugene E. Kohlbecker Jr.
8316 <em>Syntactic Extensions in the Programming Language Lisp.</em>
8317 PhD thesis, Indiana University, August 1986.
8319 </li><li> [hygienic]
8320 <a name="index-hygienic-1"></a>
8321 Eugene E. Kohlbecker Jr., Daniel P. Friedman, Matthias Felleisen, and Bruce Duba.
8322 Hygienic macro expansion.
8323 In <em>Proceedings of the 1986 ACM Conference on Lisp
8324 and Functional Programming</em>, pages 151&ndash;161.
8326 </li><li> [Landin65]
8327 <a name="index-Landin65"></a>
8328 Peter Landin.
8329 A correspondence between Algol 60 and Church's lambda notation: Part I.
8330 <em>Communications of the ACM</em> 8(2):89&ndash;101, February 1965.
8332 </li><li> [MITScheme]
8333 <a name="index-MITScheme"></a>
8334 MIT Department of Electrical Engineering and Computer Science.
8335 Scheme manual, seventh edition.
8336 September 1984.
8338 </li><li> [Naur63]
8339 <a name="index-Naur63"></a>
8340 Peter Naur et al.
8341 Revised report on the algorithmic language Algol 60.
8342 <em>Communications of the ACM</em> 6(1):1&ndash;17, January 1963.
8344 </li><li> [Penfield81]
8345 <a name="index-Penfield81"></a>
8346 Paul Penfield, Jr.
8347 Principal values and branch cuts in complex APL.
8348 In <em>APL '81 Conference Proceedings,</em> pages 248&ndash;256.
8349 ACM SIGAPL, San Francisco, September 1981.
8350 Proceedings published as <em>APL Quote Quad</em> 12(1), ACM, September 1981.
8352 </li><li> [Pitman83]
8353 <a name="index-Pitman83"></a>
8354 Kent M. Pitman.
8355 The revised MacLisp manual (Saturday evening edition).
8356 MIT Laboratory for Computer Science Technical Report 295, May 1983.
8358 </li><li> [Rees82]
8359 <a name="index-Rees82"></a>
8360 Jonathan A. Rees and Norman I. Adams IV.
8361 T: A dialect of Lisp or, lambda: The ultimate software tool.
8362 In <em>Conference Record of the 1982 ACM Symposium on Lisp and
8363 Functional Programming</em>, pages 114&ndash;122.
8365 </li><li> [Rees84]
8366 <a name="index-Rees84"></a>
8367 Jonathan A. Rees, Norman I. Adams IV, and James R. Meehan.
8368 The T manual, fourth edition.
8369 Yale University Computer Science Department, January 1984.
8371 </li><li> [R3RS]
8372 <a name="index-R3RS"></a>
8373 Jonathan Rees and William Clinger, editors.
8374 The revised^3 report on the algorithmic language Scheme.
8375 In <em>ACM SIGPLAN Notices</em> 21(12), pages 37&ndash;79, December 1986.
8377 </li><li> [Reynolds72]
8378 <a name="index-Reynolds72"></a>
8379 John Reynolds.
8380 Definitional interpreters for higher order programming languages.
8381 In <em>ACM Conference Proceedings</em>, pages 717&ndash;740.
8382 ACM,
8383 1972.
8385 </li><li> [Scheme78]
8386 <a name="index-Scheme78"></a>
8387 Guy Lewis Steele Jr. and Gerald Jay Sussman.
8388 The revised report on Scheme, a dialect of Lisp.
8389 MIT Artificial Intelligence Memo 452, January 1978.
8391 </li><li> [Rabbit]
8392 <a name="index-Rabbit"></a>
8393 Guy Lewis Steele Jr.
8394 Rabbit: a compiler for Scheme.
8395 MIT Artificial Intelligence Laboratory Technical Report 474, May 1978.
8397 </li><li> [CLtL]
8398 <a name="index-CLtL"></a>
8399 Guy Lewis Steele Jr.
8400 <em>Common Lisp: The Language, second edition.</em>
8401 Digital Press, Burlington MA, 1990.
8403 </li><li> [Scheme75]
8404 <a name="index-Scheme75"></a>
8405 Gerald Jay Sussman and Guy Lewis Steele Jr.
8406 Scheme: an interpreter for extended lambda calculus.
8407 MIT Artificial Intelligence Memo 349, December 1975.
8409 </li><li> [Stoy77]
8410 <a name="index-Stoy77"></a>
8411 Joseph E. Stoy.
8412 <em>Denotational Semantics: The Scott-Strachey Approach to
8413 Programming Language Theory.</em>
8414 MIT Press, Cambridge, 1977.
8416 </li><li> [TImanual85]
8417 <a name="index-TImanual85"></a>
8418 Texas Instruments, Inc.
8419 TI Scheme Language Reference Manual.
8420 Preliminary version 1.0, November 1985.
8422 </li></ul>
8431 <hr size="1">
8432 <a name="Index"></a>
8433 <table cellpadding="1" cellspacing="1" border="0">
8434 <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>
8435 <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>
8436 <td valign="middle" align="left"> &nbsp; </td>
8437 <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>
8438 <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>
8439 <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>
8440 <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>
8441 <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>
8442 <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>
8443 </tr></table>
8444 <a name="Alphabetic-index-of-definitions-of-concepts_002c-keywords_002c-and-procedures"></a>
8445 <h1 class="unnumbered">Alphabetic index of definitions of concepts, keywords, and procedures</h1>
8449 <p>The principal entry for each term, procedure, or keyword is listed
8450 first, separated from the other entries by a semicolon.
8451 </p>
8452 <br>
8453 <br>
8454 <br>
8455 <br>
8456 <br>
8457 <br>
8459 <hr size="1">
8460 <a name="Concepts"></a>
8461 <table cellpadding="1" cellspacing="1" border="0">
8462 <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>
8463 <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>
8464 <td valign="middle" align="left"> &nbsp; </td>
8465 <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>
8466 <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>
8467 <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>
8468 <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>
8469 <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>
8470 <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>
8471 </tr></table>
8472 <h2 class="unnumberedsec">Concepts</h2>
8473 <table><tr><th valign="top">Jump to: &nbsp; </th><td><a href="#Concepts_cp_symbol-1" class="summary-letter"><b>'</b></a>
8474 &nbsp;
8475 <a href="#Concepts_cp_symbol-2" class="summary-letter"><b>,</b></a>
8476 &nbsp;
8477 <a href="#Concepts_cp_symbol-3" class="summary-letter"><b>;</b></a>
8478 &nbsp;
8479 <a href="#Concepts_cp_symbol-4" class="summary-letter"><b>=</b></a>
8480 &nbsp;
8481 <a href="#Concepts_cp_symbol-5" class="summary-letter"><b>`</b></a>
8482 &nbsp;
8483 <br>
8484 <a href="#Concepts_cp_letter-B" class="summary-letter"><b>B</b></a>
8485 &nbsp;
8486 <a href="#Concepts_cp_letter-C" class="summary-letter"><b>C</b></a>
8487 &nbsp;
8488 <a href="#Concepts_cp_letter-D" class="summary-letter"><b>D</b></a>
8489 &nbsp;
8490 <a href="#Concepts_cp_letter-E" class="summary-letter"><b>E</b></a>
8491 &nbsp;
8492 <a href="#Concepts_cp_letter-F" class="summary-letter"><b>F</b></a>
8493 &nbsp;
8494 <a href="#Concepts_cp_letter-H" class="summary-letter"><b>H</b></a>
8495 &nbsp;
8496 <a href="#Concepts_cp_letter-I" class="summary-letter"><b>I</b></a>
8497 &nbsp;
8498 <a href="#Concepts_cp_letter-K" class="summary-letter"><b>K</b></a>
8499 &nbsp;
8500 <a href="#Concepts_cp_letter-L" class="summary-letter"><b>L</b></a>
8501 &nbsp;
8502 <a href="#Concepts_cp_letter-M" class="summary-letter"><b>M</b></a>
8503 &nbsp;
8504 <a href="#Concepts_cp_letter-N" class="summary-letter"><b>N</b></a>
8505 &nbsp;
8506 <a href="#Concepts_cp_letter-O" class="summary-letter"><b>O</b></a>
8507 &nbsp;
8508 <a href="#Concepts_cp_letter-P" class="summary-letter"><b>P</b></a>
8509 &nbsp;
8510 <a href="#Concepts_cp_letter-R" class="summary-letter"><b>R</b></a>
8511 &nbsp;
8512 <a href="#Concepts_cp_letter-S" class="summary-letter"><b>S</b></a>
8513 &nbsp;
8514 <a href="#Concepts_cp_letter-T" class="summary-letter"><b>T</b></a>
8515 &nbsp;
8516 <a href="#Concepts_cp_letter-U" class="summary-letter"><b>U</b></a>
8517 &nbsp;
8518 <a href="#Concepts_cp_letter-V" class="summary-letter"><b>V</b></a>
8519 &nbsp;
8520 <a href="#Concepts_cp_letter-W" class="summary-letter"><b>W</b></a>
8521 &nbsp;
8522 </td></tr></table>
8523 <table border="0" class="index-cp">
8524 <tr><td></td><th align="left">Index Entry</th><th align="left"> Section</th></tr>
8525 <tr><td colspan="3"> <hr></td></tr>
8526 <tr><th><a name="Concepts_cp_symbol-1">'</a></th><td></td><td></td></tr>
8527 <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>
8528 <tr><td colspan="3"> <hr></td></tr>
8529 <tr><th><a name="Concepts_cp_symbol-2">,</a></th><td></td><td></td></tr>
8530 <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>
8531 <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>
8532 <tr><td colspan="3"> <hr></td></tr>
8533 <tr><th><a name="Concepts_cp_symbol-3">;</a></th><td></td><td></td></tr>
8534 <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>
8535 <tr><td colspan="3"> <hr></td></tr>
8536 <tr><th><a name="Concepts_cp_symbol-4">=</a></th><td></td><td></td></tr>
8537 <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>
8538 <tr><td colspan="3"> <hr></td></tr>
8539 <tr><th><a name="Concepts_cp_symbol-5">`</a></th><td></td><td></td></tr>
8540 <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>
8541 <tr><td colspan="3"> <hr></td></tr>
8542 <tr><th><a name="Concepts_cp_letter-B">B</a></th><td></td><td></td></tr>
8543 <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>
8544 <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>
8545 <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>
8546 <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>
8547 <tr><td colspan="3"> <hr></td></tr>
8548 <tr><th><a name="Concepts_cp_letter-C">C</a></th><td></td><td></td></tr>
8549 <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>
8550 <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>
8551 <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>
8552 <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>
8553 <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>
8554 <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>
8555 <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>
8556 <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>
8557 <tr><td colspan="3"> <hr></td></tr>
8558 <tr><th><a name="Concepts_cp_letter-D">D</a></th><td></td><td></td></tr>
8559 <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>
8560 <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>
8561 <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>
8562 <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>
8563 <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>
8564 <tr><td colspan="3"> <hr></td></tr>
8565 <tr><th><a name="Concepts_cp_letter-E">E</a></th><td></td><td></td></tr>
8566 <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>
8567 <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>
8568 <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>
8569 <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>
8570 <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>
8571 <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>
8572 <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>
8573 <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>
8574 <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>
8575 <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>
8576 <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>
8577 <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>
8578 <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>
8579 <tr><td colspan="3"> <hr></td></tr>
8580 <tr><th><a name="Concepts_cp_letter-F">F</a></th><td></td><td></td></tr>
8581 <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>
8582 <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>
8583 <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>
8584 <tr><td colspan="3"> <hr></td></tr>
8585 <tr><th><a name="Concepts_cp_letter-H">H</a></th><td></td><td></td></tr>
8586 <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>
8587 <tr><td colspan="3"> <hr></td></tr>
8588 <tr><th><a name="Concepts_cp_letter-I">I</a></th><td></td><td></td></tr>
8589 <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>
8590 <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>
8591 <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>
8592 <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>
8593 <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>
8594 <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>
8595 <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>
8596 <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>
8597 <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>
8598 <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>
8599 <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>
8600 <tr><td colspan="3"> <hr></td></tr>
8601 <tr><th><a name="Concepts_cp_letter-K">K</a></th><td></td><td></td></tr>
8602 <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>
8603 <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>
8604 <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>
8605 <tr><td colspan="3"> <hr></td></tr>
8606 <tr><th><a name="Concepts_cp_letter-L">L</a></th><td></td><td></td></tr>
8607 <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>
8608 <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>
8609 <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>
8610 <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>
8611 <tr><td colspan="3"> <hr></td></tr>
8612 <tr><th><a name="Concepts_cp_letter-M">M</a></th><td></td><td></td></tr>
8613 <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>
8614 <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>
8615 <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>
8616 <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>
8617 <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>
8618 <tr><td colspan="3"> <hr></td></tr>
8619 <tr><th><a name="Concepts_cp_letter-N">N</a></th><td></td><td></td></tr>
8620 <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>
8621 <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>
8622 <tr><td colspan="3"> <hr></td></tr>
8623 <tr><th><a name="Concepts_cp_letter-O">O</a></th><td></td><td></td></tr>
8624 <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>
8625 <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>
8626 <tr><td colspan="3"> <hr></td></tr>
8627 <tr><th><a name="Concepts_cp_letter-P">P</a></th><td></td><td></td></tr>
8628 <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>
8629 <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>
8630 <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>
8631 <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>
8632 <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>
8633 <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>
8634 <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>
8635 <tr><td colspan="3"> <hr></td></tr>
8636 <tr><th><a name="Concepts_cp_letter-R">R</a></th><td></td><td></td></tr>
8637 <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>
8638 <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>
8639 <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>
8640 <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>
8641 <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>
8642 <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>
8643 <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>
8644 <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>
8645 <tr><td colspan="3"> <hr></td></tr>
8646 <tr><th><a name="Concepts_cp_letter-S">S</a></th><td></td><td></td></tr>
8647 <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>
8648 <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>
8649 <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>
8650 <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>
8651 <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>
8652 <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>
8653 <tr><td colspan="3"> <hr></td></tr>
8654 <tr><th><a name="Concepts_cp_letter-T">T</a></th><td></td><td></td></tr>
8655 <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>
8656 <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>
8657 <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>
8658 <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>
8659 <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>
8660 <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>
8661 <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>
8662 <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>
8663 <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>
8664 <tr><td colspan="3"> <hr></td></tr>
8665 <tr><th><a name="Concepts_cp_letter-U">U</a></th><td></td><td></td></tr>
8666 <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>
8667 <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>
8668 <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>
8669 <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>
8670 <tr><td colspan="3"> <hr></td></tr>
8671 <tr><th><a name="Concepts_cp_letter-V">V</a></th><td></td><td></td></tr>
8672 <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>
8673 <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>
8674 <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>
8675 <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>
8676 <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>
8677 <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>
8678 <tr><td colspan="3"> <hr></td></tr>
8679 <tr><th><a name="Concepts_cp_letter-W">W</a></th><td></td><td></td></tr>
8680 <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>
8681 <tr><td colspan="3"> <hr></td></tr>
8682 </table>
8683 <table><tr><th valign="top">Jump to: &nbsp; </th><td><a href="#Concepts_cp_symbol-1" class="summary-letter"><b>'</b></a>
8684 &nbsp;
8685 <a href="#Concepts_cp_symbol-2" class="summary-letter"><b>,</b></a>
8686 &nbsp;
8687 <a href="#Concepts_cp_symbol-3" class="summary-letter"><b>;</b></a>
8688 &nbsp;
8689 <a href="#Concepts_cp_symbol-4" class="summary-letter"><b>=</b></a>
8690 &nbsp;
8691 <a href="#Concepts_cp_symbol-5" class="summary-letter"><b>`</b></a>
8692 &nbsp;
8693 <br>
8694 <a href="#Concepts_cp_letter-B" class="summary-letter"><b>B</b></a>
8695 &nbsp;
8696 <a href="#Concepts_cp_letter-C" class="summary-letter"><b>C</b></a>
8697 &nbsp;
8698 <a href="#Concepts_cp_letter-D" class="summary-letter"><b>D</b></a>
8699 &nbsp;
8700 <a href="#Concepts_cp_letter-E" class="summary-letter"><b>E</b></a>
8701 &nbsp;
8702 <a href="#Concepts_cp_letter-F" class="summary-letter"><b>F</b></a>
8703 &nbsp;
8704 <a href="#Concepts_cp_letter-H" class="summary-letter"><b>H</b></a>
8705 &nbsp;
8706 <a href="#Concepts_cp_letter-I" class="summary-letter"><b>I</b></a>
8707 &nbsp;
8708 <a href="#Concepts_cp_letter-K" class="summary-letter"><b>K</b></a>
8709 &nbsp;
8710 <a href="#Concepts_cp_letter-L" class="summary-letter"><b>L</b></a>
8711 &nbsp;
8712 <a href="#Concepts_cp_letter-M" class="summary-letter"><b>M</b></a>
8713 &nbsp;
8714 <a href="#Concepts_cp_letter-N" class="summary-letter"><b>N</b></a>
8715 &nbsp;
8716 <a href="#Concepts_cp_letter-O" class="summary-letter"><b>O</b></a>
8717 &nbsp;
8718 <a href="#Concepts_cp_letter-P" class="summary-letter"><b>P</b></a>
8719 &nbsp;
8720 <a href="#Concepts_cp_letter-R" class="summary-letter"><b>R</b></a>
8721 &nbsp;
8722 <a href="#Concepts_cp_letter-S" class="summary-letter"><b>S</b></a>
8723 &nbsp;
8724 <a href="#Concepts_cp_letter-T" class="summary-letter"><b>T</b></a>
8725 &nbsp;
8726 <a href="#Concepts_cp_letter-U" class="summary-letter"><b>U</b></a>
8727 &nbsp;
8728 <a href="#Concepts_cp_letter-V" class="summary-letter"><b>V</b></a>
8729 &nbsp;
8730 <a href="#Concepts_cp_letter-W" class="summary-letter"><b>W</b></a>
8731 &nbsp;
8732 </td></tr></table>
8734 <hr size="1">
8735 <a name="Procedures-1"></a>
8736 <table cellpadding="1" cellspacing="1" border="0">
8737 <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>
8738 <td valign="middle" align="left"><img src="button-empty.png" border="0" alt="Forward: Procedures" align="middle" width="32"></td>
8739 <td valign="middle" align="left"> &nbsp; </td>
8740 <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>
8741 <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>
8742 <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>
8743 <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>
8744 <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>
8745 <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>
8746 </tr></table>
8747 <h2 class="unnumberedsec">Procedures</h2>
8748 <table><tr><th valign="top">Jump to: &nbsp; </th><td><a href="#Procedures-1_fn_symbol-1" class="summary-letter"><b> </b></a>
8749 &nbsp;
8750 <a href="#Procedures-1_fn_symbol-2" class="summary-letter"><b>'</b></a>
8751 &nbsp;
8752 <a href="#Procedures-1_fn_symbol-3" class="summary-letter"><b>*</b></a>
8753 &nbsp;
8754 <a href="#Procedures-1_fn_symbol-4" class="summary-letter"><b>+</b></a>
8755 &nbsp;
8756 <a href="#Procedures-1_fn_symbol-5" class="summary-letter"><b>-</b></a>
8757 &nbsp;
8758 <a href="#Procedures-1_fn_symbol-6" class="summary-letter"><b>/</b></a>
8759 &nbsp;
8760 <a href="#Procedures-1_fn_symbol-7" class="summary-letter"><b>&lt;</b></a>
8761 &nbsp;
8762 <a href="#Procedures-1_fn_symbol-8" class="summary-letter"><b>=</b></a>
8763 &nbsp;
8764 <a href="#Procedures-1_fn_symbol-9" class="summary-letter"><b>&gt;</b></a>
8765 &nbsp;
8766 <a href="#Procedures-1_fn_symbol-10" class="summary-letter"><b>`</b></a>
8767 &nbsp;
8768 <br>
8769 <a href="#Procedures-1_fn_letter-A" class="summary-letter"><b>A</b></a>
8770 &nbsp;
8771 <a href="#Procedures-1_fn_letter-B" class="summary-letter"><b>B</b></a>
8772 &nbsp;
8773 <a href="#Procedures-1_fn_letter-C" class="summary-letter"><b>C</b></a>
8774 &nbsp;
8775 <a href="#Procedures-1_fn_letter-D" class="summary-letter"><b>D</b></a>
8776 &nbsp;
8777 <a href="#Procedures-1_fn_letter-E" class="summary-letter"><b>E</b></a>
8778 &nbsp;
8779 <a href="#Procedures-1_fn_letter-F" class="summary-letter"><b>F</b></a>
8780 &nbsp;
8781 <a href="#Procedures-1_fn_letter-G" class="summary-letter"><b>G</b></a>
8782 &nbsp;
8783 <a href="#Procedures-1_fn_letter-I" class="summary-letter"><b>I</b></a>
8784 &nbsp;
8785 <a href="#Procedures-1_fn_letter-L" class="summary-letter"><b>L</b></a>
8786 &nbsp;
8787 <a href="#Procedures-1_fn_letter-M" class="summary-letter"><b>M</b></a>
8788 &nbsp;
8789 <a href="#Procedures-1_fn_letter-N" class="summary-letter"><b>N</b></a>
8790 &nbsp;
8791 <a href="#Procedures-1_fn_letter-O" class="summary-letter"><b>O</b></a>
8792 &nbsp;
8793 <a href="#Procedures-1_fn_letter-P" class="summary-letter"><b>P</b></a>
8794 &nbsp;
8795 <a href="#Procedures-1_fn_letter-Q" class="summary-letter"><b>Q</b></a>
8796 &nbsp;
8797 <a href="#Procedures-1_fn_letter-R" class="summary-letter"><b>R</b></a>
8798 &nbsp;
8799 <a href="#Procedures-1_fn_letter-S" class="summary-letter"><b>S</b></a>
8800 &nbsp;
8801 <a href="#Procedures-1_fn_letter-T" class="summary-letter"><b>T</b></a>
8802 &nbsp;
8803 <a href="#Procedures-1_fn_letter-V" class="summary-letter"><b>V</b></a>
8804 &nbsp;
8805 <a href="#Procedures-1_fn_letter-W" class="summary-letter"><b>W</b></a>
8806 &nbsp;
8807 <a href="#Procedures-1_fn_letter-Z" class="summary-letter"><b>Z</b></a>
8808 &nbsp;
8809 </td></tr></table>
8810 <table border="0" class="index-fn">
8811 <tr><td></td><th align="left">Index Entry</th><th align="left"> Section</th></tr>
8812 <tr><td colspan="3"> <hr></td></tr>
8813 <tr><th><a name="Procedures-1_fn_symbol-1"> </a></th><td></td><td></td></tr>
8814 <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>
8815 <tr><td colspan="3"> <hr></td></tr>
8816 <tr><th><a name="Procedures-1_fn_symbol-2">'</a></th><td></td><td></td></tr>
8817 <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>
8818 <tr><td colspan="3"> <hr></td></tr>
8819 <tr><th><a name="Procedures-1_fn_symbol-3">*</a></th><td></td><td></td></tr>
8820 <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>
8821 <tr><td colspan="3"> <hr></td></tr>
8822 <tr><th><a name="Procedures-1_fn_symbol-4">+</a></th><td></td><td></td></tr>
8823 <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>
8824 <tr><td colspan="3"> <hr></td></tr>
8825 <tr><th><a name="Procedures-1_fn_symbol-5">-</a></th><td></td><td></td></tr>
8826 <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>
8827 <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>
8828 <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>
8829 <tr><td colspan="3"> <hr></td></tr>
8830 <tr><th><a name="Procedures-1_fn_symbol-6">/</a></th><td></td><td></td></tr>
8831 <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>
8832 <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>
8833 <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>
8834 <tr><td colspan="3"> <hr></td></tr>
8835 <tr><th><a name="Procedures-1_fn_symbol-7">&lt;</a></th><td></td><td></td></tr>
8836 <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>
8837 <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>
8838 <tr><td colspan="3"> <hr></td></tr>
8839 <tr><th><a name="Procedures-1_fn_symbol-8">=</a></th><td></td><td></td></tr>
8840 <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>
8841 <tr><td colspan="3"> <hr></td></tr>
8842 <tr><th><a name="Procedures-1_fn_symbol-9">&gt;</a></th><td></td><td></td></tr>
8843 <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>
8844 <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>
8845 <tr><td colspan="3"> <hr></td></tr>
8846 <tr><th><a name="Procedures-1_fn_symbol-10">`</a></th><td></td><td></td></tr>
8847 <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>
8848 <tr><td colspan="3"> <hr></td></tr>
8849 <tr><th><a name="Procedures-1_fn_letter-A">A</a></th><td></td><td></td></tr>
8850 <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>
8851 <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>
8852 <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>
8853 <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>
8854 <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>
8855 <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>
8856 <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>
8857 <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>
8858 <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>
8859 <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>
8860 <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>
8861 <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>
8862 <tr><td colspan="3"> <hr></td></tr>
8863 <tr><th><a name="Procedures-1_fn_letter-B">B</a></th><td></td><td></td></tr>
8864 <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>
8865 <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>
8866 <tr><td colspan="3"> <hr></td></tr>
8867 <tr><th><a name="Procedures-1_fn_letter-C">C</a></th><td></td><td></td></tr>
8868 <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>
8869 <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>
8870 <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>
8871 <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>
8872 <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>
8873 <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>
8874 <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>
8875 <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>
8876 <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>
8877 <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>
8878 <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>
8879 <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>
8880 <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>
8881 <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>
8882 <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>
8883 <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>
8884 <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>
8885 <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>
8886 <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>
8887 <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>
8888 <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>
8889 <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>
8890 <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>
8891 <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>
8892 <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>
8893 <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>
8894 <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>
8895 <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>
8896 <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>
8897 <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>
8898 <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>
8899 <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>
8900 <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>
8901 <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>
8902 <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>
8903 <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>
8904 <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>
8905 <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>
8906 <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>
8907 <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>
8908 <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>
8909 <tr><td colspan="3"> <hr></td></tr>
8910 <tr><th><a name="Procedures-1_fn_letter-D">D</a></th><td></td><td></td></tr>
8911 <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>
8912 <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>
8913 <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>
8914 <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>
8915 <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>
8916 <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>
8917 <tr><td colspan="3"> <hr></td></tr>
8918 <tr><th><a name="Procedures-1_fn_letter-E">E</a></th><td></td><td></td></tr>
8919 <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>
8920 <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>
8921 <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>
8922 <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>
8923 <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>
8924 <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>
8925 <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>
8926 <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>
8927 <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>
8928 <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>
8929 <tr><td colspan="3"> <hr></td></tr>
8930 <tr><th><a name="Procedures-1_fn_letter-F">F</a></th><td></td><td></td></tr>
8931 <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>
8932 <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>
8933 <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>
8934 <tr><td colspan="3"> <hr></td></tr>
8935 <tr><th><a name="Procedures-1_fn_letter-G">G</a></th><td></td><td></td></tr>
8936 <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>
8937 <tr><td colspan="3"> <hr></td></tr>
8938 <tr><th><a name="Procedures-1_fn_letter-I">I</a></th><td></td><td></td></tr>
8939 <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>
8940 <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>
8941 <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>
8942 <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>
8943 <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>
8944 <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>
8945 <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>
8946 <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>
8947 <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>
8948 <tr><td colspan="3"> <hr></td></tr>
8949 <tr><th><a name="Procedures-1_fn_letter-L">L</a></th><td></td><td></td></tr>
8950 <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>
8951 <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>
8952 <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>
8953 <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>
8954 <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>
8955 <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>
8956 <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>
8957 <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>
8958 <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>
8959 <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>
8960 <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>
8961 <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>
8962 <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>
8963 <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>
8964 <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>
8965 <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>
8966 <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>
8967 <tr><td colspan="3"> <hr></td></tr>
8968 <tr><th><a name="Procedures-1_fn_letter-M">M</a></th><td></td><td></td></tr>
8969 <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>
8970 <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>
8971 <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>
8972 <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>
8973 <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>
8974 <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>
8975 <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>
8976 <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>
8977 <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>
8978 <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>
8979 <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>
8980 <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>
8981 <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>
8982 <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>
8983 <tr><td colspan="3"> <hr></td></tr>
8984 <tr><th><a name="Procedures-1_fn_letter-N">N</a></th><td></td><td></td></tr>
8985 <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>
8986 <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>
8987 <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>
8988 <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>
8989 <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>
8990 <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>
8991 <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>
8992 <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>
8993 <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>
8994 <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>
8995 <tr><td colspan="3"> <hr></td></tr>
8996 <tr><th><a name="Procedures-1_fn_letter-O">O</a></th><td></td><td></td></tr>
8997 <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>
8998 <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>
8999 <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>
9000 <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>
9001 <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>
9002 <tr><td colspan="3"> <hr></td></tr>
9003 <tr><th><a name="Procedures-1_fn_letter-P">P</a></th><td></td><td></td></tr>
9004 <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>
9005 <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>
9006 <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>
9007 <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>
9008 <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>
9009 <tr><td colspan="3"> <hr></td></tr>
9010 <tr><th><a name="Procedures-1_fn_letter-Q">Q</a></th><td></td><td></td></tr>
9011 <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>
9012 <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>
9013 <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>
9014 <tr><td colspan="3"> <hr></td></tr>
9015 <tr><th><a name="Procedures-1_fn_letter-R">R</a></th><td></td><td></td></tr>
9016 <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>
9017 <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>
9018 <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>
9019 <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>
9020 <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>
9021 <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>
9022 <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>
9023 <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>
9024 <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>
9025 <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>
9026 <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>
9027 <tr><td colspan="3"> <hr></td></tr>
9028 <tr><th><a name="Procedures-1_fn_letter-S">S</a></th><td></td><td></td></tr>
9029 <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>
9030 <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>
9031 <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>
9032 <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>
9033 <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>
9034 <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>
9035 <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>
9036 <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>
9037 <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>
9038 <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>
9039 <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>
9040 <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>
9041 <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>
9042 <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>
9043 <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>
9044 <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>
9045 <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>
9046 <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>
9047 <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>
9048 <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>
9049 <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>
9050 <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>
9051 <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>
9052 <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>
9053 <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>
9054 <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>
9055 <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>
9056 <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>
9057 <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>
9058 <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>
9059 <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>
9060 <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>
9061 <tr><td colspan="3"> <hr></td></tr>
9062 <tr><th><a name="Procedures-1_fn_letter-T">T</a></th><td></td><td></td></tr>
9063 <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>
9064 <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>
9065 <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>
9066 <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>
9067 <tr><td colspan="3"> <hr></td></tr>
9068 <tr><th><a name="Procedures-1_fn_letter-V">V</a></th><td></td><td></td></tr>
9069 <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>
9070 <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>
9071 <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>
9072 <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>
9073 <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>
9074 <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>
9075 <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>
9076 <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>
9077 <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>
9078 <tr><td colspan="3"> <hr></td></tr>
9079 <tr><th><a name="Procedures-1_fn_letter-W">W</a></th><td></td><td></td></tr>
9080 <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>
9081 <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>
9082 <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>
9083 <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>
9084 <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>
9085 <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>
9086 <tr><td colspan="3"> <hr></td></tr>
9087 <tr><th><a name="Procedures-1_fn_letter-Z">Z</a></th><td></td><td></td></tr>
9088 <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>
9089 <tr><td colspan="3"> <hr></td></tr>
9090 </table>
9091 <table><tr><th valign="top">Jump to: &nbsp; </th><td><a href="#Procedures-1_fn_symbol-1" class="summary-letter"><b> </b></a>
9092 &nbsp;
9093 <a href="#Procedures-1_fn_symbol-2" class="summary-letter"><b>'</b></a>
9094 &nbsp;
9095 <a href="#Procedures-1_fn_symbol-3" class="summary-letter"><b>*</b></a>
9096 &nbsp;
9097 <a href="#Procedures-1_fn_symbol-4" class="summary-letter"><b>+</b></a>
9098 &nbsp;
9099 <a href="#Procedures-1_fn_symbol-5" class="summary-letter"><b>-</b></a>
9100 &nbsp;
9101 <a href="#Procedures-1_fn_symbol-6" class="summary-letter"><b>/</b></a>
9102 &nbsp;
9103 <a href="#Procedures-1_fn_symbol-7" class="summary-letter"><b>&lt;</b></a>
9104 &nbsp;
9105 <a href="#Procedures-1_fn_symbol-8" class="summary-letter"><b>=</b></a>
9106 &nbsp;
9107 <a href="#Procedures-1_fn_symbol-9" class="summary-letter"><b>&gt;</b></a>
9108 &nbsp;
9109 <a href="#Procedures-1_fn_symbol-10" class="summary-letter"><b>`</b></a>
9110 &nbsp;
9111 <br>
9112 <a href="#Procedures-1_fn_letter-A" class="summary-letter"><b>A</b></a>
9113 &nbsp;
9114 <a href="#Procedures-1_fn_letter-B" class="summary-letter"><b>B</b></a>
9115 &nbsp;
9116 <a href="#Procedures-1_fn_letter-C" class="summary-letter"><b>C</b></a>
9117 &nbsp;
9118 <a href="#Procedures-1_fn_letter-D" class="summary-letter"><b>D</b></a>
9119 &nbsp;
9120 <a href="#Procedures-1_fn_letter-E" class="summary-letter"><b>E</b></a>
9121 &nbsp;
9122 <a href="#Procedures-1_fn_letter-F" class="summary-letter"><b>F</b></a>
9123 &nbsp;
9124 <a href="#Procedures-1_fn_letter-G" class="summary-letter"><b>G</b></a>
9125 &nbsp;
9126 <a href="#Procedures-1_fn_letter-I" class="summary-letter"><b>I</b></a>
9127 &nbsp;
9128 <a href="#Procedures-1_fn_letter-L" class="summary-letter"><b>L</b></a>
9129 &nbsp;
9130 <a href="#Procedures-1_fn_letter-M" class="summary-letter"><b>M</b></a>
9131 &nbsp;
9132 <a href="#Procedures-1_fn_letter-N" class="summary-letter"><b>N</b></a>
9133 &nbsp;
9134 <a href="#Procedures-1_fn_letter-O" class="summary-letter"><b>O</b></a>
9135 &nbsp;
9136 <a href="#Procedures-1_fn_letter-P" class="summary-letter"><b>P</b></a>
9137 &nbsp;
9138 <a href="#Procedures-1_fn_letter-Q" class="summary-letter"><b>Q</b></a>
9139 &nbsp;
9140 <a href="#Procedures-1_fn_letter-R" class="summary-letter"><b>R</b></a>
9141 &nbsp;
9142 <a href="#Procedures-1_fn_letter-S" class="summary-letter"><b>S</b></a>
9143 &nbsp;
9144 <a href="#Procedures-1_fn_letter-T" class="summary-letter"><b>T</b></a>
9145 &nbsp;
9146 <a href="#Procedures-1_fn_letter-V" class="summary-letter"><b>V</b></a>
9147 &nbsp;
9148 <a href="#Procedures-1_fn_letter-W" class="summary-letter"><b>W</b></a>
9149 &nbsp;
9150 <a href="#Procedures-1_fn_letter-Z" class="summary-letter"><b>Z</b></a>
9151 &nbsp;
9152 </td></tr></table>
9156 <hr size="1">
9157 <a name="SEC_Contents"></a>
9158 <table cellpadding="1" cellspacing="1" border="0">
9159 <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>
9160 <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>
9161 <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>
9162 </tr></table>
9163 <h1>Table of Contents</h1>
9164 <div class="contents">
9166 <ul class="toc">
9167 <li><a name="toc-Summary" href="#Summary">Summary</a></li>
9168 <li><a name="toc-Contents" href="#Contents">Contents</a></li>
9169 <li><a name="toc-Introduction-1" href="#Introduction">Introduction</a>
9170 <ul class="toc">
9171 <li><a name="toc-Background-1" href="#Background">Background</a></li>
9172 <li><a name="toc-Acknowledgements-1" href="#Acknowledgements">Acknowledgements</a></li>
9173 </ul></li>
9174 <li><a name="toc-Overview-of-Scheme-1" href="#Overview-of-Scheme">1. Overview of Scheme</a>
9175 <ul class="toc">
9176 <li><a name="toc-Semantics-1" href="#Semantics">1.1 Semantics</a></li>
9177 <li><a name="toc-Syntax-1" href="#Syntax">1.2 Syntax</a></li>
9178 <li><a name="toc-Notation-and-terminology-1" href="#Notation-and-terminology">1.3 Notation and terminology</a>
9179 <ul class="toc">
9180 <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>
9181 <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>
9182 <li><a name="toc-Entry-format-1" href="#Entry-format">1.3.3 Entry format</a></li>
9183 <li><a name="toc-Evaluation-examples-1" href="#Evaluation-examples">1.3.4 Evaluation examples</a></li>
9184 <li><a name="toc-Naming-conventions-1" href="#Naming-conventions">1.3.5 Naming conventions</a></li>
9185 </ul>
9186 </li>
9187 </ul></li>
9188 <li><a name="toc-Lexical-conventions-1" href="#Lexical-conventions">2. Lexical conventions</a>
9189 <ul class="toc">
9190 <li><a name="toc-Identifiers-1" href="#Identifiers">2.1 Identifiers</a></li>
9191 <li><a name="toc-Whitespace-and-comments-1" href="#Whitespace-and-comments">2.2 Whitespace and comments</a></li>
9192 <li><a name="toc-Other-notations-1" href="#Other-notations">2.3 Other notations</a></li>
9193 </ul></li>
9194 <li><a name="toc-Basic-concepts-1" href="#Basic-concepts">3. Basic concepts</a>
9195 <ul class="toc">
9196 <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>
9197 <li><a name="toc-Disjointness-of-types-1" href="#Disjointness-of-types">3.2 Disjointness of types</a></li>
9198 <li><a name="toc-External-representations-2" href="#External-representations">3.3 External representations</a></li>
9199 <li><a name="toc-Storage-model-1" href="#Storage-model">3.4 Storage model</a></li>
9200 <li><a name="toc-Proper-tail-recursion-1" href="#Proper-tail-recursion">3.5 Proper tail recursion</a></li>
9201 </ul></li>
9202 <li><a name="toc-Expressions-2" href="#Expressions">4. Expressions</a>
9203 <ul class="toc">
9204 <li><a name="toc-Primitive-expression-types-1" href="#Primitive-expression-types">4.1 Primitive expression types</a>
9205 <ul class="toc">
9206 <li><a name="toc-Variable-references-1" href="#Variable-references">4.1.1 Variable references</a></li>
9207 <li><a name="toc-Literal-expressions-1" href="#Literal-expressions">4.1.2 Literal expressions</a></li>
9208 <li><a name="toc-Procedure-calls-1" href="#Procedure-calls">4.1.3 Procedure calls</a></li>
9209 <li><a name="toc-Procedures-2" href="#Procedures">4.1.4 Procedures</a></li>
9210 <li><a name="toc-Conditionals-1" href="#Conditionals">4.1.5 Conditionals</a></li>
9211 <li><a name="toc-Assignments-1" href="#Assignments">4.1.6 Assignments</a></li>
9212 </ul></li>
9213 <li><a name="toc-Derived-expression-types-1" href="#Derived-expression-types">4.2 Derived expression types</a>
9214 <ul class="toc">
9215 <li><a name="toc-Conditionals-2" href="#Conditional">4.2.1 Conditionals</a></li>
9216 <li><a name="toc-Binding-constructs-1" href="#Binding-constructs">4.2.2 Binding constructs</a></li>
9217 <li><a name="toc-Sequencing-1" href="#Sequencing">4.2.3 Sequencing</a></li>
9218 <li><a name="toc-Iteration-1" href="#Iteration">4.2.4 Iteration</a></li>
9219 <li><a name="toc-Delayed-evaluation-1" href="#Delayed-evaluation">4.2.5 Delayed evaluation</a></li>
9220 <li><a name="toc-Quasiquotation-1" href="#Quasiquotation">4.2.6 Quasiquotation</a></li>
9221 </ul></li>
9222 <li><a name="toc-Macros-1" href="#Macros">4.3 Macros</a>
9223 <ul class="toc">
9224 <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>
9225 <li><a name="toc-Pattern-language-1" href="#Pattern-language">4.3.2 Pattern language</a></li>
9226 </ul>
9227 </li>
9228 </ul></li>
9229 <li><a name="toc-Program-structure-1" href="#Program-structure">5. Program structure</a>
9230 <ul class="toc">
9231 <li><a name="toc-Programs-1" href="#Programs">5.1 Programs</a></li>
9232 <li><a name="toc-Definitions-1" href="#Definitions">5.2 Definitions</a>
9233 <ul class="toc">
9234 <li><a name="toc-Top-level-definitions-1" href="#Top-level-definitions">5.2.1 Top level definitions</a></li>
9235 <li><a name="toc-Internal-definitions-1" href="#Internal-definitions">5.2.2 Internal definitions</a></li>
9236 </ul></li>
9237 <li><a name="toc-Syntax-definitions-1" href="#Syntax-definitions">5.3 Syntax definitions</a></li>
9238 </ul></li>
9239 <li><a name="toc-Standard-procedures-1" href="#Standard-procedures">6. Standard procedures</a>
9240 <ul class="toc">
9241 <li><a name="toc-Equivalence-predicates-1" href="#Equivalence-predicates">6.1 Equivalence predicates</a></li>
9242 <li><a name="toc-Numbers-1" href="#Numbers">6.2 Numbers</a>
9243 <ul class="toc">
9244 <li><a name="toc-Numerical-types-1" href="#Numerical-types">6.2.1 Numerical types</a></li>
9245 <li><a name="toc-Exactness-1" href="#Exactness">6.2.2 Exactness</a></li>
9246 <li><a name="toc-Implementation-restrictions-1" href="#Implementation-restrictions">6.2.3 Implementation restrictions</a></li>
9247 <li><a name="toc-Syntax-of-numerical-constants-1" href="#Syntax-of-numerical-constants">6.2.4 Syntax of numerical constants</a></li>
9248 <li><a name="toc-Numerical-operations-1" href="#Numerical-operations">6.2.5 Numerical operations</a></li>
9249 <li><a name="toc-Numerical-input-and-output-1" href="#Numerical-input-and-output">6.2.6 Numerical input and output</a></li>
9250 </ul></li>
9251 <li><a name="toc-Other-data-types-1" href="#Other-data-types">6.3 Other data types</a>
9252 <ul class="toc">
9253 <li><a name="toc-Booleans-1" href="#Booleans">6.3.1 Booleans</a></li>
9254 <li><a name="toc-Pairs-and-lists-1" href="#Pairs-and-lists">6.3.2 Pairs and lists</a></li>
9255 <li><a name="toc-Symbols-1" href="#Symbols">6.3.3 Symbols</a></li>
9256 <li><a name="toc-Characters-1" href="#Characters">6.3.4 Characters</a></li>
9257 <li><a name="toc-Strings-1" href="#Strings">6.3.5 Strings</a></li>
9258 <li><a name="toc-Vectors-1" href="#Vectors">6.3.6 Vectors</a></li>
9259 </ul></li>
9260 <li><a name="toc-Control-features-1" href="#Control-features">6.4 Control features</a></li>
9261 <li><a name="toc-Eval-1" href="#Eval">6.5 Eval</a></li>
9262 <li><a name="toc-Input-and-output-1" href="#Input-and-output">6.6 Input and output</a>
9263 <ul class="toc">
9264 <li><a name="toc-Ports-1" href="#Ports">6.6.1 Ports</a></li>
9265 <li><a name="toc-Input-1" href="#Input">6.6.2 Input</a></li>
9266 <li><a name="toc-Output-1" href="#Output">6.6.3 Output</a></li>
9267 <li><a name="toc-System-interface-1" href="#System-interface">6.6.4 System interface</a></li>
9268 </ul>
9269 </li>
9270 </ul></li>
9271 <li><a name="toc-Formal-syntax-and-semantics-1" href="#Formal-syntax-and-semantics">7. Formal syntax and semantics</a>
9272 <ul class="toc">
9273 <li><a name="toc-Formal-syntax-1" href="#Formal-syntax">7.1 Formal syntax</a>
9274 <ul class="toc">
9275 <li><a name="toc-Lexical-structure-1" href="#Lexical-structure">7.1.1 Lexical structure</a></li>
9276 <li><a name="toc-External-representations-1" href="#External-representation">7.1.2 External representations</a></li>
9277 <li><a name="toc-Expressions-1" href="#Expression">7.1.3 Expressions</a></li>
9278 <li><a name="toc-Quasiquotations-1" href="#Quasiquotations">7.1.4 Quasiquotations</a></li>
9279 <li><a name="toc-Transformers-1" href="#Transformers">7.1.5 Transformers</a></li>
9280 <li><a name="toc-Programs-and-definitions-1" href="#Programs-and-definitions">7.1.6 Programs and definitions</a></li>
9281 </ul></li>
9282 <li><a name="toc-Formal-semantics-1" href="#Formal-semantics">7.2 Formal semantics</a></li>
9283 <li><a name="toc-Derived-expression-types-2" href="#Derived-expression-type">7.3 Derived expression types</a></li>
9284 </ul></li>
9285 <li><a name="toc-Notes-1" href="#Notes">Notes</a>
9286 <ul class="toc">
9287 <li><a name="toc-Language-changes-1" href="#Language-changes">Language changes</a></li>
9288 </ul></li>
9289 <li><a name="toc-Additional-material-1" href="#Additional-material">Additional material</a></li>
9290 <li><a name="toc-Example-1" href="#Example">Example</a></li>
9291 <li><a name="toc-Bibliography-1" href="#Bibliography">Bibliography</a></li>
9292 <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>
9293 <ul class="toc">
9294 <li><a name="toc-Concepts" href="#Concepts">Concepts</a></li>
9295 <li><a name="toc-Procedures-1" href="#Procedures-1">Procedures</a></li>
9296 </ul>
9297 </li>
9298 </ul>
9299 </div>
9300 <hr size="1">
9301 <a name="SEC_About"></a>
9302 <table cellpadding="1" cellspacing="1" border="0">
9303 <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>
9304 <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>
9305 <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>
9306 </tr></table>
9308 </body>
9309 </html>