concept-tokens.tex 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672
  1. % -*- Mode: TeX -*-
  2. %% Interpretation of Tokens
  3. \beginsubsection{Numbers as Tokens}
  4. %% 22.1.2 1
  5. %% 22.1.2 2
  6. When a \term{token} is read,
  7. it is interpreted as a \term{number} or \term{symbol}.
  8. The \term{token} is interpreted as a \term{number} if it satisfies
  9. the syntax for numbers specified in \thenextfigure.
  10. %\term{Whitespace}\meaning{2}, macro, and escape
  11. %characters are treated as \term{alphabetic}\meaning{2} within an extended \term{token}
  12. %unless preceded by an escape character.
  13. \DefineFigure{SyntaxForNumericTokens}
  14. %% 2.1.2 3
  15. %% 2.1.2 4
  16. %% 22.1.2 3
  17. \boxfig
  18. {\advance\baselineskip by 2.5pt
  19. \halign{{\hskip 2pc}#\hfil&#\hfil&#\hfil\cr
  20. \param{numeric-token} & ::$=$ & \down{integer} $\vert$
  21. \down{ratio} $\vert$
  22. \down{float} \cr
  23. \param{integer} & ::$=$ & \ttbrac{\param{sign}}
  24. \plusparam{decimal-digit}
  25. \param{decimal-point} $\vert$
  26. \ttbrac{\param{sign}}
  27. \plusparam{digit} \cr
  28. % \param{integer} & ::$=$ & \ttbrac{\param{sign}}
  29. % \plus{\curly{\param{digit}}}
  30. % \ttbrac{\param{decimal-point}} \cr
  31. \param{ratio} & ::$=$ & \ttbrac{\param{sign}}
  32. \plus{\curly{\param{digit}}}
  33. \param{slash}
  34. \plus{\curly{\param{digit}}} \cr
  35. \param{float} & ::$=$ & \ttbrac{\param{sign}}
  36. \star{\curly{\param{decimal-digit}}}
  37. \param{decimal-point}
  38. \plus{\curly{\param{decimal-digit}}}
  39. \ttbrac{\down{exponent}} \cr
  40. & & $\vert\;$
  41. \ttbrac{\param{sign}}
  42. \plus{\curly{\param{decimal-digit}}}
  43. \ttbrac{\param{decimal-point}
  44. \star{\curly{\param{decimal-digit}}}}
  45. \down{exponent} \cr
  46. \param{exponent} & ::$=$ & \param{exponent-marker}
  47. \ttbrac{\param{sign}}
  48. \plus{\curly{\param{digit}}} \cr
  49. \noalign{\vskip 5pt}
  50. \param{sign}---a \term{sign}.\span\span\cr
  51. \param{slash}---a \term{slash}\span\span\cr
  52. \param{decimal-point}---a \term{dot}.\span\span\cr
  53. \param{exponent-marker}---an \term{exponent marker}.\span\span\cr
  54. \param{decimal-digit}---a \term{digit} in \term{radix} \f{10}.\span\span\cr
  55. \param{digit}---a \term{digit} in the \term{current input radix}.\span\span\cr
  56. }}
  57. \caption{Syntax for Numeric Tokens}
  58. \endfig
  59. \beginsubsubsection{Potential Numbers as Tokens}
  60. \DefineSection{PotentialNumbersAsTokens}
  61. %% 22.1.2 3
  62. %% 22.1.2 4
  63. To allow implementors and future \clisp\ standards
  64. to extend the syntax of numbers, a
  65. syntax for \term{potential numbers} is defined that is
  66. more general than the syntax for numbers.
  67. A \term{token} is a \term{potential number} if it satisfies all of the following
  68. requirements:
  69. %% 22.1.2 5
  70. \beginlist
  71. \item{1.}
  72. The \term{token} consists entirely of
  73. \term{digits},
  74. \term{signs},
  75. \term{ratio markers},
  76. decimal points (\f{.}),
  77. extension characters (\hat\ or \f{\_}),
  78. and number markers.
  79. A number marker is a letter.
  80. Whether a letter may be treated as a number marker depends on context,
  81. but no letter that is adjacent to another letter may ever be treated as a number marker.
  82. \term{Exponent markers} are number markers.
  83. %% 22.1.2 6
  84. \item{2.}
  85. The \term{token} contains at least one digit. Letters may be considered to be
  86. digits, depending on the \term{current input base}, but only
  87. in \term{tokens} containing no decimal points.
  88. %% 22.1.2 7
  89. \item{3.}
  90. The \term{token} begins with a \term{digit}, \term{sign}, decimal point, or extension character,
  91. \issue{COLON-NUMBER}
  92. \reviewer{Barmar: This section is unnecessary because the first bullet already
  93. omits discussion of a colon (\term{package marker}).}%!!!
  94. but not a
  95. %colon.
  96. \term{package marker}.
  97. The syntax involving a leading
  98. %colon
  99. \term{package marker} followed by a \term{potential number} is
  100. not well-defined. The consequences of the use
  101. of notation such as \f{:1}, \f{:1/2}, and \f{:2{\hat}3} in a
  102. position where an expression appropriate for \funref{read}
  103. is expected are unspecified.
  104. \endissue{COLON-NUMBER}
  105. %% 22.1.2 8
  106. \item{4.}
  107. The \term{token} does not end with a sign.
  108. \endlist
  109. %% 22.1.2 10
  110. If a \term{potential number} has number syntax,
  111. a \term{number} of the appropriate type is constructed and returned,
  112. if the \term{number} is representable in an implementation.
  113. A \term{number} will not be representable in an implementation
  114. if it is outside the boundaries set by the \term{implementation-dependent}
  115. constants for \term{numbers}.
  116. For example, specifying too large or too small an exponent for a \term{float}
  117. may make the \term{number} impossible to represent in the implementation.
  118. A \term{ratio} with denominator zero (such as \f{-35/000})
  119. is not represented in any implementation.
  120. When a \term{token} with the syntax of a number cannot be converted to an internal
  121. \term{number}, an error \oftype{reader-error} is signaled. An error
  122. must not be signaled for specifying too many significant digits
  123. for a \term{float}; a truncated or rounded value should be produced.
  124. %% 22.1.2 11
  125. %% 22.1.2 12
  126. If there is an ambiguity as to whether
  127. a letter should be treated as a digit or as a number marker,
  128. the letter is treated as a digit.
  129. \beginsubsubsubsection{Escape Characters and Potential Numbers}
  130. \DefineSection{EscCharsAndPotentialNums}
  131. %% This section moved from 22.1.2 per Loosemore #11 (first public review). -kmp 10-May-93
  132. %% 22.1.2 9
  133. %The printed representation for
  134. A \term{potential number} cannot contain any \term{escape}
  135. \term{characters}. An \term{escape} \term{character} robs the following
  136. \term{character} of all syntactic qualities, forcing it to be strictly
  137. \term{alphabetic}\meaning{2} and therefore unsuitable for use in a
  138. \term{potential number}. For example, all of the following
  139. representations are interpreted as \term{symbols}, not \term{numbers}:
  140. \code
  141. \\256 25\\64 1.0\\E6 |100| 3\\.14159 |3/4| 3\\/4 5||
  142. \endcode
  143. In each case, removing the \term{escape} \term{character} (or \term{characters})
  144. would
  145. %% Kent and Sandra agreed that the following word change was editorial
  146. %% and would de-mystify the intent. -kmp 12-May-93
  147. %allow the token to be treated as a \term{number}.
  148. cause the token to be a \term{potential number}.
  149. \endsubsubsubsection%{Escape Characters and Potential Numbers}
  150. \beginsubsubsubsection{Examples of Potential Numbers}
  151. As examples, the \term{tokens} in \thenextfigure\ are \term{potential numbers},
  152. but they are not actually numbers, and so are reserved \term{tokens};
  153. a \term{conforming implementation} is permitted, but not required,
  154. to define their meaning.
  155. \showfive{Examples of reserved tokens}{
  156. \f{1b5000} & \f{777777q} & \f{1.7J} & \f{-3/4+6.7J} & \f{12/25/83}\cr
  157. \f{27{\hat}19} & \f{3{\hat}4/5} & \f{6//7} & \f{3.1.2.6} & \f{{\hat}-43\hat}\cr
  158. \f{3.141_592_653_589_793_238_4} & \f{-3.7+2.6i-6.17j+19.6k}\cr
  159. }
  160. The \term{tokens} in \thenextfigure\ are not \term{potential numbers};
  161. they are always treated as \term{symbols}:
  162. \showfive{Examples of symbols}{
  163. \f{/} & \f{/5} & \f{+} & \f{1+} & \f{1-}\cr
  164. \f{foo+} & \f{ab.cd} & \f{\_} & \f{\hat} & \f{{\hat}/-}\cr
  165. }
  166. The \term{tokens} in \thenextfigure\ are \term{potential numbers}
  167. if the \term{current input base} is \f{16},
  168. but they are always treated as \term{symbols} if the \term{current input base} is \f{10}.
  169. \showfive{Examples of symbols or potential numbers}{
  170. \f{bad-face} & \f{25-dec-83} & \f{a/b} & \f{fad_cafe} & \f{f{\hat}}\cr
  171. }
  172. \endsubsubsubsection%{Examples of Potential Numbers}
  173. \endsubsubsection%{Potential Numbers}
  174. \endsubsection%{Numbers as Tokens}
  175. \beginsubsection{Constructing Numbers from Tokens}
  176. \DefineSection{NumsFromTokens}
  177. A \term{real} is constructed directly from a corresponding numeric \term{token};
  178. \seefigure\SyntaxForNumericTokens.
  179. A \term{complex} is notated as a \f{\#C} (or \f{\#c}) followed by a \term{list}
  180. of two \term{reals}; \seesection\SharpsignC.
  181. The \term{reader macros} \f{\#B}, \f{\#O}, \f{\#X}, and \f{\#R} may also be useful
  182. in controlling the input \term{radix} in which \term{rationals} are parsed;
  183. \seesection\SharpsignB,
  184. \secref\SharpsignO,
  185. \secref\SharpsignX,
  186. and \secref\SharpsignR.
  187. This section summarizes the full syntax for \term{numbers}.
  188. \beginsubsubsection{Syntax of a Rational}
  189. \beginsubsubsubsection{Syntax of an Integer}
  190. \DefineSection{SyntaxOfIntegers}
  191. %% 2.1.2 3
  192. % \term{Integers} can be written as a sequence of digits, optionally
  193. % preceded by a sign and optionally followed by a decimal point;
  194. % \seefigure\SyntaxForNumericTokens.
  195. \term{Integers} can be written as a sequence of \term{digits},
  196. optionally preceded by a \term{sign} and optionally followed by a decimal point;
  197. \seefigure\SyntaxForNumericTokens.
  198. When a decimal point is used,
  199. the \term{digits} are taken to be in \term{radix} \f{10};
  200. when no decimal point is used,
  201. the \term{digits} are taken to be in radix given by the \term{current input base}.
  202. For information on how \term{integers} are printed, \seesection\PrintingIntegers.
  203. \endsubsubsubsection%{Syntax of an Integer}
  204. \beginsubsubsubsection{Syntax of a Ratio}
  205. \DefineSection{SyntaxOfRatios}
  206. \term{Ratios} can be written as an optional \term{sign} followed by two
  207. non-empty sequences of \term{digits} separated by a \term{slash};
  208. \seefigure\SyntaxForNumericTokens.
  209. %% 2.1.2 4
  210. The second sequence may not consist
  211. entirely of zeros.
  212. %The same radix specifiers
  213. %(one of \f{\#\param{nn}R}, \f{\#O}, \f{\#B}, or \f{\#X}) as for
  214. %\term{integers}
  215. %are used to notate \term{ratios} in radices other than ten.
  216. Examples of \term{ratios} are in \thenextfigure.
  217. \showtwo{Examples of Ratios}{
  218. \f{2/3} & ;This is in canonical form \cr
  219. \f{4/6} & ;A non-canonical form for 2/3 \cr
  220. \f{-17/23} & ;A ratio preceded by a sign \cr
  221. \f{-30517578125/32768} & ;This is $(-5/2)^{15}$ \cr
  222. \f{10/5} & ;The canonical form for this is \f{2} \cr
  223. \f{\#o-101/75} & ;Octal notation for $-65/61$ \cr
  224. \f{\#3r120/21} & ;Ternary notation for $15/7$ \cr
  225. \f{\#Xbc/ad} & ;Hexadecimal notation for $188/173$ \cr
  226. \f{\#xFADED/FACADE} & ;Hexadecimal notation for $1027565/16435934$ \cr
  227. }
  228. \reviewer{Barmar: \#o, \#3r, \#X, and \#x mentioned above
  229. are not in the syntax rules defined just above that.}
  230. %!!! Maybe they don't belong here? -kmp 17-Oct-90
  231. For information on how \term{ratios} are printed,
  232. \seesection\PrintingRatios.
  233. \endsubsubsubsection%{Syntax of a Ratio}
  234. \endsubsubsection%{Syntax of a Rational}
  235. \beginsubsubsection{Syntax of a Float}
  236. \DefineSection{SyntaxOfFloats}
  237. %% 2.1.3 7
  238. \term{Floats} can be written in either decimal fraction or computerized
  239. scientific notation: an optional sign, then a non-empty sequence of digits
  240. with an embedded decimal point,
  241. then an optional decimal exponent specification.
  242. If there is no exponent specifier, then
  243. the decimal point is required, and there must be digits
  244. after it.
  245. The exponent specifier consists of an \term{exponent marker},
  246. an optional sign, and a non-empty sequence of digits.
  247. If no exponent specifier is present, or if the \term{exponent marker} \f{e}
  248. (or \f{E}) is used, then
  249. % the precise format to be used
  250. % is not specified. When such a representation is read and
  251. % converted to an internal floating-point data value,
  252. the format specified
  253. by \varref{*read-default-float-format*} is used.
  254. \Seefigure\SyntaxForNumericTokens.
  255. %% 2.1.3 1
  256. An implementation may provide one or more kinds of \term{float}
  257. that collectively make up \thetype{float}.
  258. %% 2.1.3 8
  259. The letters \f{s}, \f{f}, \f{d}, and \f{l} (or their
  260. respective uppercase equivalents) explicitly specify the
  261. use of the \term{types} \typeref{short-float}, \typeref{single-float},
  262. \typeref{double-float}, and \typeref{long-float}, respectively.
  263. %% 2.1.3 9
  264. The internal format used for an external representation depends only
  265. on the \term{exponent marker}, and not on the number of decimal digits
  266. in the external representation.
  267. \Thenextfigure\ contains examples of notations for \term{floats}:
  268. \showtwo{Examples of Floating-point numbers}{
  269. \f{0.0} & ;Floating-point zero in default format \cr
  270. \f{0E0} & ;As input, this is also floating-point zero in default format. \cr
  271. & ;As output, this would appear as \f{0.0}. \cr
  272. \f{0e0} & ;As input, this is also floating-point zero in default format. \cr
  273. & ;As output, this would appear as \f{0.0}. \cr
  274. \f{-.0} & ;As input, this might be a zero or a minus zero, \cr
  275. & ; depending on whether the implementation supports \cr
  276. & ; a distinct minus zero. \cr
  277. & ;As output, \f{0.0} is zero and \f{-0.0} is minus zero. \cr
  278. \f{0.} & ;On input, the integer zero---\i{not} a floating-point number! \cr
  279. & ;Whether this appears as \f{0} or \f{0.} on output depends \cr
  280. & ;on \thevalueof{*print-radix*}. \cr
  281. \f{0.0s0} & ;A floating-point zero in short format \cr
  282. \f{0s0} & ;As input, this is a floating-point zero in short format. \cr
  283. & ;As output, such a zero would appear as \f{0.0s0} \cr
  284. & ; (or as \f{0.0} if \misc{short-float} was the default format). \cr
  285. \f{6.02E+23} & ;Avogadro's number, in default format \cr
  286. \f{602E+21} & ;Also Avogadro's number, in default format \cr
  287. }
  288. For information on how \term{floats} are printed,
  289. \seesection\PrintingFloats.
  290. \endsubsubsection%{Syntax of a Float}
  291. %!!! Barmar: This next is out of place because it isn't really syntax-related.}
  292. % KMP: Where to move it to? -kmp
  293. \beginsubsubsection{Syntax of a Complex}
  294. \DefineSection{SyntaxOfComplexes}
  295. A \term{complex} has a Cartesian structure,
  296. with a real part and an imaginary part each of which is a
  297. \issue{REAL-NUMBER-TYPE:X3J13-MAR-89}
  298. \term{real}.
  299. \endissue{REAL-NUMBER-TYPE:X3J13-MAR-89}
  300. The parts of a \term{complex} are not necessarily \term{floats}
  301. but both parts must be of the same \term{type}:
  302. \editornote{KMP: This is not the same as saying they must be the same type.
  303. Maybe we mean they are of the same `precision' or `format'?
  304. GLS had suggestions which are not yet merged.}%!!! 4-Jan-91
  305. either both are \term{rationals}, or both are of the same \term{float} \term{subtype}.
  306. When constructing a \term{complex}, if the specified parts are not the
  307. same \term{type}, the parts are converted to be the same \term{type}
  308. internally (\ie the \term{rational} part is converted to a \term{float}).
  309. An \term{object} of type \f{(complex rational)} is converted internally
  310. and represented thereafter as a \term{rational} if its imaginary part is an
  311. \term{integer} whose value is 0.
  312. For further information, \seesection\SharpsignC\ and \secref\PrintingComplexes.
  313. \endsubsubsection%{Syntax of a Complex}
  314. \endsubsection%{Constructing Numbers from Tokens}
  315. \beginsubsection{The Consing Dot}
  316. %% 22.1.2 13
  317. If a \term{token} consists solely of dots (with no escape characters),
  318. then an error \oftype{reader-error} is signaled,
  319. except in one circumstance:
  320. if the \term{token} is a single \term{dot}
  321. and appears in a situation where \term{dotted pair} notation permits a \term{dot},
  322. then it is accepted as part of such syntax and no error is signaled.
  323. \Seesection\LeftParen.
  324. \endsubsection%{The Consing Dot}
  325. \beginsubSection{Symbols as Tokens}
  326. \DefineSection{SymbolTokens}
  327. Any \term{token} that is not a \term{potential number},
  328. %next line added per Barmar:
  329. does not contain a \term{package marker},
  330. and does not consist entirely of dots
  331. will always be interpreted as a \term{symbol}.
  332. Any \term{token} that is a \term{potential number} but does not fit the
  333. number syntax is a reserved \term{token} and
  334. has an \term{implementation-dependent} interpretation.
  335. %% 22.1.2 14
  336. %% 11.3.0 7
  337. %% 2.3.0 4
  338. In all other cases, the \term{token} is construed to be the name of a \term{symbol}.
  339. Examples of the printed representation of \term{symbols} are in \thenextfigure.
  340. For presentational simplicity,
  341. these examples assume that
  342. the \term{readtable case} of the \term{current readtable} is \kwd{upcase}.
  343. %% 2.3.0 7
  344. \showtwo{Examples of the printed representation of symbols (Part 1 of 2)}{
  345. \f{FROBBOZ} & The \term{symbol} whose \term{name} is \f{FROBBOZ}. \cr
  346. \f{frobboz} & Another way to notate the same \term{symbol}. \cr
  347. \f{fRObBoz} & Yet another way to notate it. \cr
  348. \f{unwind-protect} & A \term{symbol} with a hyphen in its \term{name}. \cr
  349. \f{+\$} & The \term{symbol} named \f{+\$}. \cr
  350. \f{1+} & The \term{symbol} named \f{1+}. \cr
  351. \f{+1} & This is the \term{integer} \f{1},
  352. not a \term{symbol}. \cr
  353. \f{pascal\_style} & This \term{symbol} has an underscore
  354. in its \term{name}. \cr
  355. \f{file.rel.43} & This \term{symbol} has periods in its \term{name}. \cr
  356. \f{\\(} & The \term{symbol} whose \term{name} is \f{(}. \cr%))
  357. \f{\\+1} & The \term{symbol} whose \term{name} is \f{+1}. \cr
  358. \f{+\\1} & Also the \term{symbol} whose \term{name} is \f{+1}. \cr
  359. \f{\\frobboz} & The \term{symbol} whose \term{name} is \f{fROBBOZ}. \cr
  360. \f{3.14159265\\s0} & The \term{symbol} whose \term{name}
  361. is \f{3.14159265s0}. \cr
  362. \f{3.14159265\\S0} & A different \term{symbol},
  363. whose \term{name} is \f{3.14159265S0}. \cr
  364. \f{3.14159265s0} & A possible \term{short float}
  365. approximation to $\pi$. \cr
  366. }
  367. % This is sort of an artificial division, but addresses the fact that this table is pretty
  368. % big and makes for awkward-looking page break if the table is left all one piece.
  369. % -kmp 31-Jan-92
  370. \showtwo{Examples of the printed representation of symbols (Part 2 of 2)}{
  371. \f{APL\\\\360} & The \term{symbol} whose \term{name}
  372. is \f{APL\\360}. \cr
  373. \f{apl\\\\360} & Also the \term{symbol} whose \term{name}
  374. is \f{APL\\360}. \cr
  375. \f{\\(b{\hat}2\\)\\ -\\ 4*a\f{*c}} & The \term{name} is \f{(B{\hat}2) - 4*A*C}. \cr
  376. & Parentheses and two spaces in it. \cr
  377. \f{\\(\\b{\hat}2\\)\\ -\\4*\\a*\\c} & The \term{name} is \f{(b{\hat}2) - 4*a*c}. \cr
  378. & Letters explicitly lowercase. \cr
  379. \f{|"|} & The same as writing \f{\\"}. \cr
  380. \f{|(b{\hat}2) - 4*a*c|} & The \term{name} is \f{(b{\hat}2) - 4*a*c}. \cr
  381. \f{|frobboz|} & The \term{name} is \f{frobboz}, not \f{FROBBOZ}. \cr
  382. \f{|APL\\360|} & The \term{name} is \f{APL360}. \cr
  383. \f{|APL\\\\360|} & The \term{name} is \f{APL\\360}. \cr
  384. \f{|apl\\\\360|} & The \term{name} is \f{apl\\360}. \cr
  385. \f{|\\|\\||} & Same as \f{\\|\\|} ---the \term{name} is \f{||}. \cr
  386. \f{|(B{\hat}2) - 4*A*C|} & The \term{name} is \f{(B{\hat}2) - 4*A*C}. \cr
  387. & Parentheses and two spaces in it. \cr
  388. \f{|(b{\hat}2) - 4*a*c|} & The \term{name} is \f{(b{\hat}2) - 4*a*c}. \cr
  389. }
  390. %!!! Presumably this means "other than the code attribute." sigh... -kmp 25-Jan-92
  391. \issue{CHARACTER-PROPOSAL:2-1-1}
  392. In the process of parsing a \term{symbol},
  393. it is \term{implementation-dependent} which
  394. %\term{attributes} are removed from \term{symbol} \term{names}.
  395. %% Sandra didn't like the above wording. She suggested this:
  396. \term{implementation-defined} \term{attributes} are removed
  397. from the \term{characters} forming a \term{token} that represents a \term{symbol}.
  398. \endissue{CHARACTER-PROPOSAL:2-1-1}
  399. %% 11.3.0 2
  400. % When the \term{Lisp reader} has, by parsing, obtained a string of characters
  401. % %!!! RPG: "thought"? oh well.
  402. % thought to name a \term{symbol},
  403. % that name is looked up in the \term{current package}.
  404. %% Rewritten for RPG's sake:
  405. When parsing the syntax for a \term{symbol},
  406. the \term{Lisp reader} looks up the \term{name} of that \term{symbol}
  407. in the \term{current package}.
  408. This lookup may involve looking in other
  409. \term{packages} whose \term{external symbols}
  410. are inherited by the \term{current package}. If the name is found,
  411. the corresponding \term{symbol} is returned. If the name is not found
  412. (that is, there is no \term{symbol}
  413. of that name \term{accessible} in the \term{current package}),
  414. a new \term{symbol} is created and is placed in the \term{current package}
  415. as an \term{internal symbol}. The \term{current package} becomes the owner
  416. (\term{home package}) of the \term{symbol},
  417. and the \term{symbol} becomes interned in the \term{current package}.
  418. If the name is later read again while this same \term{package} is
  419. current, the same \term{symbol} will be found and returned.
  420. \endsubSection%{Symbols as Tokens}
  421. \beginsubSection{Valid Patterns for Tokens}
  422. The valid patterns for \term{tokens} are summarized in \thenextfigure.
  423. \showtwo{Valid patterns for tokens}{
  424. \f{\i{nnnnn}} & a \term{number} \cr
  425. \f{\i{xxxxx}} & a \term{symbol} in the \term{current package} \cr
  426. \f{:\i{xxxxx}} & a \term{symbol} in the \thepackage{keyword} \cr
  427. \f{\i{ppppp}:\i{xxxxx}} & an \term{external symbol}
  428. in the \i{ppppp} \term{package} \cr
  429. \f{\i{ppppp}::\i{xxxxx}} & a (possibly internal) \term{symbol}
  430. in the \i{ppppp} \term{package} \cr
  431. \f{:\i{nnnnn}} & undefined \cr
  432. \f{\i{ppppp}:\i{nnnnn}} & undefined \cr
  433. \f{\i{ppppp}::\i{nnnnn}} & undefined \cr
  434. \f{::\i{aaaaa}} & undefined \cr
  435. \f{\i{aaaaa}:} & undefined \cr
  436. \f{\i{aaaaa}:\i{aaaaa}:\i{aaaaa}} & undefined \cr
  437. }
  438. Note that \i{nnnnn} has number syntax,
  439. neither \i{xxxxx} nor \i{ppppp} has number syntax,
  440. and \i{aaaaa} has any syntax.
  441. %% 11.0.0 30
  442. A summary of rules concerning \term{package markers} follows.
  443. In each case, examples are offered to illustrate the case;
  444. for presentational simplicity, the examples assume that
  445. the \term{readtable case} of the \term{current readtable} is \kwd{upcase}.
  446. %% 22.1.2 15
  447. %% 11.0.0 33
  448. \beginlist
  449. \item{1.}
  450. If there is a single \term{package marker}, and it occurs at the beginning of the
  451. \term{token}, then the \term{token} is interpreted as a \term{symbol} in \thepackage{keyword}.
  452. It also sets the \funref{symbol-value} of the newly-created \term{symbol} to that
  453. same \term{symbol} so that the \term{symbol} will self-evaluate.
  454. For example,
  455. \f{:bar}, when read, interns \f{BAR} as an \term{external symbol} in \thepackage{keyword}.
  456. %% 22.1.2 16
  457. %% 11.0.0 31
  458. %% 11.0.0 29
  459. \item{2.}
  460. If there is a single \term{package marker} not at the beginning or end of the
  461. \term{token}, then it divides the \term{token} into two parts. The first part
  462. specifies a \term{package};
  463. the second part is the name of an \term{external symbol}
  464. available in that package.
  465. For example,
  466. \f{foo:bar}, when read, looks up \f{BAR} among the \term{external symbols} of
  467. the \term{package} named \f{FOO}.
  468. %\f{\#:bar}, when read, creates a new, \term{uninterned} \term{symbol}
  469. %named \f{BAR}.
  470. %\funref{import} and \funref{unintern} can create a \term{symbol}
  471. %that has no
  472. %recorded \term{home package},
  473. %but that in fact is \term{accessible} in some \term{package}.
  474. %The implementation
  475. %does not check for this pathological case, and such \term{symbols}
  476. %are printed preceded by \f{\#:}.
  477. %% 22.1.2 17
  478. %% 11.0.0 32
  479. %% 11.0.0 26
  480. \item{3.}
  481. If there are two adjacent \term{package markers} not at the beginning or end of the
  482. \term{token}, then they divide the \term{token} into two parts. The first part
  483. specifies a \term{package};
  484. the second part is the name of a \term{symbol} within
  485. that \term{package} (possibly an \term{internal symbol}).
  486. For example,
  487. \f{foo::bar}, when read, interns \f{BAR} in the \term{package} named \f{FOO}.
  488. %% 22.1.2 18
  489. \item{4.}
  490. If the \term{token} contains no \term{package markers},
  491. and does not have \term{potential number} syntax,
  492. then the entire \term{token} is the name of the \term{symbol}.
  493. The \term{symbol} is looked up in the \term{current package}.
  494. For example,
  495. \f{bar}, when read, interns \f{BAR} in the \term{current package}.
  496. %% 22.1.2 19
  497. %% 11.0.0 34
  498. \item{5.}
  499. The consequences are unspecified if any other pattern of \term{package markers}
  500. in a \term{token} is used.
  501. All other uses of \term{package markers} within names of \term{symbols}
  502. are not defined by this standard
  503. but are reserved for \term{implementation-dependent} use.
  504. \endlist
  505. %% 11.0.0 25
  506. For example,
  507. assuming the \term{readtable case} of the \term{current readtable} is \kwd{upcase},
  508. \f{editor:buffer} refers to the \term{external symbol}
  509. named \f{BUFFER} present in the \term{package} named \f{editor},
  510. regardless of whether there is a \term{symbol} named \f{BUFFER} in
  511. the \term{current package}. If there is no \term{package} named
  512. \f{editor}, or if no \term{symbol} named \f{BUFFER}
  513. is present in \f{editor}, or if \f{BUFFER} is not exported by
  514. \f{editor}, the reader signals
  515. a correctable error.
  516. %!!! Error type?
  517. If \f{editor::buffer} is seen, the effect is exactly the same as
  518. reading \f{buffer} with \thepackage{editor} being the \term{current package}.
  519. \endsubSection%{Valid Patterns for Tokens}
  520. \beginsubSection{Package System Consistency Rules}
  521. \DefineSection{PackageSysConsistencyRules}
  522. %% 11.0.0 14
  523. The following rules apply to the package system as long as
  524. \thevalueof{*package*} is not changed:
  525. %% 11.0.0 15
  526. \beginlist
  527. \itemitem{\b{Read-read consistency}}
  528. %!!! Is "same" meaning "string=" here?
  529. Reading the same \term{symbol} \term{name}
  530. % "same (eq)" => "\term{same}" for simplicity. -kmp 10-Apr-91
  531. always results in the \term{same} \term{symbol}.
  532. %% 11.0.0 16
  533. \itemitem{\b{Print-read consistency}}
  534. % "same (eq)" => "\term{same}" for simplicity. -kmp 10-Apr-91
  535. An \term{interned symbol} always prints as a sequence of characters that,
  536. when read back in, yields the \term{same} \term{symbol}.
  537. For information about how the \term{Lisp printer} treats \term{symbols},
  538. \seesection\PrintingSymbols.
  539. %% 11.0.0 17
  540. \itemitem{\b{Print-print consistency}}
  541. % "same (eq)" => "\term{same}" for simplicity. -kmp 10-Apr-91
  542. If two interned \term{symbols} are not the \term{same},
  543. then their printed representations will be different sequences of characters.
  544. \endlist
  545. %% 11.0.0 18
  546. These rules are true regardless of any implicit interning.
  547. As long as the \term{current package} is not changed,
  548. results are reproducible regardless of the order of \term{loading} files
  549. or the exact history of what \term{symbols} were typed in when.
  550. If \thevalueof{*package*} is changed and then changed back to the previous value,
  551. consistency is maintained.
  552. The rules can be violated by
  553. changing \thevalueof{*package*},
  554. forcing a change to \term{symbols}
  555. or to \term{packages}
  556. or to both
  557. by continuing from an error,
  558. or calling one of the following \term{functions}:
  559. \funref{unintern},
  560. \funref{unexport},
  561. \funref{shadow},
  562. \funref{shadowing-import},
  563. or \funref{unuse-package}.
  564. An inconsistency only applies if one of the restrictions is violated
  565. between two of the named \term{symbols}.
  566. \funref{shadow}, \funref{unexport}, \funref{unintern},
  567. and \funref{shadowing-import} can only affect the consistency of
  568. \term{symbols} with the same \term{names} (under \funref{string=})
  569. as the ones supplied as arguments.
  570. \endsubsection%{Package System Consistency Rules}