My various dotfiles

chap-23.texi 47KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456
  1. @node Reader, System Construction, Printer, Top
  2. @chapter Reader
  3. @menu
  4. * Reader Concepts::
  5. * Reader Dictionary::
  6. @end menu
  7. @node Reader Concepts, Reader Dictionary, Reader, Reader
  8. @section Reader Concepts
  9. @c including concept-reader
  10. @menu
  11. * Dynamic Control of the Lisp Reader::
  12. * Effect of Readtable Case on the Lisp Reader::
  13. * Argument Conventions of Some Reader Functions::
  14. @end menu
  15. @node Dynamic Control of the Lisp Reader, Effect of Readtable Case on the Lisp Reader, Reader Concepts, Reader Concepts
  16. @subsection Dynamic Control of the Lisp Reader
  17. Various aspects of the @i{Lisp reader} can be controlled dynamically.
  18. See @ref{Readtables} and @ref{Variables that affect the Lisp Reader}.
  19. @node Effect of Readtable Case on the Lisp Reader, Argument Conventions of Some Reader Functions, Dynamic Control of the Lisp Reader, Reader Concepts
  20. @subsection Effect of Readtable Case on the Lisp Reader
  21. The @i{readtable case} of the @i{current readtable} affects the @i{Lisp reader}
  22. in the following ways:
  23. @table @asis
  24. @item @t{:upcase}
  25. When the @i{readtable case} is @t{:upcase},
  26. unescaped constituent @i{characters} are converted to @i{uppercase},
  27. as specified in @ref{Reader Algorithm}.
  28. @item @t{:downcase}
  29. When the @i{readtable case} is @t{:downcase},
  30. unescaped constituent @i{characters} are converted to @i{lowercase}.
  31. @item @t{:preserve}
  32. When the @i{readtable case} is @t{:preserve},
  33. the case of all @i{characters} remains unchanged.
  34. @item @t{:invert}
  35. When the @i{readtable case} is @t{:invert},
  36. then if all of the unescaped letters in the extended token are of the same @i{case},
  37. those (unescaped) letters are converted to the opposite @i{case}.
  38. @end table
  39. @menu
  40. * Examples of Effect of Readtable Case on the Lisp Reader::
  41. @end menu
  42. @node Examples of Effect of Readtable Case on the Lisp Reader, , Effect of Readtable Case on the Lisp Reader, Effect of Readtable Case on the Lisp Reader
  43. @subsubsection Examples of Effect of Readtable Case on the Lisp Reader
  44. @example
  45. (defun test-readtable-case-reading ()
  46. (let ((*readtable* (copy-readtable nil)))
  47. (format t "READTABLE-CASE Input Symbol-name~
  48. ~
  49. ~
  50. (dolist (readtable-case '(:upcase :downcase :preserve :invert))
  51. (setf (readtable-case *readtable*) readtable-case)
  52. (dolist (input '("ZEBRA" "Zebra" "zebra"))
  53. (format t "~&:~A~16T~A~24T~A"
  54. (string-upcase readtable-case)
  55. input
  56. (symbol-name (read-from-string input)))))))
  57. @end example
  58. The output from @t{(test-readtable-case-reading)} should be as follows:
  59. @example
  60. READTABLE-CASE Input Symbol-name
  61. -------------------------------------
  62. :UPCASE ZEBRA ZEBRA
  63. :UPCASE Zebra ZEBRA
  64. :UPCASE zebra ZEBRA
  65. :DOWNCASE ZEBRA zebra
  66. :DOWNCASE Zebra zebra
  67. :DOWNCASE zebra zebra
  68. :PRESERVE ZEBRA ZEBRA
  69. :PRESERVE Zebra Zebra
  70. :PRESERVE zebra zebra
  71. :INVERT ZEBRA zebra
  72. :INVERT Zebra Zebra
  73. :INVERT zebra ZEBRA
  74. @end example
  75. @node Argument Conventions of Some Reader Functions, , Effect of Readtable Case on the Lisp Reader, Reader Concepts
  76. @subsection Argument Conventions of Some Reader Functions
  77. @menu
  78. * The EOF-ERROR-P argument::
  79. * The RECURSIVE-P argument::
  80. @end menu
  81. @node The EOF-ERROR-P argument, The RECURSIVE-P argument, Argument Conventions of Some Reader Functions, Argument Conventions of Some Reader Functions
  82. @subsubsection The EOF-ERROR-P argument
  83. @i{Eof-error-p} in input function calls
  84. controls what happens if input is from a file (or any other
  85. input source that has a definite end) and the end of the file is reached.
  86. If @i{eof-error-p} is @i{true} (the default),
  87. an error of @i{type} @b{end-of-file} is signaled
  88. at end of file. If it is @i{false}, then no error is signaled, and instead
  89. the function returns @i{eof-value}.
  90. Functions such as @b{read} that read the representation
  91. of an @i{object} rather than a single
  92. character always signals an error, regardless of @i{eof-error-p}, if
  93. the file ends in the middle of an object representation.
  94. For example, if a file does
  95. not contain enough right parentheses to balance the left parentheses in
  96. it, @b{read} signals an error. If a file ends in a
  97. @i{symbol} or a @i{number}
  98. immediately followed by end-of-file, @b{read} reads the
  99. @i{symbol} or
  100. @i{number}
  101. successfully and when called again will
  102. act according to @i{eof-error-p}.
  103. Similarly, the @i{function} @b{read-line}
  104. successfully reads the last line of a file even if that line
  105. is terminated by end-of-file rather than the newline character.
  106. Ignorable text, such as lines containing only @i{whitespace}_2 or comments,
  107. are not considered to begin an @i{object};
  108. if @b{read} begins to read an @i{expression} but sees only such
  109. ignorable text, it does not consider the file to end in the middle of an @i{object}.
  110. Thus an @i{eof-error-p} argument controls what happens
  111. when the file ends between @i{objects}.
  112. @node The RECURSIVE-P argument, , The EOF-ERROR-P argument, Argument Conventions of Some Reader Functions
  113. @subsubsection The RECURSIVE-P argument
  114. If @i{recursive-p} is supplied and not @b{nil}, it specifies that
  115. this function call is not an outermost call to @b{read} but an
  116. embedded call, typically from a @i{reader macro function}.
  117. It is important to distinguish such recursive calls for three reasons.
  118. @table @asis
  119. @item 1.
  120. An outermost call establishes the context within which the
  121. @t{#@i{n}=} and @t{#@i{n}#} syntax is scoped. Consider, for example,
  122. the expression
  123. @example
  124. (cons '#3=(p q r) '(x y . #3#))
  125. @end example
  126. If the @i{single-quote} @i{reader macro} were defined in this way:
  127. @example
  128. (set-macro-character #\' ;incorrect
  129. #'(lambda (stream char)
  130. (declare (ignore char))
  131. (list 'quote (read stream))))
  132. @end example
  133. then each call to the @i{single-quote} @i{reader macro function} would establish
  134. independent contexts for the scope of @b{read} information, including the scope of
  135. identifications between markers like ``@t{#3=}'' and ``@t{#3#}''. However, for
  136. this expression, the scope was clearly intended to be determined by the outer set
  137. of parentheses, so such a definition would be incorrect.
  138. The correct way to define the @i{single-quote}
  139. @i{reader macro} uses @i{recursive-p}:
  140. @example
  141. (set-macro-character #\' ;correct
  142. #'(lambda (stream char)
  143. (declare (ignore char))
  144. (list 'quote (read stream t nil t))))
  145. @end example
  146. @item 2.
  147. A recursive call does not alter whether the reading process
  148. is to preserve @i{whitespace}_2 or not (as determined by whether the
  149. outermost call was to @b{read} or @b{read-preserving-whitespace}).
  150. Suppose again that @i{single-quote}
  151. were to be defined as shown above in the incorrect definition.
  152. Then a call to @b{read-preserving-whitespace}
  153. that read the expression @t{'foo<@i{Space}>} would fail to preserve the space
  154. character following the symbol @t{foo} because the @i{single-quote}
  155. @i{reader macro function} calls @b{read},
  156. not @b{read-preserving-whitespace},
  157. to read the following expression (in this case @t{foo}).
  158. The correct definition, which passes the value @i{true} for @i{recursive-p}
  159. to @b{read}, allows the outermost call to determine
  160. whether @i{whitespace}_2 is preserved.
  161. @item 3.
  162. When end-of-file is encountered and the @i{eof-error-p} argument
  163. is not @b{nil}, the kind of error that is signaled may depend on the value
  164. of @i{recursive-p}. If @i{recursive-p}
  165. is @i{true}, then the end-of-file
  166. is deemed to have occurred within the middle of a printed representation;
  167. if @i{recursive-p} is @i{false}, then the end-of-file may be deemed to have
  168. occurred between @i{objects} rather than within the middle of one.
  169. @end table
  170. @c end of including concept-reader
  171. @node Reader Dictionary, , Reader Concepts, Reader
  172. @section Reader Dictionary
  173. @c including dict-reader
  174. @menu
  175. * readtable::
  176. * copy-readtable::
  177. * make-dispatch-macro-character::
  178. * read::
  179. * read-delimited-list::
  180. * read-from-string::
  181. * readtable-case::
  182. * readtablep::
  183. * set-dispatch-macro-character::
  184. * set-macro-character::
  185. * set-syntax-from-char::
  186. * with-standard-io-syntax::
  187. * *read-base*::
  188. * *read-default-float-format*::
  189. * *read-eval*::
  190. * *read-suppress*::
  191. * *readtable*::
  192. * reader-error::
  193. @end menu
  194. @node readtable, copy-readtable, Reader Dictionary, Reader Dictionary
  195. @subsection readtable [System Class]
  196. @subsubheading Class Precedence List::
  197. @b{readtable},
  198. @b{t}
  199. @subsubheading Description::
  200. A @i{readtable} maps @i{characters} into @i{syntax types} for
  201. the @i{Lisp reader}; see @ref{Syntax}.
  202. A @i{readtable} also
  203. contains associations between @i{macro characters}
  204. and their @i{reader macro functions},
  205. and records information about the case conversion rules
  206. to be used by the @i{Lisp reader} when parsing @i{symbols}.
  207. Each @i{simple} @i{character} must be representable in the @i{readtable}.
  208. It is @i{implementation-defined} whether @i{non-simple} @i{characters}
  209. can have syntax descriptions in the @i{readtable}.
  210. @subsubheading See Also::
  211. @ref{Readtables},
  212. @ref{Printing Other Objects}
  213. @node copy-readtable, make-dispatch-macro-character, readtable, Reader Dictionary
  214. @subsection copy-readtable [Function]
  215. @code{copy-readtable} @i{{&optional} from-readtable to-readtable} @result{} @i{readtable}
  216. @subsubheading Arguments and Values::
  217. @i{from-readtable}---a @i{readtable designator}.
  218. The default is the @i{current readtable}.
  219. @i{to-readtable}---a @i{readtable} or @b{nil}.
  220. The default is @b{nil}.
  221. @i{readtable}---the @i{to-readtable} if it is @i{non-nil},
  222. or else a @i{fresh} @i{readtable}.
  223. @subsubheading Description::
  224. @b{copy-readtable} copies @i{from-readtable}.
  225. If @i{to-readtable} is @b{nil}, a new @i{readtable} is created and returned.
  226. Otherwise the @i{readtable} specified by @i{to-readtable} is modified and returned.
  227. @b{copy-readtable} copies the setting of @b{readtable-case}.
  228. @subsubheading Examples::
  229. @example
  230. (setq zvar 123) @result{} 123
  231. (set-syntax-from-char #\z #\' (setq table2 (copy-readtable))) @result{} T
  232. zvar @result{} 123
  233. (copy-readtable table2 *readtable*) @result{} #<READTABLE 614000277>
  234. zvar @result{} VAR
  235. (setq *readtable* (copy-readtable)) @result{} #<READTABLE 46210223>
  236. zvar @result{} VAR
  237. (setq *readtable* (copy-readtable nil)) @result{} #<READTABLE 46302670>
  238. zvar @result{} 123
  239. @end example
  240. @subsubheading See Also::
  241. @b{readtable},
  242. @ref{readtable}
  243. @subsubheading Notes::
  244. @example
  245. (setq *readtable* (copy-readtable nil))
  246. @end example
  247. restores the input syntax to standard @r{Common Lisp} syntax, even if
  248. the @i{initial readtable} has been clobbered
  249. (assuming it is not so badly clobbered that you cannot type in the above expression).
  250. On the other hand,
  251. @example
  252. (setq *readtable* (copy-readtable))
  253. @end example
  254. replaces the current @i{readtable} with a copy of itself.
  255. This is useful if you want to save a copy of a readtable for later use,
  256. protected from alteration in the meantime. It is also useful if you want to
  257. locally bind the readtable to a copy of itself, as in:
  258. @example
  259. (let ((*readtable* (copy-readtable))) ...)
  260. @end example
  261. @node make-dispatch-macro-character, read, copy-readtable, Reader Dictionary
  262. @subsection make-dispatch-macro-character [Function]
  263. @code{make-dispatch-macro-character} @i{char {&optional} non-terminating-p readtable} @result{} @i{@b{t}}
  264. @subsubheading Arguments and Values::
  265. @i{char}---a @i{character}.
  266. @i{non-terminating-p}---a @i{generalized boolean}.
  267. The default is @i{false}.
  268. @i{readtable}---a @i{readtable}.
  269. The default is the @i{current readtable}.
  270. @subsubheading Description::
  271. @b{make-dispatch-macro-character} makes @i{char}
  272. be a @i{dispatching macro character} in @i{readtable}.
  273. Initially, every @i{character} in the dispatch table
  274. associated with the @i{char} has an associated function
  275. that signals an error of @i{type} @b{reader-error}.
  276. If @i{non-terminating-p} is @i{true},
  277. the @i{dispatching macro character}
  278. is made a @i{non-terminating} @i{macro character};
  279. if @i{non-terminating-p} is @i{false},
  280. the @i{dispatching macro character}
  281. is made a @i{terminating} @i{macro character}.
  282. @subsubheading Examples::
  283. @example
  284. (get-macro-character #\@{) @result{} NIL, @i{false}
  285. (make-dispatch-macro-character #\@{) @result{} T
  286. (not (get-macro-character #\@{)) @result{} @i{false}
  287. @end example
  288. The @i{readtable} is altered.
  289. @subsubheading See Also::
  290. @ref{readtable}
  291. ,
  292. @ref{set-dispatch-macro-character; get-dispatch-macro-character}
  293. @node read, read-delimited-list, make-dispatch-macro-character, Reader Dictionary
  294. @subsection read, read-preserving-whitespace [Function]
  295. @code{read} @i{{&optional} input-stream eof-error-p eof-value recursive-p} @result{} @i{object}
  296. @code{read-preserving-whitespace} @i{{&optional} input-stream eof-error-p
  297. eof-value recursive-p}@*
  298. @result{} @i{object}
  299. @subsubheading Arguments and Values::
  300. @i{input-stream}---an @i{input} @i{stream designator}.
  301. @i{eof-error-p}---a @i{generalized boolean}.
  302. The default is @i{true}.
  303. @i{eof-value}---an @i{object}.
  304. The default is @b{nil}.
  305. @i{recursive-p}---a @i{generalized boolean}.
  306. The default is @i{false}.
  307. @i{object}---an @i{object} (parsed by the @i{Lisp reader})
  308. or the @i{eof-value}.
  309. @subsubheading Description::
  310. @b{read} parses the printed representation of an @i{object}
  311. from @i{input-stream} and builds such an @i{object}.
  312. @b{read-preserving-whitespace} is like @b{read} but preserves
  313. any @i{whitespace}_2 @i{character}
  314. that delimits the printed representation of the @i{object}.
  315. @b{read-preserving-whitespace} is exactly like @b{read}
  316. when the @i{recursive-p} @i{argument} to @b{read-preserving-whitespace}
  317. is @i{true}.
  318. When @b{*read-suppress*} is @i{false},
  319. @b{read} throws away the delimiting @i{character} required by
  320. certain printed representations if it is a
  321. @i{whitespace}_2 @i{character};
  322. but @b{read} preserves the character
  323. (using @b{unread-char}) if it is
  324. syntactically meaningful, because it could be the start of the next expression.
  325. If a file ends in a @i{symbol} or a @i{number}
  326. immediately followed by an @i{end of file}_1,
  327. @b{read} reads the @i{symbol} or @i{number} successfully;
  328. when called again, it sees the @i{end of file}_1 and
  329. only then acts according to @i{eof-error-p}.
  330. If a file contains ignorable text at the end, such
  331. as blank lines and comments, @b{read}
  332. does not consider it to end in the
  333. middle of an @i{object}.
  334. If @i{recursive-p} is @i{true}, the call to @b{read} is
  335. expected to be made
  336. from within some function that itself
  337. has been called from @b{read} or from a similar input function, rather
  338. than from the top level.
  339. Both functions return the @i{object} read from @i{input-stream}.
  340. @i{Eof-value} is returned if @i{eof-error-p} is @i{false} and end of file
  341. is reached before the beginning of an @i{object}.
  342. @subsubheading Examples::
  343. @example
  344. (read)
  345. @t{ |> } @b{|>>}@t{'a}@b{<<|}
  346. @result{} (QUOTE A)
  347. (with-input-from-string (is " ") (read is nil 'the-end)) @result{} THE-END
  348. (defun skip-then-read-char (s c n)
  349. (if (char= c #\@{) (read s t nil t) (read-preserving-whitespace s))
  350. (read-char-no-hang s)) @result{} SKIP-THEN-READ-CHAR
  351. (let ((*readtable* (copy-readtable nil)))
  352. (set-dispatch-macro-character #\# #\@{ #'skip-then-read-char)
  353. (set-dispatch-macro-character #\# #\@} #'skip-then-read-char)
  354. (with-input-from-string (is "#@{123 x #@}123 y")
  355. (format t "~S ~S" (read is) (read is)))) @result{} #\x, #\Space, NIL
  356. @end example
  357. As an example, consider this @i{reader macro} definition:
  358. @example
  359. (defun slash-reader (stream char)
  360. (declare (ignore char))
  361. `(path . ,(loop for dir = (read-preserving-whitespace stream t nil t)
  362. then (progn (read-char stream t nil t)
  363. (read-preserving-whitespace stream t nil t))
  364. collect dir
  365. while (eql (peek-char nil stream nil nil t) #\/))))
  366. (set-macro-character #\/ #'slash-reader)
  367. @end example
  368. Consider now calling @b{read} on this expression:
  369. @example
  370. (zyedh /usr/games/zork /usr/games/boggle)
  371. @end example
  372. The @t{/} macro reads objects separated by more @t{/} characters;
  373. thus @t{/usr/games/zork} is intended to read as @t{(path usr games zork)}.
  374. The entire example expression should therefore be read as
  375. @example
  376. (zyedh (path usr games zork) (path usr games boggle))
  377. @end example
  378. However, if @b{read} had been used instead of
  379. @b{read-preserving-whitespace}, then after the reading of the symbol
  380. @t{zork}, the following space would be discarded; the next call
  381. to @b{peek-char} would see the following @t{/}, and the loop would
  382. continue, producing this interpretation:
  383. @example
  384. (zyedh (path usr games zork usr games boggle))
  385. @end example
  386. There are times when @i{whitespace}_2 should be discarded.
  387. If a command interpreter takes single-character commands,
  388. but occasionally reads an @i{object} then if the @i{whitespace}_2
  389. after a @i{symbol}
  390. is not discarded it might be interpreted as a command
  391. some time later after the @i{symbol} had been read.
  392. @subsubheading Affected By::
  393. @b{*standard-input*},
  394. @b{*terminal-io*},
  395. @b{*readtable*},
  396. @b{*read-default-float-format*},
  397. @b{*read-base*},
  398. @b{*read-suppress*},
  399. @b{*package*},
  400. @b{*read-eval*}.
  401. @subsubheading Exceptional Situations::
  402. @b{read} signals an error of @i{type} @b{end-of-file},
  403. regardless of @i{eof-error-p}, if
  404. the file ends in the middle of an @i{object} representation.
  405. For example, if a file does
  406. not contain enough right parentheses to balance the left parentheses in
  407. it, @b{read} signals an error.
  408. This is detected when @b{read} or @b{read-preserving-whitespace}
  409. is called with @i{recursive-p} and @i{eof-error-p} @i{non-nil},
  410. and end-of-file is reached before the beginning of an @i{object}.
  411. If @i{eof-error-p} is @i{true}, an error of @i{type} @b{end-of-file}
  412. is signaled at the end of file.
  413. @subsubheading See Also::
  414. @ref{peek-char}
  415. ,
  416. @ref{read-char}
  417. ,
  418. @ref{unread-char}
  419. ,
  420. @ref{read-from-string}
  421. ,
  422. @ref{read-delimited-list}
  423. ,
  424. @ref{parse-integer}
  425. ,
  426. {@ref{Syntax}},
  427. {@ref{Reader Concepts}}
  428. @node read-delimited-list, read-from-string, read, Reader Dictionary
  429. @subsection read-delimited-list [Function]
  430. @code{read-delimited-list} @i{char {&optional} input-stream recursive-p} @result{} @i{list}
  431. @subsubheading Arguments and Values::
  432. @i{char}---a @i{character}.
  433. @i{input-stream}---an @i{input} @i{stream designator}.
  434. The default is @i{standard input}.
  435. @i{recursive-p}---a @i{generalized boolean}.
  436. The default is @i{false}.
  437. @i{list}---a @i{list} of the @i{objects} read.
  438. @subsubheading Description::
  439. @b{read-delimited-list} reads @i{objects} from @i{input-stream}
  440. until the next character after an @i{object}'s
  441. representation (ignoring @i{whitespace}_2 characters and comments) is @i{char}.
  442. @b{read-delimited-list} looks ahead at each step
  443. for the next non-@i{whitespace}_2 @i{character}
  444. and peeks at it as if with @b{peek-char}.
  445. If it is @i{char},
  446. then the @i{character} is consumed and the @i{list} of @i{objects} is returned.
  447. If it is a @i{constituent} or @i{escape} @i{character},
  448. then @b{read} is used to read an @i{object},
  449. which is added to the end of the @i{list}.
  450. If it is a @i{macro character},
  451. its @i{reader macro function} is called;
  452. if the function returns a @i{value},
  453. that @i{value} is added to the @i{list}.
  454. The peek-ahead process is then repeated.
  455. If @i{recursive-p} is @i{true},
  456. this call is expected to be embedded in a higher-level call to @b{read}
  457. or a similar function.
  458. It is an error to reach end-of-file during the operation of
  459. @b{read-delimited-list}.
  460. The consequences are undefined
  461. if @i{char} has a @i{syntax type} of @i{whitespace}_2
  462. in the @i{current readtable}.
  463. @subsubheading Examples::
  464. @example
  465. (read-delimited-list #\{]}) 1 2 3 4 5 6 {]}
  466. @result{} (1 2 3 4 5 6)
  467. @end example
  468. Suppose you wanted @t{#@{{@i{a}} @i{b} @i{c} ... @i{z}@}}
  469. to read as a list of all pairs of the elements @i{a}, @i{b}, @i{c},
  470. ..., @i{z}, for example.
  471. @example
  472. #@{p q z a@} reads as ((p q) (p z) (p a) (q z) (q a) (z a))
  473. @end example
  474. This can be done by specifying a macro-character definition for @t{#@{}
  475. that does two things: reads in all the items up to the @t{@}},
  476. and constructs the pairs. @b{read-delimited-list} performs
  477. the first task.
  478. @example
  479. (defun |#@{-reader| (stream char arg)
  480. (declare (ignore char arg))
  481. (mapcon #'(lambda (x)
  482. (mapcar #'(lambda (y) (list (car x) y)) (cdr x)))
  483. (read-delimited-list #\@} stream t))) @result{} |#@{-reader|
  484. (set-dispatch-macro-character #\# #\@{ #'|#@{-reader|) @result{} T
  485. (set-macro-character #\@} (get-macro-character #\) @b{nil}))
  486. @end example
  487. Note that @i{true} is supplied for the @i{recursive-p} argument.
  488. It is necessary here to give a definition to the character @t{@}} as
  489. well to prevent it from being a constituent.
  490. If the line
  491. @example
  492. (set-macro-character #\@} (get-macro-character #\) @b{nil}))
  493. @end example
  494. shown above were not included, then the @t{@}} in
  495. @example
  496. #@{ p q z a@}
  497. @end example
  498. would be considered a constituent character, part of the symbol named
  499. @t{a@}}. This could be corrected by putting a space before
  500. the @t{@}}, but it is better to call
  501. @b{set-macro-character}.
  502. Giving @t{@}} the same
  503. definition as the standard definition of the character @t{)} has the
  504. twin benefit of making it terminate tokens for use with
  505. @b{read-delimited-list} and also making it invalid for use in any
  506. other context. Attempting to read a stray @t{@}} will signal an error.
  507. @subsubheading Affected By::
  508. @b{*standard-input*},
  509. @b{*readtable*},
  510. @b{*terminal-io*}.
  511. @subsubheading See Also::
  512. @ref{read; read-preserving-whitespace}
  513. ,
  514. @ref{peek-char}
  515. ,
  516. @ref{read-char}
  517. ,
  518. @ref{unread-char}
  519. .
  520. @subsubheading Notes::
  521. @b{read-delimited-list} is intended for use in implementing @i{reader macros}.
  522. Usually it is desirable for @i{char} to be a @i{terminating} @i{macro character}
  523. so that it can be used to delimit tokens; however, @b{read-delimited-list}
  524. makes no attempt to alter the syntax specified for @i{char} by the current
  525. readtable. The caller must make any necessary changes to the readtable syntax
  526. explicitly.
  527. @node read-from-string, readtable-case, read-delimited-list, Reader Dictionary
  528. @subsection read-from-string [Function]
  529. @code{read-from-string} @i{string {&optional} eof-error-p eof-value
  530. {&key} start end preserve-whitespace}@*
  531. @result{} @i{object, position}
  532. @subsubheading Arguments and Values::
  533. @i{string}---a @i{string}.
  534. @i{eof-error-p}---a @i{generalized boolean}.
  535. The default is @i{true}.
  536. @i{eof-value}---an @i{object}.
  537. The default is @b{nil}.
  538. @i{start}, @i{end}---@i{bounding index designators} of @i{string}.
  539. The defaults for @i{start} and @i{end} are @t{0} and @b{nil}, respectively.
  540. @i{preserve-whitespace}---a @i{generalized boolean}.
  541. The default is @i{false}.
  542. @i{object}---an @i{object} (parsed by the @i{Lisp reader})
  543. or the @i{eof-value}.
  544. @i{position}---an @i{integer} greater than or equal to zero,
  545. and less than or equal to
  546. one more than the @i{length} of the @i{string}.
  547. @subsubheading Description::
  548. Parses the printed representation of an @i{object}
  549. from the subsequence of @i{string} @i{bounded} by @i{start} and @i{end},
  550. as if @b{read} had been called on an @i{input} @i{stream}
  551. containing those same @i{characters}.
  552. If @i{preserve-whitespace} is @i{true},
  553. the operation will preserve @i{whitespace}_2
  554. as @b{read-preserving-whitespace} would do.
  555. If an @i{object} is successfully parsed, the @i{primary value}, @i{object},
  556. is the @i{object} that was parsed.
  557. If @i{eof-error-p} is @i{false} and if the end of the @i{substring} is reached,
  558. @i{eof-value} is returned.
  559. The @i{secondary value}, @i{position}, is the index of the first @i{character}
  560. in the @i{bounded} @i{string} that was not read.
  561. The @i{position} may depend upon the value of @i{preserve-whitespace}.
  562. If the entire @i{string} was read,
  563. the @i{position} returned is either the @i{length} of the @i{string}
  564. or one greater than the @i{length} of the @i{string}.
  565. @subsubheading Examples::
  566. @example
  567. (read-from-string " 1 3 5" t nil :start 2) @result{} 3, 5
  568. (read-from-string "(a b c)") @result{} (A B C), 7
  569. @end example
  570. @subsubheading Exceptional Situations::
  571. If the end of the supplied substring
  572. occurs before an @i{object} can be read, an
  573. error is signaled if @i{eof-error-p} is @i{true}.
  574. An error is signaled if the end of the @i{substring} occurs
  575. in the middle of an incomplete @i{object}.
  576. @subsubheading See Also::
  577. @ref{read; read-preserving-whitespace}
  578. ,
  579. @b{read-preserving-whitespace}
  580. @subsubheading Notes::
  581. The reason that @i{position} is allowed to be beyond the
  582. @i{length} of the @i{string} is to permit (but not require)
  583. the @i{implementation} to work by simulating the effect of a
  584. trailing delimiter at the end of the @i{bounded} @i{string}.
  585. When @i{preserve-whitespace} is @i{true},
  586. the @i{position} might count the simulated delimiter.
  587. @node readtable-case, readtablep, read-from-string, Reader Dictionary
  588. @subsection readtable-case [Accessor]
  589. @code{readtable-case} @i{readtable} @result{} @i{mode}
  590. (setf (@code{ readtable-case} @i{readtable}) mode)@*
  591. @subsubheading Arguments and Values::
  592. @i{readtable}---a @i{readtable}.
  593. @i{mode}---a @i{case sensitivity mode}.
  594. @subsubheading Description::
  595. @i{Accesses} the @i{readtable case} of @i{readtable},
  596. which affects the way in which the @i{Lisp Reader} reads @i{symbols}
  597. and the way in which the @i{Lisp Printer} writes @i{symbols}.
  598. @subsubheading Examples::
  599. See @ref{Examples of Effect of Readtable Case on the Lisp Reader} and @ref{Examples of Effect of Readtable Case on the Lisp Printer}.
  600. @subsubheading Exceptional Situations::
  601. Should signal an error of @i{type} @b{type-error}
  602. if @i{readtable} is not a @i{readtable}.
  603. Should signal an error of @i{type} @b{type-error}
  604. if @i{mode} is not a @i{case sensitivity mode}.
  605. @subsubheading See Also::
  606. @ref{readtable}
  607. ,
  608. @b{*print-escape*},
  609. @ref{Reader Algorithm},
  610. @ref{Effect of Readtable Case on the Lisp Reader},
  611. @ref{Effect of Readtable Case on the Lisp Printer}
  612. @subsubheading Notes::
  613. @b{copy-readtable} copies the @i{readtable case} of the @i{readtable}.
  614. @node readtablep, set-dispatch-macro-character, readtable-case, Reader Dictionary
  615. @subsection readtablep [Function]
  616. @code{readtablep} @i{object} @result{} @i{generalized-boolean}
  617. @subsubheading Arguments and Values::
  618. @i{object}---an @i{object}.
  619. @i{generalized-boolean}---a @i{generalized boolean}.
  620. @subsubheading Description::
  621. Returns @i{true} if @i{object} is of @i{type} @b{readtable};
  622. otherwise, returns @i{false}.
  623. @subsubheading Examples::
  624. @example
  625. (readtablep *readtable*) @result{} @i{true}
  626. (readtablep (copy-readtable)) @result{} @i{true}
  627. (readtablep '*readtable*) @result{} @i{false}
  628. @end example
  629. @subsubheading Notes::
  630. @example
  631. (readtablep @i{object}) @equiv{} (typep @i{object} 'readtable)
  632. @end example
  633. @node set-dispatch-macro-character, set-macro-character, readtablep, Reader Dictionary
  634. @subsection set-dispatch-macro-character, get-dispatch-macro-character
  635. @flushright
  636. @i{[Function]}
  637. @end flushright
  638. @code{get-dispatch-macro-character} @i{disp-char sub-char {&optional} readtable} @result{} @i{function}
  639. @code{set-dispatch-macro-character} @i{disp-char sub-char new-function {&optional} readtable} @result{} @i{@b{t}}
  640. @subsubheading Arguments and Values::
  641. @i{disp-char}---a @i{character}.
  642. @i{sub-char}---a @i{character}.
  643. @i{readtable}---a @i{readtable designator}.
  644. The default is the @i{current readtable}.
  645. @i{function}---a @i{function designator} or @b{nil}.
  646. @i{new-function}---a @i{function designator}.
  647. @subsubheading Description::
  648. @b{set-dispatch-macro-character} causes @i{new-function} to be called
  649. when @i{disp-char} followed by @i{sub-char} is read.
  650. If @i{sub-char} is a lowercase letter,
  651. it is converted to its uppercase equivalent.
  652. It is an error if @i{sub-char} is one of the ten decimal digits.
  653. @b{set-dispatch-macro-character} installs a @i{new-function} to be called
  654. when a particular @i{dispatching macro character} pair is read.
  655. @i{New-function} is installed as the dispatch function to be
  656. called when @i{readtable} is in use and when @i{disp-char} is followed by
  657. @i{sub-char}.
  658. For more information about how the @i{new-function} is invoked,
  659. see @ref{Macro Characters}.
  660. @b{get-dispatch-macro-character} retrieves
  661. the dispatch function associated with @i{disp-char} and @i{sub-char}
  662. in @i{readtable}.
  663. @b{get-dispatch-macro-character} returns the macro-character function
  664. for @i{sub-char} under @i{disp-char}, or @b{nil} if there is no
  665. function associated with @i{sub-char}.
  666. If @i{sub-char} is a decimal digit, @b{get-dispatch-macro-character}
  667. returns @b{nil}.
  668. @subsubheading Examples::
  669. @example
  670. (get-dispatch-macro-character #\# #\@{) @result{} NIL
  671. (set-dispatch-macro-character #\# #\@{ ;dispatch on #@{
  672. #'(lambda(s c n)
  673. (let ((list (read s nil (values) t))) ;list is object after #n@{
  674. (when (consp list) ;return nth element of list
  675. (unless (and n (< 0 n (length list))) (setq n 0))
  676. (setq list (nth n list)))
  677. list))) @result{} T
  678. #@{(1 2 3 4) @result{} 1
  679. #3@{(0 1 2 3) @result{} 3
  680. #@{123 @result{} 123
  681. @end example
  682. If it is desired that @t{#$@i{foo}} :
  683. as if it were @t{(dollars @i{foo})}.
  684. @example
  685. (defun |#$-reader| (stream subchar arg)
  686. (declare (ignore subchar arg))
  687. (list 'dollars (read stream t nil t))) @result{} |#$-reader|
  688. (set-dispatch-macro-character #\# #\$ #'|#$-reader|) @result{} T
  689. @end example
  690. @subsubheading See Also::
  691. @ref{Macro Characters}
  692. @subsubheading Side Effects::
  693. The @i{readtable} is modified.
  694. @subsubheading Affected By::
  695. @b{*readtable*}.
  696. @subsubheading Exceptional Situations::
  697. For either function, an error is signaled if @i{disp-char} is not
  698. a @i{dispatching macro character} in @i{readtable}.
  699. @subsubheading See Also::
  700. @ref{readtable}
  701. @subsubheading Notes::
  702. It is necessary
  703. to use @b{make-dispatch-macro-character} to set up the
  704. dispatch character before specifying its sub-characters.
  705. @node set-macro-character, set-syntax-from-char, set-dispatch-macro-character, Reader Dictionary
  706. @subsection set-macro-character, get-macro-character [Function]
  707. @code{get-macro-character} @i{char {&optional} readtable} @result{} @i{function, non-terminating-p}
  708. @code{set-macro-character} @i{char new-function {&optional} non-terminating-p readtable} @result{} @i{@b{t}}
  709. @subsubheading Arguments and Values::
  710. @i{char}---a @i{character}.
  711. @i{non-terminating-p}---a @i{generalized boolean}.
  712. The default is @i{false}.
  713. @i{readtable}---a @i{readtable designator}.
  714. The default is the @i{current readtable}.
  715. @i{function}---@b{nil},
  716. or a @i{designator} for a @i{function} of two @i{arguments}.
  717. @i{new-function}---a @i{function designator}.
  718. @subsubheading Description::
  719. @b{get-macro-character} returns as its @i{primary value}, @i{function},
  720. the @i{reader macro function} associated with @i{char} in @i{readtable} (if any),
  721. or else @b{nil} if @i{char} is not a @i{macro character} in @i{readtable}.
  722. The @i{secondary value}, @i{non-terminating-p}, is @i{true}
  723. if @i{char} is a @i{non-terminating} @i{macro character};
  724. otherwise, it is @i{false}.
  725. @b{set-macro-character} causes @i{char} to be a @i{macro character}
  726. associated with the @i{reader macro function} @i{new-function}
  727. (or the @i{designator} for @i{new-function}) in @i{readtable}.
  728. If @i{non-terminating-p} is @i{true},
  729. @i{char} becomes a @i{non-terminating} @i{macro character};
  730. otherwise it becomes a @i{terminating} @i{macro character}.
  731. @subsubheading Examples::
  732. @example
  733. (get-macro-character #\@{) @result{} NIL, @i{false}
  734. (not (get-macro-character #\;)) @result{} @i{false}
  735. @end example
  736. The following is a possible definition for the @i{single-quote} @i{reader macro}
  737. in @i{standard syntax}:
  738. @example
  739. (defun single-quote-reader (stream char)
  740. (declare (ignore char))
  741. (list 'quote (read stream t nil t))) @result{} SINGLE-QUOTE-READER
  742. (set-macro-character #\' #'single-quote-reader) @result{} T
  743. @end example
  744. Here @t{single-quote-reader} reads an @i{object} following the @i{single-quote}
  745. and returns a @i{list} of @b{quote} and that @i{object}.
  746. The @i{char} argument is ignored.
  747. The following is a possible definition for the @i{semicolon} @i{reader macro}
  748. in @i{standard syntax}:
  749. @example
  750. (defun semicolon-reader (stream char)
  751. (declare (ignore char))
  752. ;; First swallow the rest of the current input line.
  753. ;; End-of-file is acceptable for terminating the comment.
  754. (do () ((char= (read-char stream nil #\Newline t) #\Newline)))
  755. ;; Return zero values.
  756. (values)) @result{} SEMICOLON-READER
  757. (set-macro-character #\; #'semicolon-reader) @result{} T
  758. @end example
  759. @subsubheading Side Effects::
  760. The @i{readtable} is modified.
  761. @subsubheading See Also::
  762. @ref{readtable}
  763. @node set-syntax-from-char, with-standard-io-syntax, set-macro-character, Reader Dictionary
  764. @subsection set-syntax-from-char [Function]
  765. @code{set-syntax-from-char} @i{to-char from-char {&optional} to-readtable from-readtable} @result{} @i{@b{t}}
  766. @subsubheading Arguments and Values::
  767. @i{to-char}---a @i{character}.
  768. @i{from-char}---a @i{character}.
  769. @i{to-readtable}---a @i{readtable}.
  770. The default is the @i{current readtable}.
  771. @i{from-readtable}---a @i{readtable designator}.
  772. The default is the @i{standard readtable}.
  773. @subsubheading Description::
  774. @b{set-syntax-from-char} makes
  775. the syntax of @i{to-char} in @i{to-readtable} be the same as
  776. the syntax of @i{from-char} in @i{from-readtable}.
  777. @b{set-syntax-from-char} copies the @i{syntax types} of @i{from-char}.
  778. If @i{from-char} is a @i{macro character},
  779. its @i{reader macro function} is copied also.
  780. If the character is a @i{dispatching macro character},
  781. its entire dispatch table of @i{reader macro functions} is copied.
  782. The @i{constituent traits} of @i{from-char} are not copied.
  783. A macro definition from a character such as
  784. @t{"} can be copied to another character; the standard definition for @t{"}
  785. looks for another character that is the same as the character that
  786. invoked it. The definition of @t{(} can not be meaningfully copied
  787. to @t{@{}, on the other hand.
  788. The result is that @i{lists} are of the form
  789. @t{@{a b c)}, not @t{@{a b c@}},
  790. because the definition
  791. always looks for a closing parenthesis, not a closing brace.
  792. @subsubheading Examples::
  793. @example
  794. (set-syntax-from-char #\7 #\;) @result{} T
  795. 123579 @result{} 1235
  796. @end example
  797. @subsubheading Side Effects::
  798. The @i{to-readtable} is modified.
  799. @subsubheading Affected By::
  800. The existing values in the @i{from-readtable}.
  801. @subsubheading See Also::
  802. @ref{set-macro-character; get-macro-character}
  803. ,
  804. @ref{make-dispatch-macro-character}
  805. ,
  806. @ref{Character Syntax Types}
  807. @subsubheading Notes::
  808. The @i{constituent traits} of a @i{character} are ``hard wired''
  809. into the parser for extended @i{tokens}. For example, if the definition
  810. of @t{S} is copied to @t{*}, then @t{*} will become a @i{constituent}
  811. that is @i{alphabetic}_2 but that cannot be used as a
  812. @i{short float} @i{exponent marker}.
  813. For further information, see @ref{Constituent Traits}.
  814. @node with-standard-io-syntax, *read-base*, set-syntax-from-char, Reader Dictionary
  815. @subsection with-standard-io-syntax [Macro]
  816. @code{with-standard-io-syntax} @i{@{@i{form}@}{*}} @result{} @i{@{@i{result}@}{*}}
  817. @subsubheading Arguments and Values::
  818. @i{forms}---an @i{implicit progn}.
  819. @i{results}---the @i{values} returned by the @i{forms}.
  820. @subsubheading Description::
  821. Within the dynamic extent of the body of @i{forms}, all reader/printer control
  822. variables, including any @i{implementation-defined} ones not specified by
  823. this standard, are bound to values that produce standard read/print
  824. behavior. The values for the variables specified by this standard are listed in
  825. Figure 23--1.
  826. [Reviewer Note by Barrett: *print-pprint-dispatch* should probably be mentioned here, too.]
  827. @group
  828. @noindent
  829. @w{ Variable Value }
  830. @w{ @b{*package*} The @t{CL-USER} @i{package} }
  831. @w{ @b{*print-array*} @b{t} }
  832. @w{ @b{*print-base*} @t{10} }
  833. @w{ @b{*print-case*} @t{:upcase} }
  834. @w{ @b{*print-circle*} @b{nil} }
  835. @w{ @b{*print-escape*} @b{t} }
  836. @w{ @b{*print-gensym*} @b{t} }
  837. @w{ @b{*print-length*} @b{nil} }
  838. @w{ @b{*print-level*} @b{nil} }
  839. @w{ @b{*print-lines*} @b{nil} }
  840. @w{ @b{*print-miser-width*} @b{nil} }
  841. @w{ @b{*print-pprint-dispatch*} The @i{standard pprint dispatch table} }
  842. @w{ @b{*print-pretty*} @b{nil} }
  843. @w{ @b{*print-radix*} @b{nil} }
  844. @w{ @b{*print-readably*} @b{t} }
  845. @w{ @b{*print-right-margin*} @b{nil} }
  846. @w{ @b{*read-base*} @t{10} }
  847. @w{ @b{*read-default-float-format*} @b{single-float} }
  848. @w{ @b{*read-eval*} @b{t} }
  849. @w{ @b{*read-suppress*} @b{nil} }
  850. @w{ @b{*readtable*} The @i{standard readtable} }
  851. @noindent
  852. @w{ Figure 23--1: Values of standard control variables }
  853. @end group
  854. @subsubheading Examples::
  855. @example
  856. (with-open-file (file pathname :direction :output)
  857. (with-standard-io-syntax
  858. (print data file)))
  859. ;;; ... Later, in another Lisp:
  860. (with-open-file (file pathname :direction :input)
  861. (with-standard-io-syntax
  862. (setq data (read file))))
  863. @end example
  864. @node *read-base*, *read-default-float-format*, with-standard-io-syntax, Reader Dictionary
  865. @subsection *read-base* [Variable]
  866. @subsubheading Value Type::
  867. a @i{radix}.
  868. @subsubheading Initial Value::
  869. @t{10}.
  870. @subsubheading Description::
  871. Controls the interpretation of tokens by @b{read} as being
  872. @i{integers} or @i{ratios}.
  873. The @i{value} of @b{*read-base*}, called the @i{current input base}
  874. @IGindex{current input base}
  875. ,
  876. is the radix in which @i{integers} and
  877. @i{ratios} are to be read by the @i{Lisp reader}.
  878. The parsing of other numeric @i{types} (@i{e.g.}, @i{floats}) is
  879. not affected by this option.
  880. The effect of @b{*read-base*} on the reading of any particular
  881. @i{rational} number can be locally overridden by explicit use of the
  882. @t{#O}, @t{#X}, @t{#B}, or @t{#@i{n}R} syntax
  883. or by a trailing decimal point.
  884. @subsubheading Examples::
  885. @example
  886. (dotimes (i 6)
  887. (let ((*read-base* (+ 10. i)))
  888. (let ((object (read-from-string "(\\DAD DAD |BEE| BEE 123. 123)")))
  889. (print (list *read-base* object)))))
  890. @t{ |> } (10 (DAD DAD BEE BEE 123 123))
  891. @t{ |> } (11 (DAD DAD BEE BEE 123 146))
  892. @t{ |> } (12 (DAD DAD BEE BEE 123 171))
  893. @t{ |> } (13 (DAD DAD BEE BEE 123 198))
  894. @t{ |> } (14 (DAD 2701 BEE BEE 123 227))
  895. @t{ |> } (15 (DAD 3088 BEE 2699 123 258))
  896. @result{} NIL
  897. @end example
  898. @subsubheading Notes::
  899. Altering the input radix can be useful when reading data files in special formats.
  900. @node *read-default-float-format*, *read-eval*, *read-base*, Reader Dictionary
  901. @subsection *read-default-float-format* [Variable]
  902. @subsubheading Value Type::
  903. one of the @i{atomic type specifiers}
  904. @b{short-float},
  905. @b{single-float},
  906. @b{double-float},
  907. or @b{long-float},
  908. or else some other @i{type specifier} defined
  909. by the @i{implementation} to be acceptable.
  910. @subsubheading Initial Value::
  911. The @i{symbol} @b{single-float}.
  912. @subsubheading Description::
  913. Controls the floating-point format that is to be used when reading a
  914. floating-point number that has no @i{exponent marker} or that has
  915. @t{e} or @t{E} for an @i{exponent marker}. Other @i{exponent markers}
  916. explicitly prescribe the floating-point format to be used.
  917. The printer uses @b{*read-default-float-format*} to guide the
  918. choice of @i{exponent markers} when printing floating-point numbers.
  919. @subsubheading Examples::
  920. @example
  921. (let ((*read-default-float-format* 'double-float))
  922. (read-from-string "(1.0 1.0e0 1.0s0 1.0f0 1.0d0 1.0L0)"))
  923. @result{} (1.0 1.0 1.0 1.0 1.0 1.0) ;Implementation has float format F.
  924. @result{} (1.0 1.0 1.0s0 1.0 1.0 1.0) ;Implementation has float formats S and F.
  925. @result{} (1.0d0 1.0d0 1.0 1.0 1.0d0 1.0d0) ;Implementation has float formats F and D.
  926. @result{} (1.0d0 1.0d0 1.0s0 1.0 1.0d0 1.0d0) ;Implementation has float formats S, F, D.
  927. @result{} (1.0d0 1.0d0 1.0 1.0 1.0d0 1.0L0) ;Implementation has float formats F, D, L.
  928. @result{} (1.0d0 1.0d0 1.0s0 1.0 1.0d0 1.0L0) ;Implementation has formats S, F, D, L.
  929. @end example
  930. @node *read-eval*, *read-suppress*, *read-default-float-format*, Reader Dictionary
  931. @subsection *read-eval* [Variable]
  932. @subsubheading Value Type::
  933. a @i{generalized boolean}.
  934. @subsubheading Initial Value::
  935. @i{true}.
  936. @subsubheading Description::
  937. If it is @i{true}, the @t{#.} @i{reader macro} has its normal effect.
  938. Otherwise, that @i{reader macro} signals an error of @i{type} @b{reader-error}.
  939. @subsubheading See Also::
  940. @b{*print-readably*}
  941. @subsubheading Notes::
  942. If @b{*read-eval*} is @i{false} and @b{*print-readably*} is @i{true},
  943. any @i{method} for @b{print-object} that would output a reference
  944. to the @t{#.} @i{reader macro} either outputs something different
  945. or signals an error of @i{type} @b{print-not-readable}.
  946. @node *read-suppress*, *readtable*, *read-eval*, Reader Dictionary
  947. @subsection *read-suppress* [Variable]
  948. @subsubheading Value Type::
  949. a @i{generalized boolean}.
  950. @subsubheading Initial Value::
  951. @i{false}.
  952. @subsubheading Description::
  953. This variable is intended primarily to support the operation of the
  954. read-time conditional notations @t{#+} and @t{#-}. It is important for the
  955. @i{reader macros} which implement these notations
  956. to be able to skip over the printed representation of an
  957. @i{expression} despite the possibility that the syntax of the skipped
  958. @i{expression} may not be entirely valid for the current implementation,
  959. since @t{#+} and @t{#-} exist in order to allow the same program to be
  960. shared among several @r{Lisp} implementations (including dialects other than @r{Common Lisp})
  961. despite small incompatibilities of syntax.
  962. If it is @i{false}, the @i{Lisp reader} operates normally.
  963. If the @i{value} of @b{*read-suppress*} is @i{true},
  964. @b{read},
  965. @b{read-preserving-whitespace},
  966. @b{read-delimited-list},
  967. and @b{read-from-string}
  968. all return a @i{primary value} of @b{nil} when they complete successfully;
  969. however, they continue to parse the representation of an @i{object}
  970. in the normal way, in order to skip over the @i{object},
  971. and continue to indicate @i{end of file} in the normal way.
  972. Except as noted below,
  973. any @i{standardized} @i{reader macro}_2
  974. that is defined to @i{read}_2
  975. a following @i{object} or @i{token}
  976. will do so,
  977. but not signal an error if the @i{object}
  978. read is not of an appropriate type or syntax.
  979. The @i{standard syntax} and its associated @i{reader macros}
  980. will not construct any new @i{objects}
  981. (@i{e.g.}, when reading the representation of a @i{symbol},
  982. no @i{symbol} will be constructed or interned).
  983. @table @asis
  984. @item Extended tokens
  985. All extended tokens are completely uninterpreted.
  986. Errors such as those that might otherwise be signaled due to
  987. detection of invalid @i{potential numbers},
  988. invalid patterns of @i{package markers},
  989. and invalid uses of the @i{dot} character are suppressed.
  990. @item Dispatching macro characters (including @i{sharpsign})
  991. @i{Dispatching macro characters} continue to parse an infix numerical
  992. argument, and invoke the dispatch function. The @i{standardized}
  993. @i{sharpsign} @i{reader macros} do not enforce any constraints
  994. on either the presence of or the value of the numerical argument.
  995. @item #=
  996. The @t{#=} notation is totally ignored. It does not read
  997. a following @i{object}. It produces no @i{object},
  998. but is treated as @i{whitespace}_2.
  999. @item ##
  1000. The @t{##} notation always produces @b{nil}.
  1001. @end table
  1002. No matter what the @i{value} of @b{*read-suppress*},
  1003. parentheses still continue to delimit and construct @i{lists};
  1004. the @t{#(} notation continues to delimit @i{vectors};
  1005. and comments, @i{strings},
  1006. and the @i{single-quote} and @i{backquote} notations continue to be
  1007. interpreted properly. Such situations as
  1008. @t{')}, @t{#<},
  1009. @t{#)}, and @t{#<@i{Space}>} continue to signal errors.
  1010. @subsubheading Examples::
  1011. @example
  1012. (let ((*read-suppress* t))
  1013. (mapcar #'read-from-string
  1014. '("#(foo bar baz)" "#P(:type :lisp)" "#c1.2"
  1015. "#.(PRINT 'FOO)" "#3AHELLO" "#S(INTEGER)"
  1016. "#*ABC" "#\GARBAGE" "#RALPHA" "#3R444")))
  1017. @result{} (NIL NIL NIL NIL NIL NIL NIL NIL NIL NIL)
  1018. @end example
  1019. @subsubheading See Also::
  1020. @ref{read; read-preserving-whitespace}
  1021. ,
  1022. {@ref{Syntax}}
  1023. @subsubheading Notes::
  1024. @i{Programmers} and @i{implementations} that define additional
  1025. @i{macro characters} are strongly encouraged to make them respect
  1026. @b{*read-suppress*} just as @i{standardized} @i{macro characters} do.
  1027. That is, when the @i{value} of @b{*read-suppress*} is @i{true},
  1028. they should ignore type errors when reading a following @i{object}
  1029. and the @i{functions} that implement @i{dispatching macro characters}
  1030. should tolerate @b{nil} as their infix @i{parameter} value even if a numeric
  1031. value would ordinarily be required.
  1032. @node *readtable*, reader-error, *read-suppress*, Reader Dictionary
  1033. @subsection *readtable* [Variable]
  1034. @subsubheading Value Type::
  1035. a @i{readtable}.
  1036. @subsubheading Initial Value::
  1037. A @i{readtable} that conforms to the description of @r{Common Lisp} syntax in @ref{Syntax}.
  1038. @subsubheading Description::
  1039. The @i{value} of @b{*readtable*} is called the @i{current readtable}.
  1040. It controls the parsing behavior of the @i{Lisp reader},
  1041. and can also influence the @i{Lisp printer} (@i{e.g.}, see the @i{function} @b{readtable-case}).
  1042. @subsubheading Examples::
  1043. @example
  1044. (readtablep *readtable*) @result{} @i{true}
  1045. (setq zvar 123) @result{} 123
  1046. (set-syntax-from-char #\z #\' (setq table2 (copy-readtable))) @result{} T
  1047. zvar @result{} 123
  1048. (setq *readtable* table2) @result{} #<READTABLE>
  1049. zvar @result{} VAR
  1050. (setq *readtable* (copy-readtable nil)) @result{} #<READTABLE>
  1051. zvar @result{} 123
  1052. @end example
  1053. @subsubheading Affected By::
  1054. @b{compile-file},
  1055. @b{load}
  1056. @subsubheading See Also::
  1057. @ref{compile-file}
  1058. ,
  1059. @ref{load}
  1060. ,
  1061. @ref{readtable}
  1062. ,
  1063. @ref{The Current Readtable}
  1064. @node reader-error, , *readtable*, Reader Dictionary
  1065. @subsection reader-error [Condition Type]
  1066. @subsubheading Class Precedence List::
  1067. @b{reader-error},
  1068. @b{parse-error},
  1069. @b{stream-error},
  1070. @b{error},
  1071. @b{serious-condition},
  1072. @b{condition},
  1073. @b{t}
  1074. @subsubheading Description::
  1075. The @i{type} @b{reader-error} consists of
  1076. error conditions that are related to tokenization and parsing
  1077. done by the @i{Lisp reader}.
  1078. @subsubheading See Also::
  1079. @ref{read; read-preserving-whitespace}
  1080. ,
  1081. @ref{stream-error-stream}
  1082. ,
  1083. @ref{Reader Concepts}
  1084. @c end of including dict-reader
  1085. @c %**end of chapter