My various dotfiles

chap-2.texi 99KB

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