~ubuntu-branches/ubuntu/quantal/gclcvs/quantal

« back to all changes in this revision

Viewing changes to info/chap-2.texi

  • Committer: Bazaar Package Importer
  • Author(s): Camm Maguire
  • Date: 2004-06-24 15:13:46 UTC
  • Revision ID: james.westby@ubuntu.com-20040624151346-xh0xaaktyyp7aorc
Tags: 2.7.0-26
C_GC_OFFSET is 2 on m68k-linux

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
 
 
3
@node Syntax, Evaluation and Compilation, Introduction (Introduction), Top
 
4
@chapter Syntax
 
5
 
 
6
@menu
 
7
* Character Syntax::            
 
8
* Reader Algorithm::            
 
9
* Interpretation of Tokens::    
 
10
* Standard Macro Characters::   
 
11
@end menu
 
12
 
 
13
@node Character Syntax, Reader Algorithm, Syntax, Syntax
 
14
@section Character Syntax
 
15
 
 
16
@c including concept-syntax
 
17
 
 
18
The @i{Lisp reader} takes @i{characters} from a @i{stream}, 
 
19
interprets them as a printed representation of an @i{object},
 
20
constructs that @i{object}, and returns it.
 
21
 
 
22
The syntax described by this chapter is called the @i{standard syntax}
 
23
@IGindex{standard syntax}
 
24
.
 
25
Operations are provided by @r{Common Lisp} so that
 
26
various aspects of the syntax information represented by a @i{readtable} 
 
27
can be modified under program control; see @ref{Reader}.
 
28
Except as explicitly stated otherwise, 
 
29
the syntax used throughout this document is @i{standard syntax}.
 
30
 
 
31
@menu
 
32
* Readtables::                  
 
33
* Variables that affect the Lisp Reader::  
 
34
* Standard Characters::         
 
35
* Character Syntax Types::      
 
36
@end menu
 
37
 
 
38
@node Readtables, Variables that affect the Lisp Reader, Character Syntax, Character Syntax
 
39
@subsection Readtables
 
40
 
 
41
Syntax information for use by the @i{Lisp reader} is embodied in an
 
42
@i{object} called a @i{readtable}
 
43
@IGindex{readtable}
 
44
.  Among other things, 
 
45
the @i{readtable} contains the association between @i{characters} 
 
46
and @i{syntax types}.
 
47
 
 
48
Figure 2--1 lists some @i{defined names} that are applicable to
 
49
@i{readtables}.
 
50
 
 
51
@format
 
52
@group
 
53
@noindent
 
54
@w{  *readtable*                    readtable-case                }
 
55
@w{  copy-readtable                 readtablep                    }
 
56
@w{  get-dispatch-macro-character   set-dispatch-macro-character  }
 
57
@w{  get-macro-character            set-macro-character           }
 
58
@w{  make-dispatch-macro-character  set-syntax-from-char          }
 
59
 
 
60
@noindent
 
61
@w{              Figure 2--1: Readtable defined names             }
 
62
 
 
63
@end group
 
64
@end format
 
65
 
 
66
@menu
 
67
* The Current Readtable::       
 
68
* The Standard Readtable::      
 
69
* The Initial Readtable::       
 
70
@end menu
 
71
 
 
72
@node The Current Readtable, The Standard Readtable, Readtables, Readtables
 
73
@subsubsection The Current Readtable
 
74
 
 
75
Several @i{readtables} describing different syntaxes can exist,
 
76
but at any given time only one, called the @i{current readtable}
 
77
@IGindex{current readtable}
 
78
 
79
affects the way in which @i{expressions}_2 are parsed 
 
80
into @i{objects} by the @i{Lisp reader}.
 
81
The @i{current readtable} in a given @i{dynamic environment}
 
82
is the @i{value} of @b{*readtable*} in that @i{environment}.
 
83
To make a different @i{readtable} become the @i{current readtable},
 
84
@b{*readtable*} can be @i{assigned} or @i{bound}.
 
85
 
 
86
@node The Standard Readtable, The Initial Readtable, The Current Readtable, Readtables
 
87
@subsubsection The Standard Readtable
 
88
 
 
89
The @i{standard readtable}
 
90
@IGindex{standard readtable}
 
91
 conforms to @i{standard syntax}.
 
92
The consequences are undefined if an attempt is made
 
93
to modify the @i{standard readtable}.
 
94
To achieve the effect of altering or extending @i{standard syntax},
 
95
a copy of the @i{standard readtable} can be created; see the @i{function} @b{copy-readtable}.
 
96
 
 
97
The @i{readtable case} of the @i{standard readtable} is @t{:upcase}.
 
98
 
 
99
@node The Initial Readtable,  , The Standard Readtable, Readtables
 
100
@subsubsection The Initial Readtable
 
101
 
 
102
The @i{initial readtable}
 
103
@IGindex{initial readtable}
 
104
 is
 
105
the @i{readtable} that is the @i{current readtable}
 
106
at the time when the @i{Lisp image} starts.
 
107
At that time, it conforms to @i{standard syntax}.
 
108
The @i{initial readtable} is @i{distinct} 
 
109
from the @i{standard readtable}.
 
110
It is permissible for a @i{conforming program} 
 
111
to modify the @i{initial readtable}.
 
112
 
 
113
@node Variables that affect the Lisp Reader, Standard Characters, Readtables, Character Syntax
 
114
@subsection Variables that affect the Lisp Reader
 
115
 
 
116
The @i{Lisp reader} is influenced not only by the @i{current readtable},
 
117
but also by various @i{dynamic variables}.  Figure 2--2 lists
 
118
the @i{variables} that influence the behavior of the @i{Lisp reader}.
 
119
 
 
120
@format
 
121
@group
 
122
@noindent
 
123
@w{  *package*    *read-default-float-format*  *readtable*  }
 
124
@w{  *read-base*  *read-suppress*                           }
 
125
 
 
126
@noindent
 
127
@w{  Figure 2--2: Variables that influence the Lisp reader. }
 
128
 
 
129
@end group
 
130
@end format
 
131
 
 
132
@node Standard Characters, Character Syntax Types, Variables that affect the Lisp Reader, Character Syntax
 
133
@subsection Standard Characters
 
134
 
 
135
All @i{implementations} must support a @i{character} @i{repertoire}
 
136
called @b{standard-char}; @i{characters} that are members of that
 
137
@i{repertoire} are called @i{standard characters}
 
138
@IGindex{standard character}
 
139
.
 
140
 
 
141
The @b{standard-char} @i{repertoire} consists of
 
142
the @i{non-graphic} @i{character} @i{newline},
 
143
the @i{graphic} @i{character} @i{space},
 
144
and the following additional
 
145
ninety-four @i{graphic} @i{characters} or their equivalents:
 
146
 
 
147
@format
 
148
@group
 
149
@noindent
 
150
@w{  Graphic ID  Glyph  Description  Graphic ID  Glyph  Description  }
 
151
@w{  LA01        @t{a}      small a      LN01        @t{n}      small n      }
 
152
@w{  LA02        @t{A}      capital A    LN02        @t{N}      capital N    }
 
153
@w{  LB01        @t{b}      small b      LO01        @t{o}      small o      }
 
154
@w{  LB02        @t{B}      capital B    LO02        @t{O}      capital O    }
 
155
@w{  LC01        @t{c}      small c      LP01        @t{p}      small p      }
 
156
@w{  LC02        @t{C}      capital C    LP02        @t{P}      capital P    }
 
157
@w{  LD01        @t{d}      small d      LQ01        @t{q}      small q      }
 
158
@w{  LD02        @t{D}      capital D    LQ02        @t{Q}      capital Q    }
 
159
@w{  LE01        @t{e}      small e      LR01        @t{r}      small r      }
 
160
@w{  LE02        @t{E}      capital E    LR02        @t{R}      capital R    }
 
161
@w{  LF01        @t{f}      small f      LS01        @t{s}      small s      }
 
162
@w{  LF02        @t{F}      capital F    LS02        @t{S}      capital S    }
 
163
@w{  LG01        @t{g}      small g      LT01        @t{t}      small t      }
 
164
@w{  LG02        @t{G}      capital G    LT02        @t{T}      capital T    }
 
165
@w{  LH01        @t{h}      small h      LU01        @t{u}      small u      }
 
166
@w{  LH02        @t{H}      capital H    LU02        @t{U}      capital U    }
 
167
@w{  LI01        @t{i}      small i      LV01        @t{v}      small v      }
 
168
@w{  LI02        @t{I}      capital I    LV02        @t{V}      capital V    }
 
169
@w{  LJ01        @t{j}      small j      LW01        @t{w}      small w      }
 
170
@w{  LJ02        @t{J}      capital J    LW02        @t{W}      capital W    }
 
171
@w{  LK01        @t{k}      small k      LX01        @t{x}      small x      }
 
172
@w{  LK02        @t{K}      capital K    LX02        @t{X}      capital X    }
 
173
@w{  LL01        @t{l}      small l      LY01        @t{y}      small y      }
 
174
@w{  LL02        @t{L}      capital L    LY02        @t{Y}      capital Y    }
 
175
@w{  LM01        @t{m}      small m      LZ01        @t{z}      small z      }
 
176
@w{  LM02        @t{M}      capital M    LZ02        @t{Z}      capital Z    }
 
177
 
 
178
@noindent
 
179
@w{  Figure 2--3: Standard Character Subrepertoire (Part 1 of 3: Latin Characters)}
 
180
 
 
181
@end group
 
182
@end format
 
183
 
 
184
@format
 
185
@group
 
186
@noindent
 
187
@w{  Graphic ID  Glyph  Description  Graphic ID  Glyph  Description  }
 
188
@w{  ND01        @t{1}      digit 1      ND06        @t{6}      digit 6      }
 
189
@w{  ND02        @t{2}      digit 2      ND07        @t{7}      digit 7      }
 
190
@w{  ND03        @t{3}      digit 3      ND08        @t{8}      digit 8      }
 
191
@w{  ND04        @t{4}      digit 4      ND09        @t{9}      digit 9      }
 
192
@w{  ND05        @t{5}      digit 5      ND10        @t{0}      digit 0      }
 
193
 
 
194
@noindent
 
195
@w{  Figure 2--4: Standard Character Subrepertoire (Part 2 of 3: Numeric Characters)}
 
196
 
 
197
@end group
 
198
@end format
 
199
 
 
200
@format
 
201
@group
 
202
@noindent
 
203
@w{  Graphic ID  Glyph  Description                              }
 
204
@w{  SP02        @t{!}      exclamation mark                         }
 
205
@w{  SC03        @t{$}     dollar sign                              }
 
