-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathintro.html
388 lines (323 loc) · 21.5 KB
/
intro.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd"><!-- DO NOT EDIT THIS FILE-->
<!-- Edit the .tex version instead-->
<html>
<head>
<title>简介</title>
<link href="csug.css" rel="stylesheet" type="text/css">
</head>
<body>
<a name="g0"></a>
<a name="./intro:h0"></a>
<h1>Chapter 1. 简介</h1>
<p>
<i>Chez Scheme</i>是一种有着众多的语言和编程环境扩展的“Revised<sup>6</sup> Report on Scheme [<a class=citation href="./bibliography.html#g173">27</a>] (R6RS)”实现。
<p>
本书详细描述了这些扩展。
亦包含了标准的和<i>Chez Scheme</i>的形式与过程的简明摘要,给出了每个形式和每个过程所接受的参数的数量和类型的语法。
标准Scheme特性的详细内容可参考<a name="./intro:s0"></a><a href=http://www.scheme.com/tspl4/><i>The
Scheme Programming Language, 4th Edition</i></a> (TSPL4) [<a class=citation href="./bibliography.html#g157">11</a>]或者the Revised<sup>6</sup> Report on Scheme.
<i>The Scheme Programming Language, 4th Edition</i>也包含了一个关于Scheme语言的广泛的介绍和众多长长短短的例子。
<p>
本文档大部分内容也适用于<a name="./intro:s1"></a><i>Petite Chez Scheme</i>(与完整版Chez Scheme系统完全兼容,但其使用了一个高速解释器替代了增量本地编译器)。
为<i>Chez Scheme</i>写的程序只要不调用编译器的话,那么无需修改就能在<i>Petite Chez Scheme</i>中运行,
事实上,<i>Petite Chez Scheme</i>编译自与<i>Chez Scheme</i>相同的代码,仅仅除去了与编译器相关的代码。
该区别造成的影响的详细讨论参见Section <a href="./use.html#g13">2.8</a>.
<p>
本章的其余部分将介绍<i>Chez Scheme</i>对Scheme语法的拓展(Section <a href="./intro.html#g1">1.1</a>),本书中使用的符号约定(Section <a href="./intro.html#g2">1.2</a>),用于系统自定义的参数用法(Section <a href="./intro.html#g3">1.3</a>),与如何查找与<i>Chez Scheme</i>相关的更多信息(Section <a href="./intro.html#g4">1.4</a>).
<p>Chapter <a href="./use.html#g5">2</a> 描述了如何使用<i>Chez Scheme</i>来进行程序开发、脚本、应用交付,以及如何使编译器生成最高效的代码。
<br/>Chapter <a href="./debug.html#g15">3</a> 描述了调试和对象检查功能(//object inspection facilities)。
<br/>Chapter <a href="./foreign.html#g22">4</a> 陈述了与不同处理器或其他语言代码交互的facilities。
<br/>Chapter <a href="./binding.html#g36">5</a> 描述了绑定表格。
<br/>Chapter <a href="./control.html#g42">6</a> 陈述了控制结构。
<br/>Chapter <a href="./objects.html#g47">7</a> 陈述了对非数字对象的操作。
<br/>Chapter <a href="./numeric.html#g62">8</a> 陈述了各种对数字的操作,包括各种数字操作、高效的特定类型操作。
<br/>Chapter <a href="./io.html#g70">9</a> 描述了输入/输出操作和允许定义具有任意输入/输出语义的通用端口。
<br/>Chapter <a href="./libraries.html#g88">10</a> 讨论了如何将R6RS库和顶层程序加载到<i>Chez Scheme</i>以及控制和跟踪加载过程的各种功能。
<br/>Chapter <a href="./syntax.html#g95">11</a> 描述了语法扩展和模块。
<br/>Chapter <a href="./system.html#g107">12</a> 描述了系统操作,例如与操作系统交互和定制<i>Chez Scheme</i>的用户界面的操作。
<br/>Chapter <a href="./smgmt.html#g124">13</a> 描述了如何调用和控制存储管理系统并记录监护人和弱对。(//documents guardians and weak pairs.)
<br/>Chapter <a href="./expeditor.html#g128">14</a> 描述了<i>Chez Scheme</i>的表达式编辑器以及如何对其定制。
<br/>Chapter <a href="./threads.html#g133">15</a> 陈述了包括<i>Chez Scheme</i>的本地线程系统接口的过程和语法形式。
<br/>Chapter <a href="./compat.html#g142">16</a> 描述了各种兼容性功能。
<p>
本书的后面包含了参考书目,语法形式摘要,和索引。
在语法形式摘要出现的页码以及在索引中出现的斜体页码指明了语法形式和过程被正式定义在文本中的位置
语法形式摘要和索引包含了来自TSPL4的条目,故而它们完整覆盖了<i>Chez Scheme</i>的功能。
TSPL4的条目以一个“t”字母为页码前缀作为标记。
<p>
本书和TSPL4的在线版本和勘误表可参见<a href=http://www.scheme.com>www.scheme.com</a>.
<p>
<p><i>致谢:</i>
Michael Adams, Mike Ashley, Carl Bruggeman, Bob Burger, Sam
Daniel, George Davidson, Aziz Ghuloum, Bob Hieb, Andy Keep, and Oscar Waddell have
contributed substantially to the development of <i>Chez Scheme</i>.
<i>Chez Scheme</i>'s expression editor is based on a command-line editor for
Scheme developed from 1989 through 1994 by C. David Boyer.
File compression is performed with the use of the zlib compression library
developed by Jean-loup Gailly and Mark Adler.
Implementations of the list and vector sorting routines are based on
Olin Shiver's opportunistic merge-sort algorithm and implementation.
Michael Lenaghan provided a number of corrections for earlier drafts
of this book.
Many of the features documented in this book were suggested by
current <i>Chez Scheme</i> users, and numerous comments from users have also
led to improvements in the text.
Additional suggestions for improvements to <i>Chez Scheme</i> and to this
book are welcome.
<p>
<h3><a name="g1"></a><a name="./intro:h1"></a>Section 1.1. Chez Scheme Syntax<a name="SECTINTROSYNTAX"></a></h3>
<p>
<i>Chez Scheme</i>同时在对象(数据(//datum))层面和语法形式层面拓展了Scheme的语法。
在对象层面,<i>Chez Scheme</i>支持包含非标准字符、以浮点数和科学计数法表达的非十进制数字、显式长度的向量、共享和环状结构、records,boxes等等的符号的额外表示法。
这些扩展将在下面描述。
语法形式层面的拓展的描述将贯穿本书,并且将总结在本书的后面的语法形式摘要中。
<p>
<i>Chez Scheme</i>以多种方式拓展了标识符的语法。
首先,组建标识符名字的字符序列可以以数字、句点、加号、减号为开头,只要整体不被解析为一个数字。
例如,<tt>0abc</tt>, <tt>+++</tt>, and <tt>..</tt>在<i>Chez Scheme</i>中都是有效的标识符。
第二点,单字符序列<tt>{</tt>和<tt>}</tt>也是标识符。
第三点,包含任意字符的标识符将可以使用<tt>\</tt>或<tt>|</tt>来使用转义字符的方式打印。
<tt>\</tt>用来转义单个字符(除了‘x’,因为<tt>\x</tt>用于标记一个十六进制标量值的开始),
而<tt>|</tt>用来转义从|开始到|结束的中键的字符串组。
例如<tt>\||\|</tt>是一个有着两个字符的标识符,其由一个字符<tt>|</tt>后跟一个字符<tt>\</tt>组成,而<tt>|hit me!|</tt>则是一个包含着一个空格字符的标识符。
<p>
此外,gensyms(page <a href="./objects.html#g56">7.9</a>)能写成以<a name="./intro:s2"></a><tt>#{</tt>和<tt>}</tt>括起来的包含漂亮和独一无二两个名字的形式,例如<tt>#{g1426 e5g1c94g642dssw-a}</tt>。
它们也可以只用漂亮名字以<a name="./intro:s3"></a><tt>#:</tt>作为前缀来书写,例如<tt>#:g1426</tt>。
<p>
任意2到36的基数(译注,二进制基数是2、十进制基数是10、十六进制基数是16)可以使用前缀<a name="./intro:s4"></a><tt>#<i>n</i>r</tt>,其中的<tt><i>n</i></tt>表示基数。
大小写并不重要,所以写成<tt>#<i>n</i>R</tt>也能用。
从10到35的数字能用大/小写的英文字母表示,就像十六进制那么用一样。
例如<tt>#36rZZ</tt>表示35 × 36 + 35,也即1295。
<p>
<i>Chez Scheme</i>也允许非十进制数字以浮点数或科学计数法的方式打印
例如,<tt>#o1.4</tt>等于<tt>1.5</tt>,而<tt>#b1e10</tt>等于<tt>4.0</tt>。
数字写在指数的前面,所以<tt>#x1e20</tt>等同于四位十六进制数<tt>7712</tt>.
<p>
除了标准命名的字符
<a name="./intro:s5"><tt>#\alarm</tt>,
<a name="./intro:s6"></a><tt>#\backspace</tt>,
<a name="./intro:s7"></a><tt>#\delete</tt>,
<a name="./intro:s8"></a><tt>#\esc</tt>,
<a name="./intro:s9"></a><tt>#\linefeed</tt>,
<a name="./intro:s10"></a><tt>#\newline</tt>,
<a name="./intro:s11"></a><tt>#\page</tt>,
<a name="./intro:s12"></a><tt>#\return</tt>,
<a name="./intro:s13"></a><tt>#\space</tt>,
和
<a name="./intro:s14"></a><tt>#\tab</tt>,
<i>Chez Scheme</i>也能识别
<a name="./intro:s15"></a><tt>#\bel</tt>,
<a name="./intro:s16"></a><tt>#\ls</tt>,
<a name="./intro:s17"></a><tt>#\nel</tt>,
<a name="./intro:s18"></a><tt>#\nul</tt>,
<a name="./intro:s19"></a><tt>#\rubout</tt>,
和
<a name="./intro:s20"></a><tt>#\vt</tt> (or <tt>#\vtab</tt>)。
标量值小于256的字符也能以<tt>#\</tt>为前缀后跟3个八进制数的八进制方式书写。
例如,<tt>#\000</tt>等同于<tt>#\nul</tt>。
<p>
<i>Chez Scheme</i>的fxvectors,或者换种说法fixnum vectors,能写成类似向量(vectors)但却以<tt>#vfx(</tt>为前缀而不是<tt>#(</tt>的形式。
向量(Vectors),bytevectors以及fxvectors都可以写成以一个明确的长度为前缀,并且当明确的长度被指定,重复的尾部元素可以被简写为一个。
例如,<a name="./intro:s21"></a><tt>#(a b c)</tt>能写成<a name="./intro:s22"></a><tt>#3(a b c)</tt>,而一个包含100个全零的向量可以简写为<tt>#100(0)</tt>。
<p>
<i>Chez Scheme</i>的box以<a name="./intro:s23"></a><tt>#&</tt>为前缀,例如<tt>#&17</tt>是一个包含整型数<tt>17</tt>的box。
<p>
Records能写成<a name="./intro:s24"></a><tt>#[<i>type-name</i> <i>field</i> ...]</tt>这样的语法形式,其中符号<tt><i>type-name</i></tt>是record的类型名、<tt><i>field</i> ...</tt>则表示record字段的内容。
<p>
共享和循环结构可写成使用图标记和相关前缀<a name="./intro:s25"></a><tt>#<i>n</i>=</tt>和<a name="./intro:s26"></a><tt>#<i>n</i>#</tt>的形式。
<tt>#<i>n</i>=</tt>用于标记输入端的项, 而<tt>#<i>n</i>#</tt>用于标记被标注为<tt><i>n</i></tt>的项。
例如,<tt>'(#1=(a) . #1#)</tt>是一个car和cdr包含着同一list的pair,而<tt>#0=(a . #0#)</tt>是一个循环list,也就是说,它的cdr是它本身。
<p>
一个<tt>$primitive</tt> form (详见page <a href="./system.html#desc:hash-primitive">336</a>)可能会以<tt>quote</tt> form同样的方式,即使用<a name="./intro:s27"></a><tt>#%</tt>为前缀,作为缩写。
例如,
<tt>#%car</tt>等同于<tt>($primitive car)</tt>,
<tt>#2%car</tt>等同于<tt>($primitive 2 car)</tt>,
<tt>#3%car</tt>等同于<tt>($primitive 3 car)</tt>,
<p>
<i>Chez Scheme</i>的end-of-file对象写作<tt>#!eof</tt>。
如果end-of-file对象出现在任何载入了的文件的数据外部(//If the end-of-file object appears outside of any datum within a file
being loaded),<tt>load</tt>将把它视为一个真正的文件结尾并停止在这个位置的载入。
在一个文件的中间插入<tt>#!eof</tt>可以方便地跟踪load-time错误。
<p>
weak pairs中的Broken pointers(详见page <a href="./smgmt.html#desc:weak-cons">381</a>)被表示为<i>broken weak pointer</i>对象,写作<tt>#!bwp</tt>。
<p>
除了标准的分隔符(空格,左右小括号,左右中括号,双引号,分号,以及<tt>#</tt>), <i>Chez Scheme</i>也将以下作为分隔符:左右大括号,单引号,反引号,逗号。
<p>
The <i>Chez Scheme</i> lexical extensions described above are disabled in an
input stream after an <tt>#!r6rs</tt> comment directive has been seen,
unless a <tt>#!chezscheme</tt> comment directive has been seen since.
Each library loaded implicitly via <tt>import</tt> and each RNRS top-level
program loaded via the <tt>--program</tt> command-line option, the
<tt>scheme-script</tt> command, or the <tt>load-program</tt> procedure is
treated as if it begins implicitly with an <tt>#!r6rs</tt> comment directive.
<p>
The case of symbol and character names is normally significant,
as required by the Revised<sup>6</sup> Report.
Names are folded, as if by <tt>string-foldcase</tt>, following a
<tt>#!fold-case</tt> comment directive in the same input stream
unless a <tt>#!no-fold-case</tt> has been seen since.
Names are also folded if neither directive has been seen and the
parameter <tt>case-sensitive</tt> has been set to <tt>#f</tt>.
<p>
The printer invoked by <tt>write</tt>, <tt>put-datum</tt>,
<tt>pretty-print</tt>, and the <tt>format</tt> <tt>~s</tt>
option always prints standard Revised<sup>6</sup> Report objects
using the standard syntax.
For example, it prints symbols whose names require escaping using hex
scalar value escapes, not one of the other mechanisms supported by the
reader.
Similarly, it does not print the explicit length or suppress
duplicate trailing elements unless the parameter
<a name="./intro:s28"></a><tt>print-vector-length</tt> is set to
true.
<p>
<h3><a name="g2"></a><a name="./intro:h2"></a>Section 1.2. Notational Conventions<a name="SECTINTRONOTATION"></a></h3>
<p>
This book follows essentially the same notational conventions as
<i>The Scheme Programming Language, 4th Edition</i>.
These conventions are repeated below, with notes specific to
<i>Chez Scheme</i>.
<p>
When the value produced by a procedure or syntactic form is said to
be <a name="./intro:s29"></a><i>unspecified</i>, the form or procedure may
return any number of values, each of which may be any Scheme
object.
<i>Chez Scheme</i> usually returns a single, unique
<a name="./intro:s30"></a><i>void</i> object
(see <a name="./intro:s31"></a><tt>void</tt>) whenever
the result is unspecified; avoid counting on this behavior, however,
especially if your program may be ported to another Scheme implementation.
Printing of the void object is suppressed by <i>Chez Scheme</i>'s waiter
(read-evaluate-print loop).
<p>
<a name="./intro:s32"></a>This book uses the words "must" and "should" to
describe program requirements, such as the requirement to provide an index
that is less than the length of the vector in a call to
<tt>vector-ref</tt>.
If the word "must" is used, it means that the requirement is enforced
by the implementation, i.e., an exception is raised, usually with
condition type <tt>&assertion</tt>.
If the word "should" is used, an exception may or may not be raised,
and if not, the behavior of the program is undefined.
<a name="./intro:s33"></a>The phrase "syntax violation" is used to
describe a situation in which a program is malformed.
Syntax violations are detected prior to program execution.
When a syntax violation is detected, an exception of type <tt>&syntax</tt>
is raised and the program is not executed.
<p>
Scheme objects are displayed in a <tt>typewriter</tt> typeface just
as they are to be typed at the keyboard.
This includes identifiers, constant objects, parenthesized Scheme
expressions, and whole programs.
An <i>italic</i> typeface is used to set off syntax variables in
the descriptions of syntactic forms and arguments in the descriptions of
procedures.
Italics are also used to set off technical terms the first time they
appear.
The first letter of an identifier that is not ordinarily capitalized
is not capitalized when it appears at the beginning of a sentence.
The same is true for syntax variables written in italics.
<p>
In the description of a syntactic form or procedure, a pattern shows
the syntactic form or the application of the procedure.
The syntax keyword or procedure name is given in typewriter font,
as are parentheses.
The remaining pieces of the syntax or arguments are shown in italics,
using names that imply the types of the expressions or arguments expected
by the syntactic form or procedure.
Ellipses are used to specify
zero or more occurrences of a subexpression or argument.
<p>
<h3><a name="g3"></a><a name="./intro:h3"></a>Section 1.3. Parameters<a name="SECTINTROPARAMETERS"></a></h3>
<p>
<a name="./intro:s34"></a>All <i>Chez Scheme</i> system customization is done via
<i>parameters</i>.
A parameter is a procedure that encapsulates a hidden state variable.
When invoked without arguments, a parameter returns the value of
the encapsulated variable.
When invoked with one argument, the parameter changes the value
of the variable to the value of its argument.
A parameter may raise an exception if its argument is not appropriate,
or it may filter the argument in some way.
<p>
New parameters may be created and used by programs running in
<i>Chez Scheme</i>.
Parameters are used rather than global variables for program customization
for two reasons:
First, unintentional redefinition of a customization variable can cause
unexpected problems, whereas unintentional redefinition of a
parameter simply makes the parameter inaccessible.
For example, a program that defines <tt>*print-level*</tt> for its own
purposes in early releases of <i>Chez Scheme</i> would have unexpected
effects on the printing of Scheme objects, whereas a program that
defines <a name="./intro:s35"></a><tt>print-level</tt> for its own
purposes simply loses the ability to alter the printer's behavior.
Of course, a program that invokes <tt>print-level</tt> by accident can
still affect the system in unintended ways, but such an occurrence is
less likely, and can only happen in an incorrect program.
<p>
Second, invalid values for parameters can be detected and rejected
immediately when the "assignment" is made, rather than at the point
where the first use occurs, when it is too late to recover and
reinstate the old value.
For example, an assignment of <tt>*print-level*</tt> to -1 would not
have been caught until the first call to <tt>write</tt> or
<tt>pretty-print</tt>, whereas an attempted assignment of -1 to the
parameter <tt>print-level</tt>, i.e., <tt>(print-level -1)</tt>, is
flagged as an error immediately, before the change is actually made.
<p>
Built-in system parameters are described in different sections
throughout this book and are listed along with other syntactic
forms and procedures in the Summary of Forms in the
back of this book.
Parameters marked "thread parameters" have per-thread values in threaded
versions of <i>Chez Scheme</i>, while the values of parameters marked "global
parameters" are shared by all threads.
Nonthreaded versions of <i>Chez Scheme</i> do not distinguish between
thread and global parameters.
See Sections <a href="./system.html#g120">12.13</a> and <a href="./threads.html#g139">15.6</a> for
more information on creating and manipulating parameters.
<p>
<h3><a name="g4"></a><a name="./intro:h4"></a>Section 1.4. More Information<a name="SECTINTROMOREINFO"></a></h3>
<p>
The articles and technical reports listed below document various
features of <i>Chez Scheme</i> and its implementation:
<p>
<ul>
<li>syntactic abstraction [<a class=citation href="./bibliography.html#g160">14</a>,<a class=citation href="./bibliography.html#g154">8</a>,<a class=citation href="./bibliography.html#g163">17</a>],
<li>modules [<a class=citation href="./bibliography.html#g177">31</a>],
<li>libraries [<a class=citation href="./bibliography.html#g167">21</a>],
<li>storage management [<a class=citation href="./bibliography.html#g158">12</a>,<a class=citation href="./bibliography.html#g159">13</a>],
<li>threads [<a class=citation href="./bibliography.html#g156">10</a>],
<li>multiple return values [<a class=citation href="./bibliography.html#g148">2</a>],
<li>optional arguments [<a class=citation href="./bibliography.html#g162">16</a>],
<li>continuations [<a class=citation href="./bibliography.html#g153">7</a>,<a class=citation href="./bibliography.html#g170">24</a>,<a class=citation href="./bibliography.html#g149">3</a>],
<li>eq? hashtables [<a class=citation href="./bibliography.html#g166">20</a>],
<li>internal definitions, <tt>letrec</tt>, and <tt>letrec*</tt> [<a class=citation href="./bibliography.html#g178">32</a>,<a class=citation href="./bibliography.html#g168">22</a>],
<li><tt>equal?</tt> [<a class=citation href="./bibliography.html#g147">1</a>],
<li>engines [<a class=citation href="./bibliography.html#g161">15</a>],
<li>floating-point printing [<a class=citation href="./bibliography.html#g150">4</a>],
<li>code generation [<a class=citation href="./bibliography.html#g164">18</a>],
<li>register allocation [<a class=citation href="./bibliography.html#g152">6</a>],
<li>procedure inlining [<a class=citation href="./bibliography.html#g176">30</a>],
<li>profiling [<a class=citation href="./bibliography.html#g151">5</a>],
and
<li>history of the implementation [<a class=citation href="./bibliography.html#g155">9</a>].
</ul>
<p>
<p>
Links to abstracts and electronic versions of these publications are
available at the url
<a href=http://www.cs.indiana.edu/chezscheme/pubs/>http://www.cs.indiana.edu/chezscheme/pubs/</a>.
<hr class=copyright align=left>
<p>
<a class=plain href="index.html">Chez Scheme Version 9 User's Guide</a><br>
Copyright © 2016 Cisco Systems, Inc.<br>
Licensed under the <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache License Version 2.0</a>
(<a class=plain href="canned/copyright.html">full copyright notice.</a>).</br>
Revised June 2016 for Chez Scheme Version 9.4<br>
<a class=plain href="canned/about.html">about this book</a>
</tr></table>
</body>
</html>