206
@w{  SP04        @t{"}      quotation mark, or double quote          }
 
207
@w{  SP05        @t{'}      apostrophe, or @r{[}single@r{]} quote            }
 
208
@w{  SP06        @t{(}      left parenthesis, or open parenthesis    }
 
209
@w{  SP07        @t{)}      right parenthesis, or close parenthesis  }
 
210
@w{  SP08        @t{,}      comma                                    }
 
211
@w{  SP09        @t{_}      low line, or underscore                  }
 
212
@w{  SP10        @t{-}      hyphen, or minus @r{[}sign@r{]}                  }
 
213
@w{  SP11        @t{.}      full stop, period, or dot                }
 
214
@w{  SP12        @t{/}      solidus, or slash                        }
 
215
@w{  SP13        @t{:}      colon                                    }
 
216
@w{  SP14        @t{;}      semicolon                                }
 
217
@w{  SP15        @t{?}      question mark                            }
 
218
@w{  SA01        @t{+}      plus @r{[}sign@r{]}                              }
 
219
@w{  SA03        @t{<}      less-than @r{[}sign@r{]}                         }
 
220
@w{  SA04        @t{=}      equals @r{[}sign@r{]}                            }
 
221
@w{  SA05        @t{>}      greater-than @r{[}sign@r{]}                      }
 
222
@w{  SM01        @t{#}      number sign, or sharp@r{[}sign@r{]}              }
 
223
@w{  SM02        @t{%}      percent @r{[}sign@r{]}                           }
 
224
@w{  SM03        @t{&}      ampersand                                }
 
225
@w{  SM04        @t{*}      asterisk, or star                        }
 
226
@w{  SM05        @t{@@}      commercial at, or at-sign                }
 
227
@w{  SM06        @t{[}      left @r{[}square@r{]} bracket                    }
 
228
@w{  SM07        @t{\}      reverse solidus, or backslash            }
 
229
@w{  SM08        @t{]}      right @r{[}square@r{]} bracket                   }
 
230
@w{  SM11        @t{@{}      left curly bracket, or left brace        }
 
231
@w{  SM13        @t{|}      vertical bar                             }
 
232
@w{  SM14        @t{@}}      right curly bracket, or right brace      }
 
233
@w{  SD13        @t{`}      grave accent, or backquote               }
 
234
@w{  SD15        @t{@t{^}}      circumflex accent                        }
 
235
@w{  SD19        @t{~}      tilde                                    }
 
236
 
 
237
@noindent
 
238
@w{  Figure 2--5: Standard Character Subrepertoire (Part 3 of 3: Special Characters)}
 
239
 
 
240
@end group
 
241
@end format
 
242
 
 
243
The graphic IDs are not used within @r{Common Lisp},
 
244
but are provided for cross reference purposes with @r{ISO 6937/2}.
 
245
Note that the first letter of the graphic ID 
 
246
categorizes the character as follows:
 
247
L---Latin, N---Numeric, S---Special.
 
248
 
 
249
@node Character Syntax Types,  , Standard Characters, Character Syntax
 
250
@subsection Character Syntax Types
 
251
 
 
252
The @i{Lisp reader} constructs an @i{object} 
 
253
from the input text by interpreting each @i{character} 
 
254
according to its @i{syntax type}.
 
255
The @i{Lisp reader} cannot accept as input 
 
256
everything that the @i{Lisp printer} produces,
 
257
and the @i{Lisp reader} has features that are not used by the @i{Lisp printer}.
 
258
The @i{Lisp reader} can be used as a lexical analyzer 
 
259
for a more general user-written parser.
 
260
 
 
261
When the @i{Lisp reader} is invoked, it reads a single character from 
 
262
the @i{input} @i{stream} and dispatches according to the
 
263
@i{syntax type}
 
264
@IGindex{syntax type}
 
265
 of that @i{character}.
 
266
Every @i{character} that can appear in the @i{input} @i{stream}
 
267
is of one of the @i{syntax types} shown in @i{Figure~2--6}.
 
268
 
 
269
@format
 
270
@group
 
271
@noindent
 
272
@w{  @i{constituent}  @i{macro character}  @i{single escape}  }
 
273
@w{  @i{invalid}      @i{multiple escape}  @i{whitespace}_2   }
 
274
 
 
275
@noindent
 
276
@w{  Figure 2--6: Possible Character Syntax Types }
 
277
 
 
278
@end group
 
279
@end format
 
280
 
 
281
The @i{syntax type} of a @i{character} in a @i{readtable}
 
282
determines how that character is interpreted by the @i{Lisp reader}
 
283
while that @i{readtable} is the @i{current readtable}.
 
284
At any given time, every character has exactly one @i{syntax type}.
 
285
 
 
286
@i{Figure~2--7} 
 
287
lists the @i{syntax type} of each @i{character} in @i{standard syntax}.
 
288
 
 
289
 
 
290
 
 
291
@format
 
292
@group
 
293
@noindent
 
294
@w{  character  syntax type                 character  syntax type             }
 
295
@w{  Backspace  @i{constituent}                 0--9       @i{constituent}             }
 
296
@w{  Tab        @i{whitespace}_2                :          @i{constituent}             }
 
297
@w{  Newline    @i{whitespace}_2                ;          @i{terminating} @i{macro char}  }
 
298
@w{  Linefeed   @i{whitespace}_2                @t{<}          @i{constituent}             }
 
299
@w{  Page       @i{whitespace}_2                =          @i{constituent}             }
 
300
@w{  Return     @i{whitespace}_2                @t{>}          @i{constituent}             }
 
301
@w{  Space      @i{whitespace}_2                ?          @i{constituent}*            }
 
302
@w{  !          @i{constituent}*                @t{@@}          @i{constituent}             }
 
303
@w{  @t{"}          @i{terminating} @i{macro char}      A--Z       @i{constituent}             }
 
304
@w{  #          @i{non-terminating} @i{macro char}  @t{[}          @i{constituent}*            }
 
305
@w{  $         @i{constituent}                 @t{\}          @i{single escape}           }
 
306
@w{  %          @i{constituent}                 @t{]}          @i{constituent}*            }
 
307
@w{  &          @i{constituent}                 @t{^}          @i{constituent}             }
 
308
@w{  '          @i{terminating} @i{macro char}      @t{_}          @i{constituent}             }
 
309
@w{  (          @i{terminating} @i{macro char}      `          @i{terminating} @i{macro char}  }
 
310
@w{  )          @i{terminating} @i{macro char}      a--z       @i{constituent}             }
 
311
@w{  @t{*}          @i{constituent}                 @t{@{}          @i{constituent}*            }
 
312
@w{  +          @i{constituent}                 @t{|}          @i{multiple escape}         }
 
313
@w{  ,          @i{terminating} @i{macro char}      @t{@}}          @i{constituent}*            }
 
314
@w{  -          @i{constituent}                 @t{~}          @i{constituent}             }
 
315
@w{  .          @i{constituent}                 Rubout     @i{constituent}             }
 
316
@w{  /          @i{constituent}                 }
 
317
 
 
318
@noindent
 
319
@w{            Figure 2--7: Character Syntax Types in Standard Syntax          }
 
320
 
 
321
@end group
 
322
@end format
 
323
 
 
324
 
 
325
The characters marked with an asterisk (*) are initially @i{constituents},
 
326
but they are not used in any standard @r{Common Lisp} notations.
 
327
These characters are explicitly reserved to the @i{programmer}.
 
328
@t{~} is not used in @r{Common Lisp}, and reserved to implementors.
 
329
@t{$} and @t{%} are @i{alphabetic}_2 @i{characters},
 
330
but are not used in the names of any standard @r{Common Lisp} @i{defined names}.
 
331
 
 
332
@i{Whitespace}_2 characters serve as separators but are otherwise
 
333
ignored.  @i{Constituent} and @i{escape} @i{characters} are accumulated
 
334
to make a @i{token}, which is then interpreted as a @i{number} or @i{symbol}.
 
335
@i{Macro characters} trigger the invocation of @i{functions} (possibly
 
336
user-supplied) that can perform arbitrary parsing actions.
 
337
@i{Macro characters} are divided into two kinds,
 
338
@i{terminating} and @i{non-terminating},
 
339
depending on whether or not they terminate a @i{token}.
 
340
The following are descriptions of each kind of @i{syntax type}.
 
341
 
 
342
@menu
 
343
* Constituent Characters::      
 
344
* Constituent Traits::          
 
345
* Invalid Characters::          
 
346
* Macro Characters::            
 
347
* Multiple Escape Characters::  
 
348
* Examples of Multiple Escape Characters::  
 
349
* Single Escape Character::     
 
350
* Examples of Single Escape Characters::  
 
351
* Whitespace Characters::       
 
352
* Examples of Whitespace Characters::  
 
353
@end menu
 
354
 
 
355
@node Constituent Characters, Constituent Traits, Character Syntax Types, Character Syntax Types
 
356
@subsubsection Constituent Characters
 
357
 
 
358
@i{Constituent} @i{characters} are used in @i{tokens}.
 
359
A @i{token}
 
360
@IGindex{token}
 
361
 is a representation of a @i{number} or a @i{symbol}.  
 
362
Examples of @i{constituent} @i{characters} are letters and digits.
 
363
 
 
364
Letters in symbol names are sometimes converted to 
 
365
letters in the opposite @i{case} when the name is read;
 
366
see @ref{Effect of Readtable Case on the Lisp Reader}.
 
367
@i{Case} conversion can be suppressed by the use 
 
368
of @i{single escape} or @i{multiple escape} characters.
 
369
 
 
370
@node Constituent Traits, Invalid Characters, Constituent Characters, Character Syntax Types
 
371
@subsubsection Constituent Traits
 
372
 
 
373
Every @i{character} has one or more @i{constituent traits}
 
374
that define how the @i{character} is to be interpreted by the @i{Lisp reader}
 
375
when the @i{character} is a @i{constituent} @i{character}.
 
376
These @i{constituent traits} are 
 
377
     @i{alphabetic}_2,                  
 
378
     digit,
 
379
     @i{package marker},
 
380
     plus sign,
 
381
     minus sign, 
 
382
     dot,
 
383
     decimal point,
 
384
     @i{ratio marker},
 
385
     @i{exponent marker},
 
386
 and @i{invalid}.
 
387
@i{Figure~2--8} shows the @i{constituent traits}
 
388
of the @i{standard characters}
 
389
and of certain @i{semi-standard} @i{characters};
 
390
no mechanism is provided for changing the @i{constituent trait} of a @i{character}.
 
391
Any @i{character} with the alphadigit @i{constituent trait}
 
392
in that figure is a digit if the @i{current input base} is greater
 
393
than that character's digit value,
 
394
otherwise the @i{character} is @i{alphabetic}_2.  
 
395
Any @i{character} quoted by a @i{single escape} 
 
396
is treated as an @i{alphabetic}_2 constituent, regardless of its normal syntax.
 
397
 
 
398
@format
 
399
@group
 
400
@noindent
 
401
@w{ constituent traits         constituent traits                                   }
 
402
@w{ character                  character   }
 
403
@w{ ________________________________________________________________________________}
 
404
@w{ Backspace   @i{invalid}        @t{@{}           @i{alphabetic}_2                             }
 
405
@w{ Tab         @i{invalid}*       @t{@}}           @i{alphabetic}_2                             }
 
406
@w{ Newline     @i{invalid}*       +           @i{alphabetic}_2, plus sign                  }
 
407
@w{ Linefeed    @i{invalid}*       -           @i{alphabetic}_2, minus sign                 }
 
408
@w{ Page        @i{invalid}*       .           @i{alphabetic}_2, dot, decimal point         }
 
409
@w{ Return      @i{invalid}*       /           @i{alphabetic}_2, @i{ratio marker}               }
 
410
@w{ Space       @i{invalid}*       A, a        alphadigit                               }
 
411
@w{ !           @i{alphabetic}_2   B, b        alphadigit                               }
 
412
@w{ @t{"}           @i{alphabetic}_2*  C, c        alphadigit                               }
 
413
@w{ #           @i{alphabetic}_2*  D, d        alphadigit, double-float @i{exponent marker} }
 
414
@w{ $          @i{alphabetic}_2   E, e        alphadigit, float @i{exponent marker}        }
 
415
@w{ %           @i{alphabetic}_2   F, f        alphadigit, single-float @i{exponent marker} }
 
416
@w{ &           @i{alphabetic}_2   G, g        alphadigit                               }
 
417
@w{ '           @i{alphabetic}_2*  H, h        alphadigit                               }
 
418
@w{ (           @i{alphabetic}_2*  I, i        alphadigit                               }
 
419
@w{ )           @i{alphabetic}_2*  J, j        alphadigit                               }
 
420
@w{ @t{*}           @i{alphabetic}_2   K, k        alphadigit                               }
 
421
@w{ ,           @i{alphabetic}_2*  L, l        alphadigit, long-float @i{exponent marker}   }
 
422
@w{ 0-9         alphadigit     M, m        alphadigit                               }
 
423
@w{ :           @i{package marker} N, n        alphadigit                               }
 
424
@w{ ;           @i{alphabetic}_2*  O, o        alphadigit                               }
 
425
@w{ @t{<}           @i{alphabetic}_2   P, p        alphadigit                               }
 
426
@w{ =           @i{alphabetic}_2   Q, q        alphadigit                               }
 
427
@w{ @t{>}           @i{alphabetic}_2   R, r        alphadigit                               }
 
428
@w{ ?           @i{alphabetic}_2   S, s        alphadigit, short-float @i{exponent marker}  }
 
429
@w{ @t{@@}           @i{alphabetic}_2   T, t        alphadigit                               }
 
430
@w{ @t{[}           @i{alphabetic}_2   U, u        alphadigit                               }
 
431
@w{ @t{\}           @i{alphabetic}_2*  V, v        alphadigit                               }
 
432
@w{ @t{]}           @i{alphabetic}_2   W, w        alphadigit                               }
 
433
@w{ @t{^}           @i{alphabetic}_2   X, x        alphadigit                               }
 
434
@w{ @t{_}           @i{alphabetic}_2   Y, y        alphadigit                               }
 
435
@w{ `           @i{alphabetic}_2*  Z, z        alphadigit                               }
 
436
@w{ @t{|}           @i{alphabetic}_2*  Rubout      @i{invalid}                                  }
 
437
@w{ @t{~}           @i{alphabetic}_2   }
 
438
@end group
 
439
@end format
 
440
 
 
441
@w{  Figure 2--8: Constituent Traits of Standard Characters and Semi-Standard Characters}
 
442
 
 
443
The interpretations in this table apply only to @i{characters}
 
444
whose @i{syntax type} is @i{constituent}.
 
445
Entries marked with an asterisk (*) are normally @i{shadowed}_2 
 
446
because the indicated @i{characters} are of @i{syntax type}
 
447
@i{whitespace}_2,
 
448
@i{macro character},
 
449
@i{single escape},
 
450
or @i{multiple escape};
 
451
these @i{constituent traits} apply to them only if their @i{syntax types} 
 
452
are changed to @i{constituent}.
 
453
 
 
454
@node Invalid Characters, Macro Characters, Constituent Traits, Character Syntax Types
 
455
@subsubsection Invalid Characters
 
456
 
 
457
@i{Characters} with the @i{constituent trait} @i{invalid} 
 
458
cannot ever appear in a @i{token} 
 
459
except under the control of a @i{single escape} @i{character}.
 
460
If an @i{invalid} @i{character} is encountered while an @i{object} is
 
461
being read, an error of @i{type} @b{reader-error} is signaled.
 
462
If an @i{invalid} @i{character} is preceded by a @i{single escape} @i{character},
 
463
it is treated as an @i{alphabetic}_2 @i{constituent} instead.
 
464
 
 
465
@node Macro Characters, Multiple Escape Characters, Invalid Characters, Character Syntax Types
 
466
@subsubsection Macro Characters
 
467
 
 
468
When the @i{Lisp reader} encounters a @i{macro character} 
 
469
on an @i{input} @i{stream},
 
470
special parsing of subsequent @i{characters} 
 
471
on the @i{input} @i{stream} 
 
472
is performed.
 
473
 
 
474
A @i{macro character} has an associated @i{function}
 
475
called a @i{reader macro function}
 
476
@IGindex{reader macro function}
 
477
 that implements its specialized parsing behavior.
 
478
An association of this kind can be established or modified under control of
 
479
a @i{conforming program} by using 
 
480
the @i{functions} @b{set-macro-character} and @b{set-dispatch-macro-character}.
 
481
 
 
482
Upon encountering a @i{macro character}, the @i{Lisp reader} calls its
 
483
@i{reader macro function}, which parses one specially formatted object 
 
484
from the @i{input} @i{stream}.
 
485
The @i{function} either returns the parsed @i{object},
 
486
or else it returns no @i{values} 
 
487
    to indicate that the characters scanned by the @i{function}
 
488
    are being ignored (@i{e.g.}, in the case of a comment).
 
489
Examples of @i{macro characters}
 
490
are @i{backquote}, @i{single-quote}, @i{left-parenthesis}, and 
 
491
@i{right-parenthesis}.
 
492
 
 
493
A @i{macro character} is either @i{terminating} or @i{non-terminating}.
 
494
The difference between @i{terminating} and @i{non-terminating} @i{macro characters} 
 
495
lies in what happens when such characters occur in the middle of a @i{token}.  
 
496
If a @i{non-terminating}
 
497
@IGindex{non-terminating}
 
498
 @i{macro character} occurs in the middle of a @i{token},
 
499
the @i{function} associated 
 
500
with the @i{non-terminating} @i{macro character} is not called,
 
501
and the
 
502
@i{non-terminating} @i{macro character} does not terminate the @i{token}'s name; it
 
503
becomes part of the name as if the @i{macro character} were really a constituent
 
504
character.  A @i{terminating}
 
505
@IGindex{terminating}
 
506
 @i{macro character} terminates any @i{token},
 
507
and its associated @i{reader macro function}
 
508
is called no matter where the @i{character} appears.
 
509
The only @i{non-terminating} @i{macro character} in @i{standard syntax} 
 
510
is @i{sharpsign}.
 
511
 
 
512
If a @i{character} is a @i{dispatching macro character} C_1,
 
513
its @i{reader macro function} is a @i{function} supplied by the @i{implementation}.
 
514
This @i{function} reads decimal @i{digit} @i{characters} until a non-@i{digit}
 
515
C_2 is read.
 
516
If any @i{digits} were read,
 
517
they are converted into a corresponding @i{integer} infix parameter P;
 
518
otherwise, the infix parameter P is @b{nil}.  
 
519
The terminating non-@i{digit} C_2 is a @i{character} 
 
520
(sometimes called a ``sub-character'' to emphasize its subordinate role in the dispatching)
 
521
that is looked up in the dispatch table associated with
 
522
the @i{dispatching macro character} C_1.
 
523
The @i{reader macro function} associated with the sub-character C_2 
 
524
is invoked with three arguments:
 
525
     the @i{stream},
 
526
     the sub-character C_2,
 
527
 and the infix parameter P.
 
528
For more information about dispatch characters,
 
529
see the @i{function} @b{set-dispatch-macro-character}.
 
530
 
 
531
For information about the @i{macro characters} 
 
532
that are available in @i{standard syntax},
 
533
see @ref{Standard Macro Characters}.
 
534
 
 
535
@node Multiple Escape Characters, Examples of Multiple Escape Characters, Macro Characters, Character Syntax Types
 
536
@subsubsection Multiple Escape Characters
 
537
 
 
538
A pair of @i{multiple escape}
 
539
@IGindex{multiple escape}
 
540
 @i{characters}
 
541
is used to indicate that an enclosed sequence of characters,
 
542
including possible @i{macro characters} and @i{whitespace}_2 @i{characters},
 
543
are to be treated as @i{alphabetic}_2 @i{characters} 
 
544
with @i{case} preserved.
 
545
Any @i{single escape} and @i{multiple escape} @i{characters} 
 
546
that are to appear in the sequence must be preceded by a @i{single escape} 
 
547
@i{character}.  
 
548
 
 
549
@i{Vertical-bar} is a @i{multiple escape} @i{character}
 
550
in @i{standard syntax}.
 
551
 
 
552
@node Examples of Multiple Escape Characters, Single Escape Character, Multiple Escape Characters, Character Syntax Types
 
553
@subsubsection Examples of Multiple Escape Characters
 
554
 
 
555
@example
 
556
 ;; The following examples assume the readtable case of *readtable* 
 
557
 ;; and *print-case* are both :upcase.
 
558
 (eq 'abc 'ABC) @result{}  @i{true}
 
559
 (eq 'abc '|ABC|) @result{}  @i{true}
 
560
 (eq 'abc 'a|B|c) @result{}  @i{true}
 
561
 (eq 'abc '|abc|) @result{}  @i{false}
 
562
@end example
 
563
 
 
564
@node Single Escape Character, Examples of Single Escape Characters, Examples of Multiple Escape Characters, Character Syntax Types
 
565
@subsubsection Single Escape Character
 
566
 
 
567
A @i{single escape}
 
568
@IGindex{single escape}
 
569
 is used to indicate that 
 
570
the next @i{character} is to be treated as 
 
571
an @i{alphabetic}_2 @i{character}
 
572
with its @i{case} preserved,
 
573
no matter what the @i{character} is 
 
574
or which @i{constituent traits} it has.  
 
575
 
 
576
@i{Slash} is a @i{single escape} @i{character}
 
577
in @i{standard syntax}.
 
578
 
 
579
@node Examples of Single Escape Characters, Whitespace Characters, Single Escape Character, Character Syntax Types
 
580
@subsubsection Examples of Single Escape Characters
 
581
 
 
582
@example
 
583
 ;; The following examples assume the readtable case of *readtable* 
 
584
 ;; and *print-case* are both :upcase.
 
585
 (eq 'abc '\A\B\C) @result{}  @i{true}
 
586
 (eq 'abc 'a\Bc) @result{}  @i{true}
 
587
 (eq 'abc '\ABC) @result{}  @i{true}
 
588
 (eq 'abc '\abc) @result{}  @i{false}
 
589
@end example
 
590
 
 
591
@node Whitespace Characters, Examples of Whitespace Characters, Examples of Single Escape Characters, Character Syntax Types
 
592
@subsubsection Whitespace Characters
 
593
 
 
594
@i{Whitespace}_2 @i{characters} are used to separate @i{tokens}.
 
595
 
 
596
@i{Space} and @i{newline} are @i{whitespace}_2 @i{characters}
 
597
in @i{standard syntax}.
 
598
 
 
599
@node Examples of Whitespace Characters,  , Whitespace Characters, Character Syntax Types
 
600
@subsubsection Examples of Whitespace Characters
 
601
 
 
602
@example
 
603
 (length '(this-that)) @result{}  1
 
604
 (length '(this - that)) @result{}  3
 
605
 (length '(a
 
606
           b)) @result{}  2
 
607
 (+ 34) @result{}  34
 
608
 (+ 3 4) @result{}  7
 
609
@end example
 
610
 
 
611
@c end of including concept-syntax
 
612
 
 
613
@node Reader Algorithm, Interpretation of Tokens, Character Syntax, Syntax
 
614
@section Reader Algorithm
 
615
 
 
616
@c including concept-reader-algorithm
 
617
 
 
618
This section describes the algorithm used by the @i{Lisp reader}
 
619
to parse @i{objects} from an @i{input} @i{character} @i{stream},
 
620
including how the @i{Lisp reader} processes @i{macro characters}.
 
621
 
 
622
When dealing with @i{tokens}, the reader's basic function is to distinguish
 
623
representations of @i{symbols} from those of @i{numbers}.
 
624
When a @i{token} is accumulated, it is assumed to represent a @i{number} if it
 
625
satisfies the syntax for numbers listed in @i{Figure~2--9}.
 
626
If it does not represent a @i{number},
 
627
it is then assumed to be a @i{potential number} 
 
628
if it satisfies the rules governing the syntax for a @i{potential number}.
 
629
If a valid @i{token} is neither a representation of a @i{number} 
 
630
                               nor a @i{potential number},
 
631
it represents a @i{symbol}.
 
632
 
 
633
The algorithm performed by the @i{Lisp reader} is as follows:
 
634
 
 
635
@table @asis
 
636
 
 
637
@item 1.  
 
638
If at end of file, end-of-file processing is performed as specified
 
639
in @b{read}.
 
640
Otherwise,
 
641
one @i{character}, @i{x},  is read from the @i{input} @i{stream}, and
 
642
dispatched according to the @i{syntax type} of @i{x} to one
 
643
of steps 2 to 7.
 
644
 
 
645
@item 2.  
 
646
If @i{x} is an @i{invalid} @i{character},
 
647
an error of @i{type} @b{reader-error} is signaled.
 
648
 
 
649
@item 3.  
 
650
If @i{x} is a @i{whitespace}_2 @i{character},
 
651
then it is discarded and step 1 is re-entered.
 
652
 
 
653
@item 4.  
 
654
If @i{x} is a @i{terminating} or @i{non-terminating} @i{macro character}
 
655
then its associated @i{reader macro function} is called with two @i{arguments},
 
656
the @i{input} @i{stream} and @i{x}.
 
657
 
 
658
The @i{reader macro function} may read @i{characters} 
 
659
from the @i{input} @i{stream}; 
 
660
if it does, it will see those @i{characters} following the @i{macro character}.
 
661
The @i{Lisp reader} may be invoked recursively from the @i{reader macro function}.
 
662
 
 
663
The @i{reader macro function} must not have any side effects other than on the
 
664
@i{input} @i{stream};
 
665
because of backtracking and restarting of the @b{read} operation,
 
666
front ends to the @i{Lisp reader} (@i{e.g.}, ``editors'' and ``rubout handlers'') 
 
667
may cause the @i{reader macro function} to be called repeatedly during the
 
668
reading of a single @i{expression} in which @i{x} only appears once.
 
669
 
 
670
The @i{reader macro function} may return zero values or one value.
 
671
If one value is returned,
 
672
then that value is returned as the result of the read operation;
 
673
the algorithm is done.
 
674
If zero values are returned, then step 1 is re-entered.
 
675
 
 
676
@item 5.  
 
677
If @i{x} is a @i{single escape} @i{character}
 
678
then the next @i{character}, @i{y}, is read, or an error of @i{type} @b{end-of-file} 
 
679
is signaled if at the end of file.
 
680
@i{y} is treated as if it is a @i{constituent} 
 
681
whose only @i{constituent trait} is @i{alphabetic}_2.
 
682
@i{y} is used to begin a @i{token}, and step 8 is entered.
 
683
 
 
684
@item 6.  
 
685
If @i{x} is a @i{multiple escape} @i{character}
 
686
then a @i{token} (initially
 
687
containing no @i{characters}) is  begun and step 9 is entered.
 
688
 
 
689
@item 7.  
 
690
If @i{x} is a @i{constituent} @i{character}, then it begins a @i{token}.
 
691
After the @i{token} is read in, it will be interpreted
 
692
either as a @r{Lisp} @i{object} or as being of invalid syntax.
 
693
If the @i{token} represents an @i{object},
 
694
that @i{object} is returned as the result of the read operation.
 
695
If the @i{token} is of invalid syntax, an error is signaled.
 
696
If @i{x} is a @i{character} with @i{case},
 
697
it might be replaced with the corresponding @i{character} of the opposite @i{case}, 
 
698
depending on the @i{readtable case} of the @i{current readtable},
 
699
as outlined in @ref{Effect of Readtable Case on the Lisp Reader}.
 
700
@i{X} is used to begin a @i{token}, and step 8 is entered.
 
701
 
 
702
@item 8.  
 
703
At this point a @i{token} is being accumulated, and an even number
 
704
of @i{multiple escape} @i{characters} have been encountered.
 
705
If at end of file, step 10 is entered.
 
706
Otherwise, a @i{character}, @i{y}, is read, and
 
707
one of the following actions is performed according to its @i{syntax type}:
 
708
 
 
709
@table @asis
 
710
 
 
711
@item @t{*}  
 
712
If @i{y} is a @i{constituent} or @i{non-terminating} @i{macro character}:
 
713
@table @asis
 
714
 
 
715
@item --  
 
716
If @i{y} is a @i{character} with @i{case},
 
717
it might be replaced with the corresponding @i{character} of the opposite @i{case}, 
 
718
depending on the @i{readtable case} of the @i{current readtable},
 
719
as outlined in @ref{Effect of Readtable Case on the Lisp Reader}.
 
720
@item --  
 
721
@i{Y} is appended to the @i{token} being built.
 
722
@item --  
 
723
Step 8 is repeated.
 
724
@end table
 
725
 
 
726
@item @t{*}  
 
727
If @i{y} is a @i{single escape} @i{character}, then the next @i{character},
 
728
@i{z}, is read, or an error of @i{type} @b{end-of-file} is signaled if at end of file.
 
729
@i{Z} is treated as if it is a @i{constituent} 
 
730
whose only @i{constituent trait} is @i{alphabetic}_2.
 
731
@i{Z} is appended to the @i{token} being built,
 
732
and step 8 is repeated.
 
733
 
 
734
@item @t{*}  
 
735
If @i{y} is a @i{multiple escape} @i{character},
 
736
then step 9 is entered.
 
737
 
 
738
@item @t{*}  
 
739
If @i{y} is an @i{invalid} @i{character},
 
740
an error of @i{type} @b{reader-error} is signaled.
 
741
 
 
742
@item @t{*}  
 
743
If @i{y} is a @i{terminating} @i{macro character},
 
744
then it terminates the @i{token}.
 
745
First the @i{character} @i{y} is unread (see @b{unread-char}),
 
746
and then step 10 is entered.
 
747
 
 
748
@item @t{*}  
 
749
If @i{y} is a @i{whitespace}_2 @i{character}, then it terminates
 
750
the @i{token}.  First the @i{character} @i{y} is unread
 
751
if appropriate (see @b{read-preserving-whitespace}),
 
752
and then step 10 is entered.
 
753
@end table
 
754
 
 
755
@item 9.  
 
756
At this point a @i{token} is being accumulated, and an odd number
 
757
of @i{multiple escape} @i{characters} have been encountered.
 
758
If at end of file, an error of @i{type} @b{end-of-file} is signaled.
 
759
Otherwise, a @i{character}, @i{y}, is read, and
 
760
one of the following actions is performed according to its @i{syntax type}:
 
761
 
 
762
@table @asis
 
763
 
 
764
@item @t{*}  
 
765
If @i{y} is a @i{constituent}, macro, or @i{whitespace}_2 @i{character},
 
766
@i{y} is treated as a @i{constituent} 
 
767
whose only @i{constituent trait} is @i{alphabetic}_2.             
 
768
@i{Y} is appended to the @i{token} being built, and step 9 is repeated.
 
769
 
 
770
@item @t{*}  
 
771
If @i{y} is a @i{single escape} @i{character}, then the next @i{character},
 
772
@i{z}, is read, or an error of @i{type} @b{end-of-file} is signaled if at end of file.
 
773
@i{Z} is treated as a @i{constituent}
 
774
whose only @i{constituent trait} is @i{alphabetic}_2.
 
775
@i{Z} is appended to the @i{token} being built,
 
776
and step 9 is repeated.
 
777
 
 
778
@item @t{*}  
 
779
If @i{y} is a @i{multiple escape} @i{character},
 
780
then step 8 is entered.
 
781
 
 
782
@item @t{*}  
 
783
If @i{y} is an @i{invalid} @i{character},
 
784
an error of @i{type} @b{reader-error} is signaled.
 
785
@end table
 
786
 
 
787
@item 10.  
 
788
An entire @i{token} has been accumulated.
 
789
The @i{object} represented by the @i{token} is returned 
 
790
as the result of the read operation,
 
791
or an error of @i{type} @b{reader-error} is signaled if the @i{token} is not of valid syntax.
 
792
@end table
 
793
 
 
794
@c end of including concept-reader-algorithm
 
795
 
 
796
@node Interpretation of Tokens, Standard Macro Characters, Reader Algorithm, Syntax
 
797
@section Interpretation of Tokens
 
798
 
 
799
@c including concept-tokens
 
800
 
 
801
@menu
 
802
* Numbers as Tokens::           
 
803
* Constructing Numbers from Tokens::  
 
804
* The Consing Dot::             
 
805
* Symbols as Tokens::           
 
806
* Valid Patterns for Tokens::   
 
807
* Package System Consistency Rules::  
 
808
@end menu
 
809
 
 
810
@node Numbers as Tokens, Constructing Numbers from Tokens, Interpretation of Tokens, Interpretation of Tokens
 
811
@subsection Numbers as Tokens
 
812
 
 
813
When a @i{token} is read,
 
814
it is interpreted as a @i{number} or @i{symbol}.
 
815
The @i{token} is interpreted as a @i{number} if it satisfies
 
816
the syntax for numbers specified in Figure 2--9.
 
817
 
 
818
@format
 
819
@group
 
820
@noindent
 
821
@w{ @i{numeric-token} ::= !@i{integer} | !@i{ratio} | !@i{float}                                              }
 
822
@w{ @i{integer}       ::= @t{[}@i{sign}@t{]} @{@i{decimal-digit}@}^+ @i{decimal-point} | @t{[}@i{sign}@t{]} @{@i{digit}@}^+               }
 
823
@w{ @i{ratio}         ::= @t{[}@i{sign}@t{]} @{@i{digit}@}^+ @i{slash} @{@i{digit}@}^+                                        }
 
824
@w{ @i{float}         ::= @t{[}@i{sign}@t{]} @{@i{decimal-digit}@}* @i{decimal-point} @{@i{decimal-digit}@}^+ @t{[}!@i{exponent}@t{]}   }
 
825
@w{                   | @t{[}@i{sign}@t{]} @{@i{decimal-digit}@}^+ @t{[}@i{decimal-point} @{@i{decimal-digit}@}*@t{]} !@i{exponent} }
 
826
@w{ @i{exponent}      ::= @i{exponent-marker} @t{[}@i{sign}@t{]} @{@i{digit}@}^+                                        }
 
827
@w{ @i{sign}---a @i{sign}.}
 
828
@w{ @i{slash}---a @i{slash}}
 
829
@w{ @i{decimal-point}---a @i{dot}.}
 
830
@w{ @i{exponent-marker}---an @i{exponent marker}.}
 
831
@w{ @i{decimal-digit}---a @i{digit} in @i{radix} @t{10}.}
 
832
@w{ @i{digit}---a @i{digit} in the @i{current input radix}.}
 
833
@end group
 
834
@end format
 
835
 
 
836
@w{  Figure 2--9: Syntax for Numeric Tokens}
 
837
 
 
838
@menu
 
839
* Potential Numbers as Tokens::  
 
840
* Escape Characters and Potential Numbers::  
 
841
* Examples of Potential Numbers::  
 
842
@end menu
 
843
 
 
844
@node Potential Numbers as Tokens, Escape Characters and Potential Numbers, Numbers as Tokens, Numbers as Tokens
 
845
@subsubsection Potential Numbers as Tokens
 
846
 
 
847
To allow implementors and future @r{Common Lisp} standards
 
848
to extend the syntax of numbers, a
 
849
syntax for @i{potential numbers} is defined that is
 
850
more general than the syntax for numbers.
 
851
A @i{token} is a @i{potential number} if it satisfies all of the following
 
852
requirements:
 
853
 
 
854
@table @asis
 
855
 
 
856
@item 1.  
 
857
The @i{token} consists entirely of 
 
858
  @i{digits},
 
859
  @i{signs},
 
860
  @i{ratio markers},
 
861
  decimal points (@t{.}),
 
862
  extension characters (@t{^} or @t{_}),
 
863
  and number markers.
 
864
A number marker is a letter. 
 
865
Whether a letter may be treated as a number marker depends on context,
 
866
but no letter that is adjacent to another letter may ever be treated as a number marker.
 
867
@i{Exponent markers} are number markers.
 
868
 
 
869
@item 2.  
 
870
The @i{token} contains at least one digit.  Letters may be considered to be
 
871
digits, depending on the @i{current input base}, but only
 
872
in @i{tokens} containing no decimal points.
 
873
 
 
874
@item 3.  
 
875
The @i{token} begins with a @i{digit}, @i{sign}, decimal point, or extension character,
 
876
 
 
877
[Reviewer Note by Barmar: This section is unnecessary because the first bullet already 
 
878
                  omits discussion of a colon (@i{package marker}).]
 
879
but not a 
 
880
@i{package marker}.
 
881
The syntax involving a leading 
 
882
@i{package marker} followed by a @i{potential number} is
 
883
not well-defined. The consequences of the use 
 
884
of notation such as @t{:1}, @t{:1/2}, and @t{:2^3} in a
 
885
position where an expression appropriate for @b{read} 
 
886
is expected are unspecified.
 
887
 
 
888
@item 4.  
 
889
The @i{token} does not end with a sign.
 
890
@end table
 
891
 
 
892
If a @i{potential number} has number syntax, 
 
893
a @i{number} of the appropriate type is constructed and returned, 
 
894
if the @i{number} is representable in an implementation.
 
895
A @i{number} will not be representable in an implementation 
 
896
if it is outside the boundaries set by the @i{implementation-dependent} 
 
897
constants for @i{numbers}.
 
898
For example, specifying too large or too small an exponent for a @i{float}
 
899
may make the @i{number} impossible to represent in the implementation.
 
900
A @i{ratio} with denominator zero (such as @t{-35/000})
 
901
is not represented in any implementation.
 
902
When a @i{token} with the syntax of a number cannot be converted to an internal
 
903
@i{number}, an error of @i{type} @b{reader-error} is signaled.  An error
 
904
must not be signaled for specifying too many significant digits
 
905
for a @i{float}; a truncated or rounded value should be produced.
 
906
 
 
907
If there is an ambiguity as to whether
 
908
a letter should be treated as a digit or as a number marker,
 
909
the letter is treated as a digit.
 
910
 
 
911
@node Escape Characters and Potential Numbers, Examples of Potential Numbers, Potential Numbers as Tokens, Numbers as Tokens
 
912
@subsubsection Escape Characters and Potential Numbers
 
913
 
 
914
A @i{potential number} cannot contain any @i{escape}
 
915
@i{characters}.  An @i{escape} @i{character} robs the following
 
916
@i{character} of all syntactic qualities, forcing it to be strictly
 
917
@i{alphabetic}_2 and therefore unsuitable for use in a
 
918
@i{potential number}.  For example, all of the following
 
919
representations are interpreted as @i{symbols}, not @i{numbers}:
 
920
 
 
921
@example
 
922
 \256   25\64   1.0\E6   |100|   3\.14159   |3/4|   3\/4   5||
 
923
@end example
 
924
 
 
925
In each case, removing the @i{escape} @i{character} (or @i{characters}) 
 
926
would 
 
927
cause the token to be a @i{potential number}.
 
928
 
 
929
@node Examples of Potential Numbers,  , Escape Characters and Potential Numbers, Numbers as Tokens
 
930
@subsubsection Examples of Potential Numbers
 
931
 
 
932
As examples, the @i{tokens} in Figure 2--10 are @i{potential numbers},
 
933
but they are not actually numbers, and so are reserved @i{tokens};
 
934
a @i{conforming implementation} is permitted, but not required,
 
935
to define their meaning.
 
936
 
 
937
@format
 
938
@group
 
939
@noindent
 
940
@w{  @t{1b5000}                       @t{777777q}                @t{1.7J}  @t{-3/4+6.7J}  @t{12/25/83}  }
 
941
@w{  @t{27^19}                      @t{3^4/5}                @t{6//7}  @t{3.1.2.6}    @t{@t{^}-43@t{^}}   }
 
942
@w{  @t{3.141_592_653_589_793_238_4}  @t{-3.7+2.6i-6.17j+19.6k}  }
 
943
 
 
944
@noindent
 
945
@w{                     Figure 2--10: Examples of reserved tokens                   }
 
946
 
 
947
@end group
 
948
@end format
 
949
 
 
950
The @i{tokens} in Figure 2--11 are not @i{potential numbers}; 
 
951
they are always treated as @i{symbols}:
 
952
 
 
953
@format
 
954
@group
 
955
@noindent
 
956
@w{  @t{/}     @t{/5}     @t{+}  @t{1+}  @t{1-}     }
 
957
@w{  @t{foo+}  @t{ab.cd}  @t{_}  @t{@t{^}}   @t{@t{^}/-}  }
 
958
 
 
959
@noindent
 
960
@w{  Figure 2--11: Examples of symbols}
 
961
 
 
962
@end group
 
963
@end format
 
964
 
 
965
The @i{tokens} in Figure 2--12 are @i{potential numbers}
 
966
if the @i{current input base} is @t{16}, 
 
967
but they are always treated as @i{symbols} if the @i{current input base} is @t{10}. 
 
968
 
 
969
@format
 
970
@group
 
971
@noindent
 
972
@w{  @t{bad-face}  @t{25-dec-83}  @t{a/b}  @t{fad_cafe}  @t{f@t{^}} }
 
973
 
 
974
@noindent
 
975
@w{  Figure 2--12: Examples of symbols or potential numbers}
 
976
 
 
977
@end group
 
978
@end format
 
979
 
 
980
@node Constructing Numbers from Tokens, The Consing Dot, Numbers as Tokens, Interpretation of Tokens
 
981
@subsection Constructing Numbers from Tokens
 
982
 
 
983
A @i{real} is constructed directly from a corresponding numeric @i{token};
 
984
see @i{Figure~2--9}.
 
985
 
 
986
A @i{complex} is notated as a @t{#C} (or @t{#c}) followed by a @i{list}
 
987
of two @i{reals}; see @ref{Sharpsign C}.
 
988
 
 
989
The @i{reader macros} @t{#B}, @t{#O}, @t{#X}, and @t{#R} may also be useful
 
990
in controlling the input @i{radix} in which @i{rationals} are parsed;
 
991
 see @ref{Sharpsign B},
 
992
     @ref{Sharpsign O},
 
993
     @ref{Sharpsign X},
 
994
 and @ref{Sharpsign R}.
 
995
 
 
996
This section summarizes the full syntax for @i{numbers}.
 
997
 
 
998
@menu
 
999
* Syntax of a Rational::        
 
1000
* Syntax of an Integer::        
 
1001
* Syntax of a Ratio::           
 
1002
* Syntax of a Float::           
 
1003
* Syntax of a Complex::         
 
1004
@end menu
 
1005
 
 
1006
@node Syntax of a Rational, Syntax of an Integer, Constructing Numbers from Tokens, Constructing Numbers from Tokens
 
1007
@subsubsection Syntax of a Rational
 
1008
 
 
1009
@node Syntax of an Integer, Syntax of a Ratio, Syntax of a Rational, Constructing Numbers from Tokens
 
1010
@subsubsection Syntax of an Integer
 
1011
 
 
1012
@i{Integers} can be written as a sequence of @i{digits}, 
 
1013
optionally preceded by a @i{sign} and optionally followed by a decimal point;
 
1014
see @i{Figure~2--9}.
 
1015
When a decimal point is used,
 
1016
the @i{digits} are taken to be in @i{radix} @t{10};
 
1017
when no decimal point is used,
 
1018
the @i{digits} are taken to be in radix given by the @i{current input base}.
 
1019
 
 
1020
For information on how @i{integers} are printed, see @ref{Printing Integers}.
 
1021
 
 
1022
@node Syntax of a Ratio, Syntax of a Float, Syntax of an Integer, Constructing Numbers from Tokens
 
1023
@subsubsection Syntax of a Ratio
 
1024
 
 
1025
@i{Ratios} can be written as an optional @i{sign} followed by two
 
1026
non-empty sequences of @i{digits} separated by a @i{slash};
 
1027
see @i{Figure~2--9}.
 
1028
The second sequence may not consist
 
1029
entirely of zeros.
 
1030
Examples of @i{ratios} are in Figure 2--13.
 
1031
 
 
1032
@format
 
1033
@group
 
1034
@noindent
 
1035
@w{  @t{2/3}                 ;This is in canonical form                  }
 
1036
@w{  @t{4/6}                 ;A non-canonical form for 2/3               }
 
1037
@w{  @t{-17/23}              ;A ratio preceded by a sign                 }
 
1038
@w{  @t{-30517578125/32768}  ;This is (-5/2)^15                        }
 
1039
@w{  @t{10/5}                ;The canonical form for this is @t{2}           }
 
1040
@w{  @t{#o-101/75}           ;Octal notation for -65/61                  }
 
1041
@w{  @t{#3r120/21}           ;Ternary notation for 15/7                  }
 
1042
@w{  @t{#Xbc/ad}             ;Hexadecimal notation for 188/173           }
 
1043
@w{  @t{#xFADED/FACADE}      ;Hexadecimal notation for 1027565/16435934  }
 
1044
 
 
1045
@noindent
 
1046
@w{                  Figure 2--13: Examples of Ratios                }
 
1047
 
 
1048
@end group
 
1049
@end format
 
1050
 
 
1051
[Reviewer Note by Barmar: #o, #3r, #X, and #x mentioned above 
 
1052
                  are not in the syntax rules defined just above that.]
 
1053
 
 
1054
For information on how @i{ratios} are printed,
 
1055
see @ref{Printing Ratios}.
 
1056
 
 
1057
@node Syntax of a Float, Syntax of a Complex, Syntax of a Ratio, Constructing Numbers from Tokens
 
1058
@subsubsection Syntax of a Float
 
1059
 
 
1060
@i{Floats} can be written in either decimal fraction or computerized
 
1061
scientific notation: an optional sign, then a non-empty sequence of digits
 
1062
with an embedded decimal point,
 
1063
then an optional decimal exponent specification.
 
1064
If there is no exponent specifier, then
 
1065
the decimal point is required, and there must be digits
 
1066
after it.
 
1067
The exponent specifier consists of an @i{exponent marker},
 
1068
an optional sign, and a non-empty sequence of digits.
 
1069
If no exponent specifier is present, or if the @i{exponent marker} @t{e}
 
1070
(or @t{E}) is used, then
 
1071
the format specified
 
1072
by @b{*read-default-float-format*} is used.
 
1073
See @i{Figure~2--9}.
 
1074
 
 
1075
An implementation may provide one or more kinds of @i{float}
 
1076
that collectively make up the @i{type} @b{float}.
 
1077
The letters @t{s}, @t{f}, @t{d}, and @t{l} (or their
 
1078
respective uppercase equivalents) explicitly specify the
 
1079
use of the @i{types} @b{short-float}, @b{single-float}, 
 
1080
@b{double-float}, and @b{long-float}, respectively.
 
1081
 
 
1082
The internal format used for an external representation depends only
 
1083
on the @i{exponent marker}, and not on the number of decimal digits
 
1084
in the external representation.
 
1085
 
 
1086
Figure 2--14 contains examples of notations for @i{floats}: 
 
1087
 
 
1088
@format
 
1089
@group
 
1090
@noindent
 
1091
@w{  @t{0.0}       ;Floating-point zero in default format                          }
 
1092
@w{  @t{0E0}       ;As input, this is also floating-point zero in default format.  }
 
1093
@w{            ;As output, this would appear as @t{0.0}.                           }
 
1094
@w{  @t{0e0}       ;As input, this is also floating-point zero in default format.  }
 
1095
@w{            ;As output, this would appear as @t{0.0}.                           }
 
1096
@w{  @t{-.0}       ;As input, this might be a zero or a minus zero,                }
 
1097
@w{            ; depending on whether the implementation supports              }
 
1098
@w{            ; a distinct minus zero.                                        }
 
1099
@w{            ;As output, @t{0.0} is zero and @t{-0.0} is minus zero.                 }
 
1100
@w{  @t{0.}        ;On input, the integer zero---@i{not} a floating-point number!      }
 
1101
@w{            ;Whether this appears as @t{0} or @t{0.} on output depends              }
 
1102
@w{            ;on the @i{value} of @b{*print-radix*}.                                 }
 
1103
@w{  @t{0.0s0}     ;A floating-point zero in short format                          }
 
1104
@w{  @t{0s0}       ;As input, this is a floating-point zero in short format.       }
 
1105
@w{            ;As output, such a zero would appear as @t{0.0s0}                   }
 
1106
@w{            ; (or as @t{0.0} if @b{short-float} was the default format).            }
 
1107
@w{  @t{6.02E+23}  ;Avogadro's number, in default format                           }
 
1108
@w{  @t{602E+21}   ;Also Avogadro's number, in default format                      }
 
1109
 
 
1110
@noindent
 
1111
@w{               Figure 2--14: Examples of Floating-point numbers             }
 
1112
 
 
1113
@end group
 
1114
@end format
 
1115
 
 
1116
For information on how @i{floats} are printed,
 
1117
see @ref{Printing Floats}.
 
1118
 
 
1119
@node Syntax of a Complex,  , Syntax of a Float, Constructing Numbers from Tokens
 
1120
@subsubsection Syntax of a Complex
 
1121
 
 
1122
A @i{complex} has a Cartesian structure, 
 
1123
with a real part and an imaginary part each of which is a 
 
1124
 
 
1125
@i{real}.
 
1126
 
 
1127
The parts of a @i{complex} are not necessarily @i{floats} 
 
1128
but both parts must be of the same @i{type}: 
 
1129
 
 
1130
[Editorial Note by KMP: This is not the same as saying they must be the same type.
 
1131
                 Maybe we mean they are of the same `precision' or `format'?
 
1132
                 GLS had suggestions which are not yet merged.]
 
1133
either both are @i{rationals}, or both are of the same @i{float} @i{subtype}.
 
1134
When constructing a @i{complex}, if the specified parts are not the
 
1135
same @i{type}, the parts are converted to be the same @i{type}
 
1136
internally (@i{i.e.}, the @i{rational} part is converted to a @i{float}). 
 
1137
An @i{object} of type @t{(complex rational)} is converted internally
 
1138
and represented thereafter as a @i{rational} if its imaginary part is an 
 
1139
@i{integer} whose value is 0.
 
1140
 
 
1141
For further information, see @ref{Sharpsign C} and @ref{Printing Complexes}.
 
1142
 
 
1143
@node The Consing Dot, Symbols as Tokens, Constructing Numbers from Tokens, Interpretation of Tokens
 
1144
@subsection The Consing Dot
 
1145
 
 
1146
If a @i{token} consists solely of dots (with no escape characters),
 
1147
then an error of @i{type} @b{reader-error} is signaled,
 
1148
except in one circumstance:
 
1149
if the @i{token} is a single @i{dot}
 
1150
and appears in a situation where @i{dotted pair} notation permits a @i{dot},
 
1151
then it is accepted as part of such syntax and no error is signaled. 
 
1152
See @ref{Left-Parenthesis}.
 
1153
 
 
1154
@node Symbols as Tokens, Valid Patterns for Tokens, The Consing Dot, Interpretation of Tokens
 
1155
@subsection Symbols as Tokens
 
1156
 
 
1157
Any @i{token} that is not a @i{potential number},
 
1158
does not contain a @i{package marker},
 
1159
and does not consist entirely of dots
 
1160
will always be interpreted as a @i{symbol}.
 
1161
Any @i{token} that is a @i{potential number} but does not fit the       
 
1162
number syntax is a reserved @i{token} and
 
1163
has an @i{implementation-dependent} interpretation.
 
1164
In all other cases, the @i{token} is construed to be the name of a @i{symbol}.
 
1165
 
 
1166
Examples of the printed representation of @i{symbols} are in Figure 2--15. 
 
1167
For presentational simplicity,
 
1168
these examples assume that
 
1169
the @i{readtable case} of the @i{current readtable} is @t{:upcase}.
 
1170
 
 
1171
@format
 
1172
@group
 
1173
@noindent
 
1174
@w{  @t{FROBBOZ}         The @i{symbol} whose @i{name} is @t{FROBBOZ}.                }
 
1175
@w{  @t{frobboz}         Another way to notate the same @i{symbol}.           }
 
1176
@w{  @t{fRObBoz}         Yet another way to notate it.                    }
 
1177
@w{  @t{unwind-protect}  A @i{symbol} with a hyphen in its @i{name}.              }
 
1178
@w{  @t{+$}             The @i{symbol} named @t{+$}.                            }
 
1179
@w{  @t{1+}              The @i{symbol} named @t{1+}.                             }
 
1180
@w{  @t{+1}              This is the @i{integer} @t{1}, not a @i{symbol}.             }
 
1181
@w{  @t{pascal_style}    This @i{symbol} has an underscore in its @i{name}.       }
 
1182
@w{  @t{file.rel.43}     This @i{symbol} has periods in its @i{name}.             }
 
1183
@w{  @t{\(}              The @i{symbol} whose @i{name} is @t{(}.                      }
 
1184
@w{  @t{\+1}             The @i{symbol} whose @i{name} is @t{+1}.                     }
 
1185
@w{  @t{+\1}             Also the @i{symbol} whose @i{name} is @t{+1}.                }
 
1186
@w{  @t{\frobboz}        The @i{symbol} whose @i{name} is @t{fROBBOZ}.                }
 
1187
@w{  @t{3.14159265\s0}   The @i{symbol} whose @i{name} is @t{3.14159265s0}.           }
 
1188
@w{  @t{3.14159265\S0}   A different @i{symbol}, whose @i{name} is @t{3.14159265S0}.  }
 
1189
@w{  @t{3.14159265s0}    A possible @i{short float} approximation to \pi.     }
 
1190
 
 
1191
@noindent
 
1192
@w{  Figure 2--15: Examples of the printed representation of symbols (Part 1 of 2)}
 
1193
 
 
1194
@end group
 
1195
@end format
 
1196
 
 
1197
@format
 
1198
@group
 
1199
@noindent
 
1200
@w{  @t{APL\\360}               The @i{symbol} whose @i{name} is @t{APL\360}.       }
 
1201
@w{  @t{apl\\360}               Also the @i{symbol} whose @i{name} is @t{APL\360}.  }
 
1202
@w{  @t{\(b@t{^}2\)\ -\ 4*a@t{*c}}    The @i{name} is @t{(B@t{^}2) - 4*A*C}.            }
 
1203
@w{                         Parentheses and two spaces in it.       }
 
1204
@w{  @t{\(\b@t{^}2\)\ -\4*\a*\c}  The @i{name} is @t{(b@t{^}2) - 4*a*c}.            }
 
1205
@w{                         Letters explicitly lowercase.           }
 
1206
@w{  @t{|"|}                    The same as writing @t{\"}.                 }
 
1207
@w{  @t{|(b@t{^}2) - 4*a*c|}      The @i{name} is @t{(b@t{^}2) - 4*a*c}.            }
 
1208
@w{  @t{|frobboz|}              The @i{name} is @t{frobboz}, not @t{FROBBOZ}.       }
 
1209
@w{  @t{|APL\360|}              The @i{name} is @t{APL360}.                     }
 
1210
@w{  @t{|APL\\360|}             The @i{name} is @t{APL\360}.                    }
 
1211
@w{  @t{|apl\\360|}             The @i{name} is @t{apl\360}.                    }
 
1212
@w{  @t{|\|\||}                 Same as @t{\|\|} ---the @i{name} is @t{||}.          }
 
1213
@w{  @t{|(B@t{^}2) - 4*A*C|}      The @i{name} is @t{(B@t{^}2) - 4*A*C}.            }
 
1214
@w{                         Parentheses and two spaces in it.       }
 
1215
@w{  @t{|(b@t{^}2) - 4*a*c|}      The @i{name} is @t{(b@t{^}2) - 4*a*c}.            }
 
1216
 
 
1217
@noindent
 
1218
@w{  Figure 2--16: Examples of the printed representation of symbols (Part 2 of 2)}
 
1219
 
 
1220
@end group
 
1221
@end format
 
1222
 
 
1223
In the process of parsing a @i{symbol},
 
1224
it is @i{implementation-dependent} which
 
1225
@i{implementation-defined} @i{attributes} are removed
 
1226
from the @i{characters} forming a @i{token} that represents a @i{symbol}.
 
1227
 
 
1228
When parsing the syntax for a @i{symbol},
 
1229
the @i{Lisp reader} looks up the @i{name} of that @i{symbol} 
 
1230
in the @i{current package}.
 
1231
This lookup may involve looking in other 
 
1232
@i{packages} whose @i{external symbols}
 
1233
are inherited by the @i{current package}.  If the name is found,
 
1234
the corresponding @i{symbol} is returned.  If the name is not found
 
1235
(that is, there is no @i{symbol} 
 
1236
of that name @i{accessible} in the @i{current package}),
 
1237
a new @i{symbol} is created and is placed in the @i{current package}
 
1238
as an @i{internal symbol}.  The @i{current package} becomes the owner
 
1239
(@i{home package}) of the @i{symbol}, 
 
1240
and the @i{symbol} becomes interned in the @i{current package}.
 
1241
If the name is later read again while this same @i{package} is
 
1242
current, the same @i{symbol} will be found and returned.
 
1243
 
 
1244
@node Valid Patterns for Tokens, Package System Consistency Rules, Symbols as Tokens, Interpretation of Tokens
 
1245
@subsection Valid Patterns for Tokens
 
1246
 
 
1247
The valid patterns for @i{tokens} are summarized in Figure 2--17. 
 
1248
 
 
1249
@format
 
1250
@group
 
1251
@noindent
 
1252
@w{  @t{@i{nnnnn}}              a @i{number}                                           }
 
1253
@w{  @t{@i{xxxxx}}              a @i{symbol} in the @i{current package}                    }
 
1254
@w{  @t{:@i{xxxxx}}             a @i{symbol} in the the @t{KEYWORD} @i{package}                }
 
1255
@w{  @t{@i{ppppp}:@i{xxxxx}}        an @i{external symbol} in the @i{ppppp} @i{package}            }
 
1256
@w{  @t{@i{ppppp}::@i{xxxxx}}       a (possibly internal) @i{symbol} in the @i{ppppp} @i{package}  }
 
1257
@w{  @t{:@i{nnnnn}}             undefined                                          }
 
1258
@w{  @t{@i{ppppp}:@i{nnnnn}}        undefined                                          }
 
1259
@w{  @t{@i{ppppp}::@i{nnnnn}}       undefined                                          }
 
1260
@w{  @t{::@i{aaaaa}}            undefined                                          }
 
1261
@w{  @t{@i{aaaaa}:}             undefined                                          }
 
1262
@w{  @t{@i{aaaaa}:@i{aaaaa}:@i{aaaaa}}  undefined                                          }
 
1263
 
 
1264
@noindent
 
1265
@w{                 Figure 2--17: Valid patterns for tokens                }
 
1266
 
 
1267
@end group
 
1268
@end format
 
1269
 
 
1270
Note that @i{nnnnn} has number syntax,
 
1271
          neither @i{xxxxx} nor @i{ppppp} has number syntax,
 
1272
      and @i{aaaaa} has any syntax.
 
1273
 
 
1274
A summary of rules concerning @i{package markers} follows.
 
1275
In each case, examples are offered to illustrate the case;
 
1276
for presentational simplicity, the examples assume that
 
1277
the @i{readtable case} of the @i{current readtable} is @t{:upcase}.
 
1278
 
 
1279
@table @asis
 
1280
 
 
1281
@item 1.  
 
1282
If there is a single @i{package marker}, and it occurs at the beginning of the
 
1283
@i{token}, then the @i{token} is interpreted as a @i{symbol} in the @t{KEYWORD} @i{package}.
 
1284
It also sets the @b{symbol-value} of the newly-created @i{symbol} to that
 
1285
same @i{symbol} so that the @i{symbol} will self-evaluate.
 
1286
 
 
1287
For example, 
 
1288
@t{:bar}, when read, interns @t{BAR} as an @i{external symbol} in the @t{KEYWORD} @i{package}.
 
1289
 
 
1290
@item 2.  
 
1291
If there is a single @i{package marker} not at the beginning or end of the
 
1292
@i{token}, then it divides the @i{token} into two parts.  The first part
 
1293
specifies a @i{package}; 
 
1294
the second part is the name of an @i{external symbol}
 
1295
available in that package.  
 
1296
 
 
1297
For example, 
 
1298
@t{foo:bar}, when read, looks up @t{BAR} among the @i{external symbols} of
 
1299
the @i{package} named @t{FOO}.
 
1300
 
 
1301
@item 3.  
 
1302
If there are two adjacent @i{package markers} not at the beginning or end of the
 
1303
@i{token}, then they divide the @i{token} into two parts.  The first part
 
1304
specifies a @i{package};
 
1305
the second part is the name of a @i{symbol} within
 
1306
that @i{package} (possibly an @i{internal symbol}).
 
1307
 
 
1308
For example, 
 
1309
@t{foo::bar}, when read, interns @t{BAR} in the @i{package} named @t{FOO}.
 
1310
 
 
1311
@item 4.  
 
1312
If the @i{token} contains no @i{package markers}, 
 
1313
and does not have @i{potential number} syntax,
 
1314
then the entire @i{token} is the name of the @i{symbol}.
 
1315
The @i{symbol} is looked up in the @i{current package}.
 
1316
 
 
1317
For example, 
 
1318
@t{bar}, when read, interns @t{BAR} in the @i{current package}.
 
1319
 
 
1320
@item 5.  
 
1321
The consequences are unspecified if any other pattern of @i{package markers}
 
1322
in a @i{token} is used.
 
1323
All other uses of @i{package markers} within names of @i{symbols} 
 
1324
are not defined by this standard 
 
1325
but are reserved for @i{implementation-dependent} use.
 
1326
@end table
 
1327
 
 
1328
For example,
 
1329
assuming the @i{readtable case} of the @i{current readtable} is @t{:upcase},
 
1330
@t{editor:buffer} refers to the @i{external symbol} 
 
1331
named @t{BUFFER} present in the @i{package} named @t{editor},
 
1332
regardless of whether there is a @i{symbol} named @t{BUFFER} in
 
1333
the @i{current package}.  If there is no @i{package} named
 
1334
@t{editor}, or if no @i{symbol} named @t{BUFFER}
 
1335
is present in @t{editor}, or if @t{BUFFER} is not exported by
 
1336
@t{editor}, the reader signals
 
1337
a correctable error.
 
1338
If @t{editor::buffer} is seen, the effect is exactly the same as
 
1339
reading @t{buffer} with the @t{EDITOR} @i{package} being the @i{current package}.
 
1340
 
 
1341
@node Package System Consistency Rules,  , Valid Patterns for Tokens, Interpretation of Tokens
 
1342
@subsection Package System Consistency Rules
 
1343
 
 
1344
The following rules apply to the package system as long as 
 
1345
the @i{value} of @b{*package*} is not changed:
 
1346
 
 
1347
@table @asis
 
1348
 
 
1349
@item @b{Read-read consistency}  
 
1350
Reading the same @i{symbol} @i{name}
 
1351
always results in the @i{same} @i{symbol}.
 
1352
 
 
1353
@item @b{Print-read consistency}  
 
1354
An @i{interned symbol} always prints as a sequence of characters that, 
 
1355
when read back in, yields the @i{same} @i{symbol}.
 
1356
 
 
1357
For information about how the @i{Lisp printer} treats @i{symbols},
 
1358
see @ref{Printing Symbols}.
 
1359
 
 
1360
@item @b{Print-print consistency}  
 
1361
If two interned @i{symbols} are not the @i{same},
 
1362
then their printed representations will be different sequences of characters.
 
1363
@end table
 
1364
 
 
1365
These rules are true regardless of any implicit interning.
 
1366
As long as the @i{current package} is not changed,
 
1367
results are reproducible regardless of the order of @i{loading} files 
 
1368
or the exact history of what @i{symbols} were typed in when.  
 
1369
If the @i{value} of @b{*package*} is changed and then changed back to the previous value,
 
1370
consistency is maintained.
 
1371
The rules can be violated by
 
1372
    changing the @i{value} of @b{*package*},
 
1373
    forcing a change to @i{symbols} 
 
1374
                  or to @i{packages} 
 
1375
                  or to both
 
1376
    by continuing from an error,
 
1377
or calling one of the following @i{functions}:
 
1378
    @b{unintern},
 
1379
    @b{unexport},
 
1380
    @b{shadow},
 
1381
    @b{shadowing-import},
 
1382
 or @b{unuse-package}.
 
1383
 
 
1384
An inconsistency only applies if one of the restrictions is violated
 
1385
between two of the named @i{symbols}.
 
1386
@b{shadow}, @b{unexport}, @b{unintern},
 
1387
and @b{shadowing-import} can only affect the consistency of
 
1388
@i{symbols} with the same @i{names} (under @b{string=})
 
1389
as the ones supplied as arguments.
 
1390
 
 
1391
@c end of including concept-tokens
 
1392
 
 
1393
@node Standard Macro Characters,  , Interpretation of Tokens, Syntax
 
1394
@section Standard Macro Characters
 
1395
 
 
1396
@c including concept-macro-chars
 
1397
 
 
1398
If the reader encounters a @i{macro character},
 
1399
then its associated @i{reader macro function} 
 
1400
is invoked and may produce an @i{object} to be returned.
 
1401
This @i{function} may read the @i{characters} 
 
1402
following the @i{macro character} in the @i{stream} 
 
1403
in any syntax and return the @i{object} represented by that syntax.
 
1404
 
 
1405
Any @i{character} can be made to be a @i{macro character}.
 
1406
The @i{macro characters} defined initially in a @i{conforming implementation}
 
1407
include
 
1408
the following:
 
1409
 
 
1410
@menu
 
1411
* Left-Parenthesis::            
 
1412
* Right-Parenthesis::           
 
1413
* Single-Quote::                
 
1414
* Semicolon::                   
 
1415
* Double-Quote::                
 
1416
* Backquote::                   
 
1417
* Comma::                       
 
1418
* Sharpsign::                   
 
1419
* Re-Reading Abbreviated Expressions::  
 
1420
@end menu
 
1421
 
 
1422
@node Left-Parenthesis, Right-Parenthesis, Standard Macro Characters, Standard Macro Characters
 
1423
@subsection Left-Parenthesis
 
1424
 
 
1425
The @i{left-parenthesis} initiates reading of a @i{list}.
 
1426
@b{read} is called recursively to read successive @i{objects}
 
1427
until a right parenthesis is found in the input @i{stream}.
 
1428
A @i{list} of the @i{objects} read is returned.  Thus
 
1429
 
 
1430
@example
 
1431
 (a b c)
 
1432
@end example
 
1433
 
 
1434
is read as a @i{list} of three @i{objects}
 
1435
(the @i{symbols} @t{a}, @t{b}, and @t{c}).
 
1436
The right parenthesis need not immediately follow the printed representation of
 
1437
the last @i{object}; @i{whitespace}_2                              
 
1438
characters and comments may precede it.
 
1439
 
 
1440
If no @i{objects} precede the right parenthesis, 
 
1441
it reads as a @i{list} of zero @i{objects} 
 
1442
(the @i{empty list}).
 
1443
 
 
1444
If a @i{token} that is just a dot
 
1445
not immediately preceded by an escape character
 
1446
is read after some @i{object}
 
1447
then exactly one more @i{object} must follow the dot,
 
1448
possibly preceded or followed by @i{whitespace}_2 or a comment,
 
1449
followed by the right parenthesis:
 
1450
 
 
1451
@example
 
1452
 (a b c . d)
 
1453
@end example
 
1454
 
 
1455
This means that the @i{cdr} of the last @i{cons} in the 
 
1456
@i{list} is not @b{nil},
 
1457
but rather the @i{object} whose representation followed the dot.
 
1458
The above example might have been the result of evaluating
 
1459
 
 
1460
@example
 
1461
 (cons 'a (cons 'b (cons 'c 'd)))
 
1462
@end example
 
1463
 
 
1464
Similarly,
 
1465
 
 
1466
@example
 
1467
 (cons 'this-one 'that-one) @result{}  (this-one . that-one)
 
1468
@end example
 
1469
 
 
1470
It is permissible for the @i{object} 
 
1471
following the dot to be a @i{list}:
 
1472
 
 
1473
@example
 
1474
 (a b c d . (e f . (g))) @equiv{} (a b c d e f g)
 
1475
@end example
 
1476
 
 
1477
For information on how the @i{Lisp printer} prints @i{lists} and @i{conses},
 
1478
see @ref{Printing Lists and Conses}.
 
1479
 
 
1480
@node Right-Parenthesis, Single-Quote, Left-Parenthesis, Standard Macro Characters
 
1481
@subsection Right-Parenthesis
 
1482
 
 
1483
The @i{right-parenthesis} is invalid 
 
1484
except when used in conjunction with the left parenthesis character.
 
1485
For more information, see @ref{Reader Algorithm}.
 
1486
 
 
1487
@node Single-Quote, Semicolon, Right-Parenthesis, Standard Macro Characters
 
1488
@subsection Single-Quote
 
1489
 
 
1490
@b{Syntax:}  @t{'<<@i{exp}>>}
 
1491
 
 
1492
A @i{single-quote} introduces an @i{expression} to be ``quoted.''
 
1493
@i{Single-quote} followed by an @i{expression} @i{exp} 
 
1494
is treated by the @i{Lisp reader} as an abbreviation for
 
1495
and is parsed identically to the @i{expression} @t{(quote @i{exp})}.
 
1496
See the @i{special operator} @b{quote}.
 
1497
 
 
1498
@menu
 
1499
* Examples of Single-Quote::    
 
1500
@end menu
 
1501
 
 
1502
@node Examples of Single-Quote,  , Single-Quote, Single-Quote
 
1503
@subsubsection Examples of Single-Quote
 
1504
 
 
1505
@example
 
1506
 'foo @result{}  FOO
 
1507
 ''foo @result{}  (QUOTE FOO)
 
1508
 (car ''foo) @result{}  QUOTE
 
1509
@end example
 
1510
 
 
1511
@node Semicolon, Double-Quote, Single-Quote, Standard Macro Characters
 
1512
@subsection Semicolon
 
1513
 
 
1514
@b{Syntax:} @t{;<<@i{text}>>}
 
1515
 
 
1516
A @i{semicolon} introduces @i{characters} that are to be ignored,
 
1517
such as comments.  The @i{semicolon} and all @i{characters} up to
 
1518
and including the next @i{newline} or end of file are ignored.
 
1519
 
 
1520
@menu
 
1521
* Examples of Semicolon::       
 
1522
* Notes about Style for Semicolon::  
 
1523
* Use of Single Semicolon::     
 
1524
* Use of Double Semicolon::     
 
1525
* Use of Triple Semicolon::     
 
1526
* Use of Quadruple Semicolon::  
 
1527
* Examples of Style for Semicolon::  
 
1528
@end menu
 
1529
 
 
1530
@node Examples of Semicolon, Notes about Style for Semicolon, Semicolon, Semicolon
 
1531
@subsubsection Examples of Semicolon
 
1532
 
 
1533
@example
 
1534
 (+ 3 ; three
 
1535
    4)
 
1536
@result{}  7    
 
1537
@end example
 
1538
 
 
1539
@node Notes about Style for Semicolon, Use of Single Semicolon, Examples of Semicolon, Semicolon
 
1540
@subsubsection Notes about Style for Semicolon
 
1541
 
 
1542
Some text editors make assumptions about desired indentation based on
 
1543
the number of @i{semicolons} that begin a comment.  The following style 
 
1544
conventions are common, although not by any means universal.  
 
1545
 
 
1546
@node Use of Single Semicolon, Use of Double Semicolon, Notes about Style for Semicolon, Semicolon
 
1547
@subsubsection Use of Single Semicolon
 
1548
 
 
1549
Comments that begin with a single @i{semicolon} are all aligned to 
 
1550
the same column at the right (sometimes called the ``comment column'').
 
1551
The text of such a comment generally applies only to the line on which it appears.
 
1552
Occasionally two or three contain a single sentence together;
 
1553
this is sometimes indicated by indenting all but the first with an additional
 
1554
space (after the @i{semicolon}).
 
1555
 
 
1556
@node Use of Double Semicolon, Use of Triple Semicolon, Use of Single Semicolon, Semicolon
 
1557
@subsubsection Use of Double Semicolon
 
1558
 
 
1559
Comments that begin with a double @i{semicolon} are all aligned to
 
1560
the same level of indentation as a @i{form} would be at that same
 
1561
position in the @i{code}.
 
1562
The text of such a comment usually describes
 
1563
    the state of the @i{program} at the point where the comment occurs,
 
1564
    the @i{code} which follows the comment,
 
1565
 or both.
 
1566
 
 
1567
@node Use of Triple Semicolon, Use of Quadruple Semicolon, Use of Double Semicolon, Semicolon
 
1568
@subsubsection Use of Triple Semicolon
 
1569
 
 
1570
Comments that begin with a triple @i{semicolon} are all aligned to
 
1571
the left margin.  Usually they are used prior to a definition or set
 
1572
of definitions, rather than within a definition.
 
1573
 
 
1574
@node Use of Quadruple Semicolon, Examples of Style for Semicolon, Use of Triple Semicolon, Semicolon
 
1575
@subsubsection Use of Quadruple Semicolon
 
1576
 
 
1577
Comments that begin with a quadruple @i{semicolon} are all aligned to
 
1578
the left margin, and generally contain only a short piece of text that
 
1579
serve as a title for the code which follows, and might be used in the
 
1580
header or footer of a program that prepares code for presentation as 
 
1581
a hardcopy document.
 
1582
 
 
1583
@node Examples of Style for Semicolon,  , Use of Quadruple Semicolon, Semicolon
 
1584
@subsubsection Examples of Style for Semicolon
 
1585
 
 
1586
@example
 
1587
;;;; Math Utilities
 
1588
 
 
1589
;;; FIB computes the the Fibonacci function in the traditional
 
1590
;;; recursive way.
 
1591
 
 
1592
(defun fib (n)
 
1593
  (check-type n integer)
 
1594
  ;; At this point we're sure we have an integer argument.
 
1595
  ;; Now we can get down to some serious computation.
 
1596
  (cond ((< n 0)
 
1597
         ;; Hey, this is just supposed to be a simple example.
 
1598
         ;; Did you really expect me to handle the general case?
 
1599
         (error "FIB got ~D as an argument." n))
 
1600
        ((< n 2) n)             ;fib[0]=0 and fib[1]=1
 
1601
        ;; The cheap cases didn't work.
 
1602
        ;; Nothing more to do but recurse.
 
1603
        (t (+ (fib (- n 1))     ;The traditional formula
 
1604
              (fib (- n 2)))))) ; is fib[n-1]+fib[n-2].
 
1605
@end example
 
1606
 
 
1607
@node Double-Quote, Backquote, Semicolon, Standard Macro Characters
 
1608
@subsection Double-Quote
 
1609
 
 
1610
@b{Syntax:} @t{"<<@i{text}>>"}
 
1611
 
 
1612
The @i{double-quote} is used to begin and end a @i{string}.
 
1613
When a @i{double-quote} is encountered,
 
1614
@i{characters} are read from the @i{input} @i{stream} 
 
1615
and accumulated until another @i{double-quote} is encountered.
 
1616
If a @i{single escape} @i{character} is seen,
 
1617
the @i{single escape} @i{character} is discarded,
 
1618
the next @i{character} is accumulated, and accumulation continues.
 
1619
The accumulated @i{characters} 
 
1620
up to but not including the matching @i{double-quote} 
 
1621
are made into a @i{simple string} and returned.
 
1622
 
 
1623
It is @i{implementation-dependent}
 
1624
which @i{attributes} of the accumulated characters are removed in this process.
 
1625
 
 
1626
Examples of the use of the @i{double-quote} character are in Figure 2--18. 
 
1627
 
 
1628
@format
 
1629
@group
 
1630
@noindent
 
1631
@w{  @t{"Foo"}                      ;A string with three characters in it  }
 
1632
@w{  @t{""}                         ;An empty string                       }
 
1633
@w{  @t{"\"APL\\360?\" he cried."}  ;A string with twenty characters       }
 
1634
@w{  @t{"|x| = |-x|"}               ;A ten-character string                }
 
1635
 
 
1636
@noindent
 
1637
@w{          Figure 2--18: Examples of the use of double-quote         }
 
1638
 
 
1639
@end group
 
1640
@end format
 
1641
 
 
1642
Note that to place a single escape character or a @i{double-quote} into a string,
 
1643
such a character must be preceded by a single escape character.
 
1644
Note, too, that a multiple escape character need not be quoted by a 
 
1645
single escape character within a string.
 
1646
 
 
1647
For information on how the @i{Lisp printer} prints @i{strings},
 
1648
see @ref{Printing Strings}.
 
1649
 
 
1650
@node Backquote, Comma, Double-Quote, Standard Macro Characters
 
1651
@subsection Backquote
 
1652
 
 
1653
The @i{backquote} introduces a template of a data structure to be built.  
 
1654
For example, writing
 
1655
 
 
1656
@example
 
1657
 `(cond ((numberp ,x) ,@@y) (t (print ,x) ,@@y))
 
1658
@end example
 
1659
 
 
1660
is roughly equivalent to writing
 
1661
 
 
1662
@example
 
1663
 (list 'cond 
 
1664
       (cons (list 'numberp x) y) 
 
1665
       (list* 't (list 'print x) y))
 
1666
@end example
 
1667
 
 
1668
Where a comma
 
1669
occurs in the template, 
 
1670
the @i{expression}
 
1671
following the comma is to be evaluated to produce an @i{object} to
 
1672
be inserted at that point.  Assume @t{b} has the value 3, for example, then
 
1673
evaluating the @i{form} denoted by @t{`(a b ,b ,(+ b 1) b)} produces
 
1674
the result @t{(a b 3 4 b)}.
 
1675
 
 
1676
If a comma is immediately followed by an @i{at-sign}, 
 
1677
then the @i{form} following the @i{at-sign}
 
1678
is evaluated to produce a @i{list} of @i{objects}.
 
1679
These @i{objects} are then ``spliced'' into place in the template.  For
 
1680
example, if @t{x} has the value @t{(a b c)}, then
 
1681
 
 
1682
@example
 
1683
 `(x ,x ,@@x foo ,(cadr x) bar ,(cdr x) baz ,@@(cdr x))
 
1684
@result{}  (x (a b c) a b c foo b bar (b c) baz b c)
 
1685
@end example
 
1686
 
 
1687
The backquote syntax can be summarized formally as follows.
 
1688
 
 
1689
@table @asis
 
1690
 
 
1691
@item @t{*}  
 
1692
@t{`@i{basic}} is the same as @t{'@i{basic}},
 
1693
that is, @t{(quote @i{basic})}, for any @i{expression} 
 
1694
@i{basic} that is not a @i{list} or a general @i{vector}.
 
1695
 
 
1696
@item @t{*}  
 
1697
@t{`,@i{form}} is the same as @i{form}, for any @i{form}, provided
 
1698
that the representation of @i{form} does not begin with @i{at-sign}
 
1699
or @i{dot}.  (A similar caveat holds for all occurrences of a form after a @i{comma}.)
 
1700
 
 
1701
@item @t{*}  
 
1702
@t{`,@@@i{form}} has undefined consequences.
 
1703
 
 
1704
@item @t{*}  
 
1705
@t{`(x1 x2 x3 ... xn . atom)}
 
1706
may be interpreted to mean
 
1707
 
 
1708
@example
 
1709
 (append [ x1 ] [ x2 ] [ x3 ] ... [ xn ] (quote atom))
 
1710
@end example
 
1711
 
 
1712
where the brackets are used to indicate
 
1713
a transformation of an @i{xj} as follows:
 
1714
 
 
1715
@table @asis
 
1716
 
 
1717
@item --  
 
1718
@t{[@i{form}]} is interpreted as @t{(list `@i{form})}, 
 
1719
which contains a backquoted form that must then be further interpreted.
 
1720
 
 
1721
@item --  
 
1722
@t{[,@i{form}]} is interpreted as @t{(list @i{form})}.
 
1723
 
 
1724
@item --  
 
1725
@t{[,@@@i{form}]} is interpreted as @i{form}.
 
1726
@end table
 
1727
 
 
1728
@item @t{*}  
 
1729
@t{`(x1 x2 x3 ... xn)} may be interpreted to mean
 
1730
the same as the backquoted form
 
1731
@t{`(x1 x2 x3 ... xn . @b{nil})},
 
1732
thereby reducing it to the previous case.
 
1733
 
 
1734
@item @t{*}  
 
1735
@t{`(x1 x2 x3 ... xn . ,form)} may be interpreted to mean
 
1736
 
 
1737
@example
 
1738
 (append [ x1 ] [ x2 ] [ x3 ] ... [ xn ] form)
 
1739
@end example
 
1740
 
 
1741
where the brackets indicate a transformation of an @t{xj} as described above.
 
1742
 
 
1743
@item @t{*}  
 
1744
@t{`(x1 x2 x3 ... xn . ,@@form)} has undefined consequences.
 
1745
 
 
1746
@item @t{*}  
 
1747
@t{`#(x1 x2 x3 ... xn)} may be interpreted to mean
 
1748
@t{(apply #'vector `(x1 x2 x3 ... xn))}.
 
1749
@end table
 
1750
 
 
1751
Anywhere ``@t{,@@}'' may be used, the syntax ``@t{,.}'' may be used instead
 
1752
to indicate that it is permissible to operate @i{destructively} on 
 
1753
the @i{list structure}  produced by the form following the ``@t{,.}'' 
 
1754
(in effect, to use @b{nconc} instead of @b{append}).
 
1755
 
 
1756
If the backquote syntax is nested, the innermost backquoted form
 
1757
should be expanded first.  This means that if several commas occur
 
1758
in a row, the leftmost one belongs to the innermost @i{backquote}.
 
1759
 
 
1760
An @i{implementation} is free to interpret a backquoted @i{form} F_1
 
1761
as any @i{form} F_2 that, when evaluated, will produce a result that is
 
1762
the @i{same} under @b{equal} as the result implied by the above definition, 
 
1763
provided that the side-effect behavior of the substitute @i{form} F_2 
 
1764
is also consistent with the description given above.
 
1765
The constructed
 
1766
copy of the template might or might not share @i{list} structure with the
 
1767
template itself.  As an example, the above definition implies that
 
1768
 
 
1769
@example
 
1770
 `((,a b) ,c ,@@d)
 
1771
@end example
 
1772
 
 
1773
will be interpreted as if it were
 
1774
 
 
1775
@example
 
1776
 (append (list (append (list a) (list 'b) '@b{nil})) (list c) d '@b{nil})
 
1777
@end example
 
1778
 
 
1779
but it could also be legitimately interpreted to mean any of the following:
 
1780
 
 
1781
@example
 
1782
 (append (list (append (list a) (list 'b))) (list c) d)
 
1783
 (append (list (append (list a) '(b))) (list c) d)
 
1784
 (list* (cons a '(b)) c d)
 
1785
 (list* (cons a (list 'b)) c d)
 
1786
 (append (list (cons a '(b))) (list c) d)
 
1787
 (list* (cons a '(b)) c (copy-list d))
 
1788
@end example
 
1789
 
 
1790
@menu
 
1791
* Notes about Backquote::       
 
1792
@end menu
 
1793
 
 
1794
@node Notes about Backquote,  , Backquote, Backquote
 
1795
@subsubsection Notes about Backquote
 
1796
 
 
1797
Since the exact manner in which the @i{Lisp reader} will parse
 
1798
an @i{expression} involving the @i{backquote} @i{reader macro} 
 
1799
is not specified, an @i{implementation} is free to choose any
 
1800
representation that preserves the semantics described.
 
1801
 
 
1802
Often an @i{implementation} will choose a representation that facilitates
 
1803
pretty printing of the expression, so that @t{(pprint `(a ,b))} will display
 
1804
@t{`(a ,b)} and not, for example, @t{(list 'a b)}.  However, this is not a
 
1805
requirement.
 
1806
 
 
1807
Implementors who have no particular reason to make one choice or another
 
1808
might wish to refer to @b{IEEE Standard for the Scheme Programming Language}, which identifies a popular choice of
 
1809
representation for such expressions that might provide useful to be useful
 
1810
compatibility for some user communities.  There is no requirement, however,
 
1811
that any @i{conforming implementation} use this particular representation.
 
1812
This information is provided merely for cross-reference purposes.
 
1813
 
 
1814
@node Comma, Sharpsign, Backquote, Standard Macro Characters
 
1815
@subsection Comma
 
1816
 
 
1817
The @i{comma} is part of the backquote syntax; see @ref{Backquote}.
 
1818
@i{Comma} is invalid if used other than inside the body of a 
 
1819
backquote @i{expression} as described above.
 
1820
 
 
1821
@node Sharpsign, Re-Reading Abbreviated Expressions, Comma, Standard Macro Characters
 
1822
@subsection Sharpsign
 
1823
 
 
1824
@i{Sharpsign} is a @i{non-terminating} @i{dispatching macro character}.
 
1825
It reads an optional 
 
1826
sequence of digits and then one more character,
 
1827
and uses that character to select a @i{function} to run as a
 
1828
@i{reader macro function}.
 
1829
 
 
1830
The @i{standard syntax} includes constructs introduced by the @t{#} character.
 
1831
The syntax of these constructs is as follows:
 
1832
a character that identifies the type of construct is 
 
1833
followed by arguments in some form.
 
1834
If the character is a letter, its @i{case} is not important;
 
1835
@t{#O} and @t{#o} are considered to be equivalent, for example.
 
1836
 
 
1837
Certain @t{#} constructs allow an unsigned decimal number to appear
 
1838
between the @t{#} and the character.
 
1839
 
 
1840
The @i{reader macros} associated with the @i{dispatching macro character} @t{#}
 
1841
are described later in this section and summarized in Figure 2--19.
 
1842
 
 
1843
 
 
1844
 
 
1845
@format
 
1846
@group
 
1847
@noindent
 
1848
@w{  dispatch char  purpose                  dispatch char  purpose                }
 
1849
@w{  Backspace      signals error            @t{@{}              undefined*             }
 
1850
@w{  Tab            signals error            @t{@}}              undefined*             }
 
1851
@w{  Newline        signals error            +              read-time conditional  }
 
1852
@w{  Linefeed       signals error            -              read-time conditional  }
 
1853
@w{  Page           signals error            .              read-time evaluation   }
 
1854
@w{  Return         signals error            /              undefined              }
 
1855
@w{  Space          signals error            A, a           array                  }
 
1856
@w{  !              undefined*               B, b           binary rational        }
 
1857
@w{  @t{"}              undefined                C, c           complex number         }
 
1858
@w{  #              reference to = label     D, d           undefined              }
 
1859
@w{  $             undefined                E, e           undefined              }
 
1860
@w{  %              undefined                F, f           undefined              }
 
1861
@w{  &              undefined                G, g           undefined              }
 
1862
@w{  '              function abbreviation    H, h           undefined              }
 
1863
@w{  (              simple vector            I, i           undefined              }
 
1864
@w{  )              signals error            J, j           undefined              }
 
1865
@w{  @t{*}              bit vector               K, k           undefined              }
 
1866
@w{  ,              undefined                L, l           undefined              }
 
1867
@w{  :              uninterned symbol        M, m           undefined              }
 
1868
@w{  ;              undefined                N, n           undefined              }
 
1869
@w{  @t{<}              signals error            O, o           octal rational         }
 
1870
@w{  @t{=}              labels following object  P, p           pathname               }
 
1871
@w{  @t{>}              undefined                Q, q           undefined              }
 
1872
@w{  ?              undefined*               R, r           radix-n rational       }
 
1873
@w{  @@              undefined                S, s           structure              }
 
1874
@w{  [              undefined*               T, t           undefined              }
 
1875
@w{  @t{\}              character object         U, u           undefined              }
 
1876
@w{  ]              undefined*               V, v           undefined              }
 
1877
@w{  @t{^}            undefined                W, w           undefined              }
 
1878
@w{  @t{_}              undefined                X, x           hexadecimal rational   }
 
1879
@w{  `              undefined                Y, y           undefined              }
 
1880
@w{  @t{|}              balanced comment         Z, z           undefined              }
 
1881
@w{  @t{~}              undefined                Rubout         undefined              }
 
1882
 
 
1883
@noindent
 
1884
@w{           Figure 2--19: Standard # Dispatching Macro Character Syntax         }
 
1885
 
 
1886
@end group
 
1887
@end format
 
1888
 
 
1889
 
 
1890
The combinations marked by an asterisk (*) are explicitly reserved to the
 
1891
user.  No @i{conforming implementation} defines them.
 
1892
 
 
1893
Note also that @i{digits} do not appear in the preceding table.  This is
 
1894
because the notations @t{#0}, @t{#1}, ..., @t{#9} are
 
1895
reserved for another purpose which occupies the same syntactic space.
 
1896
When a @i{digit} follows a @i{sharpsign},
 
1897
it is not treated as a dispatch character.
 
1898
Instead, an unsigned integer argument is accumulated 
 
1899
and passed as an @i{argument} to the @i{reader macro} 
 
1900
for the @i{character} that follows the digits.
 
1901
For example,
 
1902
@t{#2A((1 2) (3 4))} is a use of @t{#A} with an argument of @t{2}.
 
1903
 
 
1904
@menu
 
1905
* Sharpsign Backslash::         
 
1906
* Sharpsign Single-Quote::      
 
1907
* Sharpsign Left-Parenthesis::  
 
1908
* Sharpsign Asterisk::          
 
1909
* Examples of Sharpsign Asterisk::  
 
1910
* Sharpsign Colon::             
 
1911
* Sharpsign Dot::               
 
1912
* Sharpsign B::                 
 
1913
* Sharpsign O::                 
 
1914
* Sharpsign X::                 
 
1915
* Sharpsign R::                 
 
1916
* Sharpsign C::                 
 
1917
* Sharpsign A::                 
 
1918
* Sharpsign S::                 
 
1919
* Sharpsign P::                 
 
1920
* Sharpsign Equal-Sign::        
 
1921
* Sharpsign Sharpsign::         
 
1922
* Sharpsign Plus::              
 
1923
* Sharpsign Minus::             
 
1924
* Sharpsign Vertical-Bar::      
 
1925
* Examples of Sharpsign Vertical-Bar::  
 
1926
* Notes about Style for Sharpsign Vertical-Bar::  
 
1927
* Sharpsign Less-Than-Sign::    
 
1928
* Sharpsign Whitespace::        
 
1929
* Sharpsign Right-Parenthesis::  
 
1930
@end menu
 
1931
 
 
1932
@node Sharpsign Backslash, Sharpsign Single-Quote, Sharpsign, Sharpsign
 
1933
@subsubsection Sharpsign Backslash
 
1934
 
 
1935
@b{Syntax:} @t{#\<<@i{x}>>}
 
1936
 
 
1937
When the @i{token} @i{x} is a single @i{character} long, 
 
1938
this parses as the literal @i{character} @i{char}.
 
1939
@i{Uppercase} and @i{lowercase} letters are distinguished after @t{#\};
 
1940
@t{#\A} and @t{#\a} denote different @i{character} @i{objects}.
 
1941
Any single @i{character} works after @t{#\},
 
1942
even those that are normally special to @b{read}, 
 
1943
such as @i{left-parenthesis} and @i{right-parenthesis}.
 
1944
 
 
1945
In the single @i{character} case,
 
1946
the @i{x} must be followed by a non-constituent @i{character}.
 
1947
After @t{#\} is read,
 
1948
the reader backs up over the @i{slash} and then reads a @i{token},
 
1949
treating the initial @i{slash} as a @i{single escape} @i{character}
 
1950
(whether it really is or not in the @i{current readtable}).
 
1951
 
 
1952
When the @i{token} @i{x} is more than one @i{character} long,
 
1953
the @i{x} must have the syntax of a @i{symbol} 
 
1954
with no embedded @i{package markers}.
 
1955
In this case, the @i{sharpsign} @i{backslash} notation
 
1956
parses as the @i{character} whose @i{name} is @t{(string-upcase @i{x})};
 
1957
see @ref{Character Names}.
 
1958
 
 
1959
For information about how the @i{Lisp printer} prints @i{character} @i{objects},
 
1960
see @ref{Printing Characters}.
 
1961
 
 
1962
@node Sharpsign Single-Quote, Sharpsign Left-Parenthesis, Sharpsign Backslash, Sharpsign
 
1963
@subsubsection Sharpsign Single-Quote
 
1964
 
 
1965
Any @i{expression} preceded by @t{#'} 
 
1966
(@i{sharpsign} followed by @i{single-quote}),
 
1967
as in @t{#'@i{expression}},
 
1968
is treated by the @i{Lisp reader} as an abbreviation for and parsed identically 
 
1969
to the @i{expression} @t{(function @i{expression})}.
 
1970
See @b{function}.  For example,
 
1971
 
 
1972
@example
 
1973
(apply #'+ l) @equiv{} (apply (function +) l)
 
1974
@end example
 
1975
 
 
1976
@node Sharpsign Left-Parenthesis, Sharpsign Asterisk, Sharpsign Single-Quote, Sharpsign
 
1977
@subsubsection Sharpsign Left-Parenthesis
 
1978
 
 
1979
@t{#(} and @t{)} are used to notate a @i{simple vector}. 
 
1980
 
 
1981
If an unsigned decimal integer
 
1982
appears between the @t{#} and @t{(},
 
1983
it specifies explicitly the length of the @i{vector}.  
 
1984
The consequences are undefined if the number of @i{objects} 
 
1985
specified before the closing @t{)}
 
1986
exceeds the unsigned decimal integer.
 
1987
If the number of @i{objects} supplied before the closing @t{)}
 
1988
is less than the unsigned decimal integer but greater than zero,
 
1989
the last @i{object}
 
1990
is used to fill all
 
1991
remaining elements of the @i{vector}.
 
1992
 
 
1993
[Editorial Note by Barmar: This should say "signals...".]
 
1994
The consequences are undefined if the unsigned decimal integer is non-zero and
 
1995
number of @i{objects} supplied before the closing @t{)}
 
1996
is zero.
 
1997
For example,
 
1998
 
 
1999
@example
 
2000
 #(a b c c c c)
 
2001
 #6(a b c c c c)
 
2002
 #6(a b c)
 
2003
 #6(a b c c)
 
2004
@end example
 
2005
 
 
2006
all mean the same thing: a @i{vector} of length @t{6}
 
2007
with @i{elements} @t{a}, @t{b}, and four occurrences of @t{c}.  
 
2008
Other examples follow:
 
2009
 
 
2010
@example
 
2011
 #(a b c)               ;A vector of length 3
 
2012
 #(2 3 5 7 11 13 17 19 23 29 31 37 41 43 47)
 
2013
                        ;A vector containing the primes below 50
 
2014
 #()                    ;An empty vector
 
2015
@end example
 
2016
 
 
2017
The notation @t{#()} denotes an empty @i{vector}, as does @t{#0()}.
 
2018
 
 
2019
For information on how the @i{Lisp printer} prints @i{vectors},
 
2020
see @ref{Printing Strings},
 
2021
    @ref{Printing Bit Vectors},
 
2022
 or @ref{Printing Other Vectors}.
 
2023
 
 
2024
@node Sharpsign Asterisk, Examples of Sharpsign Asterisk, Sharpsign Left-Parenthesis, Sharpsign
 
2025
@subsubsection Sharpsign Asterisk
 
2026
 
 
2027
@b{Syntax:} @t{#*<<@i{bits}>>}
 
2028
 
 
2029
A @i{simple bit vector} is constructed containing the indicated @i{bits}
 
2030
(@t{0}'s and @t{1}'s), where the leftmost @i{bit} has index zero 
 
2031
and the subsequent @i{bits} have increasing indices.
 
2032
 
 
2033
@b{Syntax:} @t{#<<@i{n}>>*<<@i{bits}>>}
 
2034
 
 
2035
With an argument @i{n},
 
2036
the @i{vector} to be created is of @i{length} @i{n}.
 
2037
If the number of @i{bits} is less than @i{n} but greater than zero,
 
2038
the last bit is used to fill all remaining bits of the @i{bit vector}.
 
2039
 
 
2040
The notations @t{#*} and @t{#0*} each denote an empty @i{bit vector}.
 
2041
 
 
2042
Regardless of whether the optional numeric argument @i{n} is provided,
 
2043
the @i{token} that follows the @i{asterisk} is delimited by 
 
2044
a normal @i{token} delimiter.
 
2045
However, (unless the @i{value} of @b{*read-suppress*} is @i{true})
 
2046
an error of @i{type} @b{reader-error} is signaled 
 
2047
     if that @i{token} is not composed entirely of @t{0}'s and @t{1}'s,
 
2048
  or if @i{n} was supplied 
 
2049
        and the @i{token} is composed of more than @i{n} @i{bits},
 
2050
  or if @i{n} is greater than one, but no @i{bits} were specified.
 
2051
Neither a @i{single escape} nor a @i{multiple escape} is permitted in this @i{token}.
 
2052
 
 
2053
For information on how the @i{Lisp printer} prints @i{bit vectors},
 
2054
see @ref{Printing Bit Vectors}.
 
2055
 
 
2056
@node Examples of Sharpsign Asterisk, Sharpsign Colon, Sharpsign Asterisk, Sharpsign
 
2057
@subsubsection Examples of Sharpsign Asterisk
 
2058
 
 
2059
For example, 
 
2060
@example
 
2061
  #*101111
 
2062
 #6*101111
 
2063
 #6*101
 
2064
 #6*1011
 
2065
@end example
 
2066
 
 
2067
all mean the same thing: a @i{vector} of length @t{6}
 
2068
with @i{elements} @t{1}, @t{0}, @t{1}, @t{1}, @t{1}, and @t{1}.
 
2069
 
 
2070
For example:
 
2071
 
 
2072
@example
 
2073
 #*         ;An empty bit-vector
 
2074
@end example
 
2075
 
 
2076
@node Sharpsign Colon, Sharpsign Dot, Examples of Sharpsign Asterisk, Sharpsign
 
2077
@subsubsection Sharpsign Colon
 
2078
 
 
2079
@b{Syntax:}  @t{#:<<@i{symbol-name}>>}
 
2080
 
 
2081
@t{#:} introduces an @i{uninterned} @i{symbol} whose @i{name} 
 
2082
is @i{symbol-name}.  Every time this syntax is encountered,
 
2083
a @i{distinct} @i{uninterned} @i{symbol} is created.
 
2084
The @i{symbol-name} must have the syntax of a @i{symbol} 
 
2085
with no @i{package prefix}.
 
2086
 
 
2087
For information on how the @i{Lisp reader} 
 
2088
prints @i{uninterned} @i{symbols},
 
2089
see @ref{Printing Symbols}.
 
2090
 
 
2091
@node Sharpsign Dot, Sharpsign B, Sharpsign Colon, Sharpsign
 
2092
@subsubsection Sharpsign Dot
 
2093
 
 
2094
@t{#.@i{foo}} is read as the @i{object} resulting from the evaluation
 
2095
of the @i{object} represented by @i{foo}.
 
2096
The evaluation is done during the @b{read} process,
 
2097
when the @t{#.} notation is encountered.
 
2098
The @t{#.} syntax therefore performs a read-time evaluation of @i{foo}.
 
2099
 
 
2100
The normal effect of @t{#.} is inhibited when the @i{value} of @b{*read-eval*} is @i{false}.
 
2101
 
 
2102
In that situation, an error of @i{type} @b{reader-error} is signaled.
 
2103
 
 
2104
For an @i{object}
 
2105
that does not have a convenient printed
 
2106
representation, a @i{form} that computes the @i{object} can be given using
 
2107
the @t{#.} notation.
 
2108
 
 
2109
@node Sharpsign B, Sharpsign O, Sharpsign Dot, Sharpsign
 
2110
@subsubsection Sharpsign B
 
2111
 
 
2112
@t{#B}@i{rational} reads @i{rational} in binary (radix 2).
 
2113
For example, 
 
2114
 
 
2115
@example
 
2116
 #B1101 @equiv{} 13 ;1101_2
 
2117
 #b101/11 @equiv{} 5/3
 
2118
@end example
 
2119
 
 
2120
The consequences are undefined if the token immediately following
 
2121
the @t{#B} does not have the syntax of a binary (@i{i.e.}, radix 2) @i{rational}.
 
2122
 
 
2123
@node Sharpsign O, Sharpsign X, Sharpsign B, Sharpsign
 
2124
@subsubsection Sharpsign O
 
2125
 
 
2126
@t{#O}@i{rational} reads @i{rational} in octal (radix 8).
 
2127
For example, 
 
2128
 
 
2129
@example
 
2130
 #o37/15 @equiv{} 31/13
 
2131
 #o777 @equiv{} 511
 
2132
 #o105 @equiv{} 69 ;105_8
 
2133
@end example
 
2134
 
 
2135
The consequences are undefined if the token immediately following
 
2136
the @t{#O} does not have the syntax of an octal (@i{i.e.}, radix 8) @i{rational}.
 
2137
 
 
2138
@node Sharpsign X, Sharpsign R, Sharpsign O, Sharpsign
 
2139
@subsubsection Sharpsign X
 
2140
 
 
2141
@t{#X}@i{rational} reads @i{rational} in hexadecimal (radix 16).
 
2142
The digits above @t{9} are the letters @t{A} through @t{F} (the lowercase
 
2143
letters @t{a} through @t{f} are also acceptable).  For example,
 
2144
 
 
2145
@example
 
2146
 #xF00 @equiv{} 3840             
 
2147
 #x105 @equiv{} 261 ;105_@t{16}
 
2148
@end example
 
2149
 
 
2150
The consequences are undefined if the token immediately following
 
2151
the @t{#X} does not have the syntax of a hexadecimal (@i{i.e.}, radix 16) @i{rational}.
 
2152
 
 
2153
@node Sharpsign R, Sharpsign C, Sharpsign X, Sharpsign
 
2154
@subsubsection Sharpsign R
 
2155
 
 
2156
@t{#@i{n}R}
 
2157
 
 
2158
@t{#@i{radix}R@i{rational}} reads @i{rational} in radix @i{radix}.
 
2159
@i{radix} must consist of only digits
 
2160
that are interpreted as an @i{integer}
 
2161
in decimal radix; its value must be between 2 and 36 (inclusive).
 
2162
Only valid digits
 
2163
for the specified radix may be used.
 
2164
 
 
2165
For example, @t{#3r102} is another way of writing @t{11} (decimal), 
 
2166
and @t{#11R32}
 
2167
is another way of writing @t{35} (decimal).  
 
2168
For radices larger than 10, letters of
 
2169
the alphabet are used in order for the digits after @t{9}.
 
2170
No alternate @t{#} notation exists for the decimal radix since a
 
2171
decimal point suffices.
 
2172
 
 
2173
Figure 2--20 contains examples of the use of @t{#B},
 
2174
@t{#O}, @t{#X}, and @t{#R}.
 
2175
 
 
2176
@format
 
2177
@group
 
2178
@noindent
 
2179
@w{  @t{#2r11010101}  ;Another way of writing @t{213} decimal  }
 
2180
@w{  @t{#b11010101}   ;Ditto                               }
 
2181
@w{  @t{#b+11010101}  ;Ditto                               }
 
2182
@w{  @t{#o325}        ;Ditto, in octal radix               }
 
2183
@w{  @t{#xD5}         ;Ditto, in hexadecimal radix         }
 
2184
@w{  @t{#16r+D5}      ;Ditto                               }
 
2185
@w{  @t{#o-300}       ;Decimal @t{-192}, written in base 8     }
 
2186
@w{  @t{#3r-21010}    ;Same thing in base 3                }
 
2187
@w{  @t{#25R-7H}      ;Same thing in base 25               }
 
2188
@w{  @t{#xACCEDED}    ;@t{181202413}, in hexadecimal radix     }
 
2189
 
 
2190
@noindent
 
2191
@w{        Figure 2--20: Radix Indicator Example       }
 
2192
 
 
2193
@end group
 
2194
@end format
 
2195
 
 
2196
The consequences are undefined if the token immediately following
 
2197
the @t{#@i{n}R} does not have the syntax of a @i{rational} in radix @i{n}.
 
2198
 
 
2199
@node Sharpsign C, Sharpsign A, Sharpsign R, Sharpsign
 
2200
@subsubsection Sharpsign C
 
2201
 
 
2202
@t{#C} reads a following @i{object}, which must be a @i{list} of
 
2203
length two whose @i{elements} are both @i{reals}.
 
2204
These @i{reals} denote, respectively,
 
2205
the real and imaginary parts of a @i{complex} number.
 
2206
 
 
2207
If the two parts as notated are not of the same data type,
 
2208
then they are converted 
 
2209
according to the rules of floating-point @i{contagion}
 
2210
described in @ref{Contagion in Numeric Operations}.
 
2211
 
 
2212
@t{#C(@i{real} @i{imag})} is equivalent to 
 
2213
@t{#.(complex (quote @i{real}) (quote @i{imag}))},
 
2214
except that @t{#C} is not affected by @b{*read-eval*}.
 
2215
See the @i{function} @b{complex}.
 
2216
 
 
2217
Figure 2--21 contains examples of the use of @t{#C}.
 
2218
 
 
2219
@format
 
2220
@group
 
2221
@noindent
 
2222
@w{  @t{#C(3.0s1 2.0s-1)}  ;A @i{complex} with @i{small float} parts.                }
 
2223
@w{  @t{#C(5 -3) }         ;A ``Gaussian integer''                             }
 
2224
@w{  @t{#C(5/3 7.0) }      ;Will be converted internally to @t{#C(1.66666 7.0)}  }
 
2225
@w{  @t{#C(0 1)}           ;The imaginary unit; that is, i.                  }
 
2226
 
 
2227
@noindent
 
2228
@w{                  Figure 2--21: Complex Number Example                }
 
2229
 
 
2230
@end group
 
2231
@end format
 
2232
 
 
2233
For further information, 
 
2234
see @ref{Printing Complexes} and @ref{Syntax of a Complex}.
 
2235
 
 
2236
@node Sharpsign A, Sharpsign S, Sharpsign C, Sharpsign
 
2237
@subsubsection Sharpsign A
 
2238
 
 
2239
@t{#@i{n}A}
 
2240
 
 
2241
@t{#@i{n}@t{A}@i{object}} constructs an @i{n}-dimensional @i{array},
 
2242
using @i{object} as the value of the @t{:initial-contents} argument
 
2243
to @b{make-array}.
 
2244
 
 
2245
For example, @t{#2A((0 1 5) (foo 2 (hot dog)))} represents a 2-by-3 matrix:
 
2246
 
 
2247
@example
 
2248
 0       1       5
 
2249
 foo     2       (hot dog)
 
2250
@end example
 
2251
 
 
2252
In contrast, @t{#1A((0 1 5) (foo 2 (hot dog)))} 
 
2253
represents a @i{vector} of @i{length} @t{2} 
 
2254
whose @i{elements} are @i{lists}:
 
2255
 
 
2256
@example
 
2257
 (0 1 5) (foo 2 (hot dog))
 
2258
@end example
 
2259
 
 
2260
@t{#0A((0 1 5) (foo 2 (hot dog)))} represents a zero-dimensional
 
2261
@i{array} whose sole element is a @i{list}:
 
2262
 
 
2263
@example
 
2264
 ((0 1 5) (foo 2 (hot dog)))
 
2265
@end example
 
2266
 
 
2267
@t{#0A foo} represents 
 
2268
a zero-dimensional @i{array} whose sole element is the 
 
2269
@i{symbol} @t{foo}.
 
2270
The notation @t{#1A foo} is not valid because @t{foo} is
 
2271
not a @i{sequence}.
 
2272
 
 
2273
If some @i{dimension} of the @i{array}
 
2274
whose representation is being parsed is found to be @t{0},
 
2275
all @i{dimensions} to the right 
 
2276
(@i{i.e.}, the higher numbered @i{dimensions})
 
2277
are also considered to be @t{0}.
 
2278
 
 
2279
For information on how the @i{Lisp printer} prints @i{arrays},
 
2280
see @ref{Printing Strings},
 
2281
    @ref{Printing Bit Vectors},
 
2282
    @ref{Printing Other Vectors},
 
2283
 or @ref{Printing Other Arrays}.
 
2284
 
 
2285
@node Sharpsign S, Sharpsign P, Sharpsign A, Sharpsign
 
2286
@subsubsection Sharpsign S
 
2287
 
 
2288
@t{#s(name slot1 value1 slot2 value2 ...)}
 
2289
denotes a @i{structure}.  This is valid only if @i{name} is the name
 
2290
of a @i{structure} @i{type} already defined by @b{defstruct} 
 
2291
and if the @i{structure} @i{type} has a standard constructor function.
 
2292
Let @i{cm} stand for the name of this constructor function;
 
2293
then this syntax is equivalent to
 
2294
 
 
2295
@example
 
2296
 #.(cm keyword1 'value1 keyword2 'value2 ...)
 
2297
@end example
 
2298
 
 
2299
where each @i{keywordj} is the result of computing
 
2300
 
 
2301
@example
 
2302
 (intern (string slotj) (find-package 'keyword))
 
2303
@end example
 
2304
 
 
2305
The net effect is that the constructor function is called with the specified
 
2306
slots having the specified values. 
 
2307
 
 
2308
(This coercion feature is deprecated; in the future, keyword names will 
 
2309
 be taken in the package they are read in, so @i{symbols} that are 
 
2310
 actually in the @t{KEYWORD} @i{package} should be used if that is what is desired.)
 
2311
 
 
2312
Whatever @i{object} the constructor function returns
 
2313
is returned by the @t{#S} syntax.
 
2314
 
 
2315
For information on how the @i{Lisp printer} prints @i{structures},
 
2316
see @ref{Printing Structures}.
 
2317
 
 
2318
@node Sharpsign P, Sharpsign Equal-Sign, Sharpsign S, Sharpsign
 
2319
@subsubsection Sharpsign P
 
2320
 
 
2321
@t{#P} reads a following @i{object}, which must be a @i{string}.
 
2322
 
 
2323
@t{#P<<@i{expression}>>} is equivalent to 
 
2324
@t{#.(parse-namestring '<<@i{expression}>>)},
 
2325
except that @t{#P} is not affected by @b{*read-eval*}.
 
2326
 
 
2327
For information on how the @i{Lisp printer} prints @i{pathnames},
 
2328
see @ref{Printing Pathnames}.
 
2329
 
 
2330
@node Sharpsign Equal-Sign, Sharpsign Sharpsign, Sharpsign P, Sharpsign
 
2331
@subsubsection Sharpsign Equal-Sign
 
2332
 
 
2333
@t{#@i{n}=}
 
2334
 
 
2335
@t{#@i{n}=@i{object}} reads as whatever @i{object}
 
2336
has @i{object} as its printed representation.  However, that @i{object}
 
2337
is labeled by @i{n}, a required unsigned decimal integer, for
 
2338
possible reference by the syntax @t{#@i{n}#}.
 
2339
The scope of the label is the @i{expression} being read by the outermost
 
2340
call to @b{read}; within this @i{expression},
 
2341
the same label may not appear twice.
 
2342
 
 
2343
@node Sharpsign Sharpsign, Sharpsign Plus, Sharpsign Equal-Sign, Sharpsign
 
2344
@subsubsection Sharpsign Sharpsign
 
2345
 
 
2346
@t{#@i{n}#}
 
2347
 
 
2348
@t{#@i{n}#}, where @i{n} is a required unsigned decimal
 
2349
@i{integer},
 
2350
provides a reference to some @i{object} labeled by @t{#@i{n}=};
 
2351
that is, @t{#@i{n}#} represents a pointer to the same 
 
2352
(@b{eq}) @i{object} labeled by @t{#@i{n}=}.
 
2353
For example, a structure created in the variable @t{y} by this code:
 
2354
 
 
2355
@example
 
2356
 (setq x (list 'p 'q))
 
2357
 (setq y (list (list 'a 'b) x 'foo x))
 
2358
 (rplacd (last y) (cdr y))
 
2359
@end example
 
2360
 
 
2361
could be represented in this way:
 
2362
 
 
2363
@example
 
2364
 ((a b) . #1=(#2=(p q) foo #2# . #1#))
 
2365
@end example
 
2366
 
 
2367
Without this notation, but with @b{*print-length*} set to @t{10}
 
2368
and @b{*print-circle*} set to @b{nil},
 
2369
the structure would print in this way:
 
2370
 
 
2371
@example
 
2372
 ((a b) (p q) foo (p q) (p q) foo (p q) (p q) foo (p q) ...)
 
2373
@end example
 
2374
 
 
2375
A reference @t{#@i{n}#} may only occur after a label @t{#@i{n}=};
 
2376
forward references are not permitted.  The reference
 
2377
may not appear as the labeled object itself (that is,
 
2378
@t{#@i{n}=#@i{n}#}) may not be written 
 
2379
because the @i{object}
 
2380
labeled by @t{#@i{n}=} is not well defined in this case.
 
2381
 
 
2382
@node Sharpsign Plus, Sharpsign Minus, Sharpsign Sharpsign, Sharpsign
 
2383
@subsubsection Sharpsign Plus
 
2384
 
 
2385
@t{#+} provides a read-time conditionalization facility;
 
2386
the syntax is @t{#+@i{test} @i{expression}}.
 
2387
If the @i{feature expression} @i{test} succeeds,
 
2388
then this textual notation represents an @i{object}
 
2389
 whose printed representation is @i{expression}.
 
2390
If the @i{feature expression} @i{test} fails,
 
2391
then this textual notation is treated as @i{whitespace}_2; 
 
2392
 that is, it is as if the ``@t{#+} @i{test} @i{expression}'' 
 
2393
 did not appear and only a @i{space} appeared in its place.
 
2394
 
 
2395
For a detailed description of success and failure in @i{feature expressions},
 
2396
see @ref{Feature Expressions}.
 
2397
 
 
2398
@t{#+} operates by first reading the @i{feature expression}
 
2399
and then skipping over the @i{form} if the @i{feature expression} fails.
 
2400
 
 
2401
While reading the @i{test}, the @i{current package} is the @t{KEYWORD} @i{package}.
 
2402
 
 
2403
Skipping over the @i{form} is accomplished by @i{binding} 
 
2404
@b{*read-suppress*} to @i{true} and then calling @b{read}.
 
2405
 
 
2406
For examples, see @ref{Examples of Feature Expressions}.
 
2407
 
 
2408
@node Sharpsign Minus, Sharpsign Vertical-Bar, Sharpsign Plus, Sharpsign
 
2409
@subsubsection Sharpsign Minus
 
2410
 
 
2411
@t{#-} is like @t{#+} 
 
2412
except that it skips the @i{expression} if the @i{test} succeeds; 
 
2413
that is,
 
2414
 
 
2415
@example
 
2416
#-@i{test} @i{expression} @equiv{} #+(not @i{test}) @i{expression}
 
2417
@end example
 
2418
 
 
2419
For examples, see @ref{Examples of Feature Expressions}.
 
2420
 
 
2421
@node Sharpsign Vertical-Bar, Examples of Sharpsign Vertical-Bar, Sharpsign Minus, Sharpsign
 
2422
@subsubsection Sharpsign Vertical-Bar
 
2423
 
 
2424
@t{#|...|#} is treated as a comment by the reader.
 
2425
It must be balanced with respect to other occurrences of @t{#|} and @t{|#},
 
2426
but otherwise may contain any characters whatsoever.
 
2427
 
 
2428
@node Examples of Sharpsign Vertical-Bar, Notes about Style for Sharpsign Vertical-Bar, Sharpsign Vertical-Bar, Sharpsign
 
2429
@subsubsection Examples of Sharpsign Vertical-Bar
 
2430
 
 
2431
The following are some examples that exploit the @t{#|...|#} notation:
 
2432
 
 
2433
@example
 
2434
;;; In this example, some debugging code is commented out with #|...|#
 
2435
;;; Note that this kind of comment can occur in the middle of a line
 
2436
;;; (because a delimiter marks where the end of the comment occurs)
 
2437
;;; where a semicolon comment can only occur at the end of a line 
 
2438
;;; (because it comments out the rest of the line).
 
2439
 (defun add3 (n) #|(format t "~&Adding 3 to ~D." n)|# (+ n 3))
 
2440
 
 
2441
;;; The examples that follow show issues related to #| ... |# nesting.
 
2442
 
 
2443
;;; In this first example, #| and |# always occur properly paired,
 
2444
;;; so nesting works naturally.
 
2445
 (defun mention-fun-fact-1a ()
 
2446
   (format t "CL uses ; and #|...|# in comments."))
 
2447
@result{}  MENTION-FUN-FACT-1A
 
2448
 (mention-fun-fact-1a)
 
2449
@t{ |> } CL uses ; and #|...|# in comments.
 
2450
@result{}  NIL
 
2451
 #| (defun mention-fun-fact-1b ()
 
2452
      (format t "CL uses ; and #|...|# in comments.")) |#
 
2453
 (fboundp 'mention-fun-fact-1b) @result{}  NIL
 
2454
 
 
2455
;;; In this example, vertical-bar followed by sharpsign needed to appear
 
2456
;;; in a string without any matching sharpsign followed by vertical-bar
 
2457
;;; having preceded this.  To compensate, the programmer has included a
 
2458
;;; slash separating the two characters.  In case 2a, the slash is 
 
2459
;;; unnecessary but harmless, but in case 2b, the slash is critical to
 
2460
;;; allowing the outer #| ... |# pair match.  If the slash were not present,
 
2461
;;; the outer comment would terminate prematurely.
 
2462
 (defun mention-fun-fact-2a ()
 
2463
   (format t "Don't use |\# unmatched or you'll get in trouble!"))
 
2464
@result{}  MENTION-FUN-FACT-2A
 
2465
 (mention-fun-fact-2a)
 
2466
@t{ |> } Don't use |# unmatched or you'll get in trouble!
 
2467
@result{}  NIL
 
2468
 #| (defun mention-fun-fact-2b ()
 
2469
      (format t "Don't use |\# unmatched or you'll get in trouble!") |#
 
2470
 (fboundp 'mention-fun-fact-2b) @result{}  NIL
 
2471
 
 
2472
;;; In this example, the programmer attacks the mismatch problem in a
 
2473
;;; different way.  The sharpsign vertical bar in the comment is not needed
 
2474
;;; for the correct parsing of the program normally (as in case 3a), but 
 
2475
;;; becomes important to avoid premature termination of a comment when such 
 
2476
;;; a program is commented out (as in case 3b).
 
2477
 (defun mention-fun-fact-3a () ; #|
 
2478
   (format t "Don't use |# unmatched or you'll get in trouble!"))
 
2479
@result{}  MENTION-FUN-FACT-3A
 
2480
 (mention-fun-fact-3a)
 
2481
@t{ |> } Don't use |# unmatched or you'll get in trouble!
 
2482
@result{}  NIL
 
2483
 #|
 
2484
 (defun mention-fun-fact-3b () ; #|
 
2485
   (format t "Don't use |# unmatched or you'll get in trouble!"))
 
2486
 |#
 
2487
 (fboundp 'mention-fun-fact-3b) @result{}  NIL
 
2488
@end example
 
2489
 
 
2490
@node Notes about Style for Sharpsign Vertical-Bar, Sharpsign Less-Than-Sign, Examples of Sharpsign Vertical-Bar, Sharpsign
 
2491
@subsubsection Notes about Style for Sharpsign Vertical-Bar
 
2492
 
 
2493
Some text editors that purport to understand Lisp syntax treat any @t{|...|}
 
2494
as balanced pairs that cannot nest (as if they were just balanced pairs of 
 
2495
the multiple escapes used in notating certain symbols).  To compensate for 
 
2496
this deficiency, some programmers use the notation @t{#||...#||...||#...||#}
 
2497
instead of @t{#|...#|...|#...|#}.   Note that this alternate usage is not
 
2498
a different @i{reader macro}; it merely exploits the fact that the additional
 
2499
vertical-bars occur within the comment in a way that tricks certain text editor
 
2500
into better supporting nested comments.  As such, one might sometimes see code
 
2501
like:
 
2502
 
 
2503
@example
 
2504
 #|| (+ #|| 3 ||# 4 5) ||# 
 
2505
@end example
 
2506
 
 
2507
Such code is equivalent to:
 
2508
 
 
2509
@example
 
2510
 #| (+ #| 3 |# 4 5) |#
 
2511
@end example
 
2512
 
 
2513
@node Sharpsign Less-Than-Sign, Sharpsign Whitespace, Notes about Style for Sharpsign Vertical-Bar, Sharpsign
 
2514
@subsubsection Sharpsign Less-Than-Sign
 
2515
 
 
2516
@t{#<} is not valid reader syntax.
 
2517
The @i{Lisp reader} will signal an error 
 
2518
 
 
2519
of @i{type} @b{reader-error}
 
2520
 
 
2521
on encountering @t{#<}.
 
2522
This syntax is typically used in the printed representation 
 
2523
of @i{objects} that cannot be read back in.  
 
2524
 
 
2525
@node Sharpsign Whitespace, Sharpsign Right-Parenthesis, Sharpsign Less-Than-Sign, Sharpsign
 
2526
@subsubsection Sharpsign Whitespace
 
2527
 
 
2528
@t{#} followed immediately by @i{whitespace}_1 is not valid reader syntax.
 
2529
The @i{Lisp reader} will signal an error of @i{type} @b{reader-error} if it
 
2530
encounters the reader macro notation @t{#<@i{Newline}>} or @t{#<@i{Space}>}.
 
2531
 
 
2532
@node Sharpsign Right-Parenthesis,  , Sharpsign Whitespace, Sharpsign
 
2533
@subsubsection Sharpsign Right-Parenthesis
 
2534
 
 
2535
This is not valid reader syntax.
 
2536
 
 
2537
The @i{Lisp reader} will signal an error 
 
2538
 
 
2539
of @i{type} @b{reader-error}
 
2540
 
 
2541
upon encountering @t{#)}.
 
2542
 
 
2543
@node Re-Reading Abbreviated Expressions,  , Sharpsign, Standard Macro Characters
 
2544
@subsection Re-Reading Abbreviated Expressions
 
2545
 
 
2546
Note that the @i{Lisp reader} will 
 
2547
generally
 
2548
signal an error of @i{type} @b{reader-error}
 
2549
when reading an @i{expression}_2 that has been
 
2550
abbreviated because of length or level limits 
 
2551
(see @b{*print-level*},
 
2552
     @b{*print-length*},
 
2553
 and @b{*print-lines*})
 
2554
due to restrictions on ``@t{..}'', ``@t{...}'', ``@t{#}'' followed by @i{whitespace}_1,
 
2555
and ``@t{#)}''.
 
2556
 
 
2557
@c end of including concept-macro-chars
 
2558
 
 
2559
@c %**end of chapter
 
2560