dict-reader.tex 51 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643
  1. % -*- Mode: TeX -*-
  2. % Reader
  3. % Reader Variables
  4. %-------------------- Readtable Type --------------------
  5. %% 2.7.0 1
  6. %% 22.1.5 2
  7. \begincom{readtable}\ftype{System Class}
  8. \label Class Precedence List::
  9. \typeref{readtable},
  10. \typeref{t}
  11. \label Description::
  12. A \term{readtable} maps \term{characters} into \term{syntax types} for
  13. the \term{Lisp reader}; \seechapter\Syntax.
  14. A \term{readtable} also
  15. contains associations between \term{macro characters}
  16. and their \term{reader macro functions},
  17. and records information about the case conversion rules
  18. to be used by the \term{Lisp reader} when parsing \term{symbols}.
  19. \issue{CHARACTER-PROPOSAL:2-1-1}
  20. %% 22.1.5 3
  21. %It is not required that an implementation have characters with non-zero
  22. %\param{bits} and \param{font} \term{attributes}
  23. %syntax descriptions in the \term{readtable}.
  24. %!!! The following replacement still isn't unambiguous.
  25. % Mail sent to Quinquevirate asking for advice.
  26. % -kmp 25-May-91
  27. Each \term{simple} \term{character} must be representable in the \term{readtable}.
  28. It is \term{implementation-defined} whether \term{non-simple} \term{characters}
  29. can have syntax descriptions in the \term{readtable}.
  30. \endissue{CHARACTER-PROPOSAL:2-1-1}
  31. \label See Also::
  32. {\secref\Readtables},
  33. {\secref\PrintingOtherObjects}
  34. \endcom%{readtable}\ftype{System Class}
  35. %-------------------- Reader --------------------
  36. %%% ========== COPY-READTABLE
  37. \begincom{copy-readtable}\ftype{Function}
  38. \label Syntax::
  39. \DefunWithValues {copy-readtable} {{\opt} from-readtable to-readtable} {readtable}
  40. \label Arguments and Values::
  41. \param{from-readtable}---a \term{readtable designator}.
  42. \Default{the \term{current readtable}}
  43. \param{to-readtable}---a \term{readtable} or \nil.
  44. \Default{\nil}
  45. \param{readtable}---the \param{to-readtable} if it is \term{non-nil},
  46. or else a \term{fresh} \term{readtable}.
  47. \label Description::
  48. %% 22.1.5 6
  49. \funref{copy-readtable} copies \param{from-readtable}.
  50. %% 22.1.5 7
  51. If \param{to-readtable} is \nil, a new \term{readtable} is created and returned.
  52. Otherwise the \term{readtable} specified by \param{to-readtable} is modified and returned.
  53. \issue{READ-CASE-SENSITIVITY:READTABLE-KEYWORDS}
  54. \funref{copy-readtable} copies the setting of \funref{readtable-case}.
  55. \endissue{READ-CASE-SENSITIVITY:READTABLE-KEYWORDS}
  56. \label Examples::
  57. %!!! This is an awful example, and relatively unsafe to just try blindly.
  58. \code
  59. (setq zvar 123) \EV 123
  60. (set-syntax-from-char #\\z #\\' (setq table2 (copy-readtable))) \EV T
  61. zvar \EV 123
  62. (copy-readtable table2 *readtable*) \EV #<READTABLE 614000277>
  63. zvar \EV VAR
  64. (setq *readtable* (copy-readtable)) \EV #<READTABLE 46210223>
  65. zvar \EV VAR
  66. (setq *readtable* (copy-readtable nil)) \EV #<READTABLE 46302670>
  67. zvar \EV 123
  68. \endcode
  69. \label Affected By:\None.
  70. \label Exceptional Situations:\None.
  71. \label See Also::
  72. \typeref{readtable},
  73. \varref{*readtable*}
  74. \label Notes::
  75. \code
  76. (setq *readtable* (copy-readtable nil))
  77. \endcode
  78. restores the input syntax to standard \clisp\ syntax, even if
  79. the \term{initial readtable} has been clobbered
  80. (assuming it is not so badly clobbered that you cannot type in the above expression).
  81. On the other hand,
  82. \code
  83. (setq *readtable* (copy-readtable))
  84. \endcode
  85. replaces the current \term{readtable} with a copy of itself.
  86. This is useful if you want to save a copy of a readtable for later use,
  87. protected from alteration in the meantime. It is also useful if you want to
  88. locally bind the readtable to a copy of itself, as in:
  89. \code
  90. (let ((*readtable* (copy-readtable))) ...)
  91. \endcode
  92. \endcom
  93. %%% ========== MAKE-DISPATCH-MACRO-CHARACTER
  94. \begincom{make-dispatch-macro-character}\ftype{Function}
  95. \label Syntax::
  96. \DefunWithValues {make-dispatch-macro-character}
  97. {char {\opt} non-terminating-p readtable}
  98. {\t}
  99. \label Arguments and Values::
  100. \issue{ARGUMENTS-UNDERSPECIFIED:SPECIFY}
  101. \param{char}---a \term{character}.
  102. \endissue{ARGUMENTS-UNDERSPECIFIED:SPECIFY}
  103. \param{non-terminating-p}---a \term{generalized boolean}.
  104. \Default{\term{false}}
  105. \param{readtable}---a \term{readtable}.
  106. \Default{the \term{current readtable}}
  107. \label Description::
  108. %% 22.1.5 19
  109. \funref{make-dispatch-macro-character} makes \param{char}
  110. be a \term{dispatching macro character} in \param{readtable}.
  111. Initially, every \term{character} in the dispatch table
  112. associated with the \param{char} has an associated function
  113. that signals an error \oftype{reader-error}.
  114. If \param{non-terminating-p} is \term{true},
  115. the \term{dispatching macro character}
  116. is made a \term{non-terminating} \term{macro character};
  117. if \param{non-terminating-p} is \term{false},
  118. the \term{dispatching macro character}
  119. is made a \term{terminating} \term{macro character}.
  120. \label Examples::
  121. \code
  122. (get-macro-character #\\\lbr) \EV NIL, \term{false}
  123. (make-dispatch-macro-character #\\\lbr) \EV T
  124. (not (get-macro-character #\\\lbr)) \EV \term{false}
  125. \endcode
  126. \label Side Effects:\None.
  127. %% Sandra thinks this is excessive.
  128. % A \term{pprint dispatch table} is created and initialized.
  129. The \param{readtable} is altered.
  130. \label Affected By:\None.
  131. \label Exceptional Situations:\None.
  132. \label See Also::
  133. \varref{*readtable*}, \funref{set-dispatch-macro-character}
  134. \label Notes:\None.
  135. \endcom
  136. %%% ========== READ
  137. %%% ========== READ-PRESERVING-WHITESPACE
  138. \begincom{read, read-preserving-whitespace}\ftype{Function}
  139. \label Syntax::
  140. \DefunWithValues read
  141. {{\opt} input-stream eof-error-p eof-value recursive-p}
  142. {object}
  143. \DefunWithValuesNewline
  144. read-preserving-whitespace
  145. {{\opt} \vtop{\hbox{input-stream eof-error-p}
  146. \hbox{eof-value recursive-p}}}
  147. {object}
  148. \label Arguments and Values::
  149. \param{input-stream}---an \term{input} \term{stream designator}.
  150. \param{eof-error-p}---a \term{generalized boolean}.
  151. \Default{\term{true}}
  152. \issue{ARGUMENTS-UNDERSPECIFIED:SPECIFY}
  153. \param{eof-value}---an \term{object}.
  154. \endissue{ARGUMENTS-UNDERSPECIFIED:SPECIFY}
  155. \Default{\nil}
  156. \param{recursive-p}---a \term{generalized boolean}.
  157. \Default{\term{false}}
  158. \param{object}---an \term{object} (parsed by the \term{Lisp reader})
  159. or the \param{eof-value}.
  160. \label Description::
  161. %% 22.2.1 9
  162. \funref{read} parses the printed representation of an \term{object}
  163. from \param{input-stream} and builds such an \term{object}.
  164. %% 22.2.1 14
  165. \funref{read-preserving-whitespace} is like \funref{read} but preserves
  166. any \term{whitespace}\meaning{2} \term{character}
  167. that delimits the printed representation of the \term{object}.
  168. %% 22.2.1 17
  169. \funref{read-preserving-whitespace} is exactly like \funref{read}
  170. when the \param{recursive-p} \term{argument} to \funref{read-preserving-whitespace}
  171. is \term{true}.
  172. %% 22.2.1 10
  173. %% 22.2.1 13
  174. When \varref{*read-suppress*} is \term{false},
  175. \funref{read} throws away the delimiting \term{character} required by
  176. certain printed representations if it is a
  177. \term{whitespace}\meaning{2} \term{character};
  178. but \funref{read} preserves the character
  179. (using \funref{unread-char}) if it is
  180. syntactically meaningful, because it could be the start of the next expression.
  181. %
  182. %% Already said in discussion of Double-Quote -kmp 25-Jan-92
  183. % %% 2.5.2 3
  184. % \funref{read} always constructs
  185. % a \term{simple string} when it reads the \term{double-quote} syntax.
  186. %
  187. %% Moved to discussion of Double-Quote -kmp 25-Jan-92
  188. % \issue{CHARACTER-PROPOSAL:2-1-1}
  189. % It is \term{implementation-dependent} which \term{attributes} are removed
  190. % from characters within \term{double-quotes}.
  191. % \endissue{CHARACTER-PROPOSAL:2-1-1}
  192. %
  193. %% Already said in discussion of #* -kmp 25-Jan-92
  194. %% 2.5.3 2
  195. % \funref{read} always constructs a \term{simple bit vector}
  196. % when it reads the \f{\#*} syntax.
  197. If a file ends in a \term{symbol} or a \term{number}
  198. immediately followed by an \term{end of file}\meaning{1},
  199. \funref{read} reads the \term{symbol} or \term{number} successfully;
  200. when called again, it sees the \term{end of file}\meaning{1} and
  201. only then acts according to \param{eof-error-p}.
  202. If a file contains ignorable text at the end, such
  203. as blank lines and comments, \funref{read}
  204. does not consider it to end in the
  205. middle of an \term{object}.
  206. % Moved to the discussion of tokenizing symbols. -kmp 25-Jan-92
  207. % \issue{CHARACTER-PROPOSAL:2-1-1}
  208. % It is \term{implementation-dependent} which
  209. % \term{attributes} are removed from \term{symbol} names.
  210. % \endissue{CHARACTER-PROPOSAL:2-1-1}
  211. If \param{recursive-p} is \term{true}, the call to \funref{read} is
  212. expected to be made
  213. from within some function that itself
  214. has been called from \funref{read} or from a similar input function, rather
  215. than from the top level.
  216. %% 22.2.1 9
  217. Both functions return the \term{object} read from \param{input-stream}.
  218. \param{Eof-value} is returned if \param{eof-error-p} is \term{false} and end of file
  219. is reached before the beginning of an \term{object}.
  220. \label Examples::
  221. %!!! This example needs work.
  222. \code
  223. (read)
  224. \OUT \IN{'a}
  225. \EV (QUOTE A)
  226. (with-input-from-string (is " ") (read is nil 'the-end)) \EV THE-END
  227. (defun skip-then-read-char (s c n)
  228. (if (char= c #\\\{) (read s t nil t) (read-preserving-whitespace s))
  229. (read-char-no-hang s)) \EV SKIP-THEN-READ-CHAR
  230. (let ((*readtable* (copy-readtable nil)))
  231. (set-dispatch-macro-character #\\# #\\\{ #'skip-then-read-char)
  232. (set-dispatch-macro-character #\\# #\\\} #'skip-then-read-char)
  233. (with-input-from-string (is "#\{123 x #\}123 y")
  234. (format t "~S ~S" (read is) (read is)))) \EV #\\x, #\\Space, NIL
  235. \endcode
  236. %% 22.2.1 15
  237. As an example, consider this \term{reader macro} definition:
  238. %JonL thinks this is easier to read if LOOP is used.
  239. % (defun slash-reader (stream char)
  240. % (declare (ignore char))
  241. % (do ((path (list (read-preserving-whitespace stream t nil t))
  242. % (cons (progn (read-char stream t nil t)
  243. % (read-preserving-whitespace
  244. % stream t nil t))
  245. % path)))
  246. % ((not (eql (peek-char nil stream nil nil t) #\\/))
  247. % (cons 'path (nreverse path)))))
  248. \code
  249. (defun slash-reader (stream char)
  250. (declare (ignore char))
  251. `(path . ,(loop for dir = (read-preserving-whitespace stream t nil t)
  252. then (progn (read-char stream t nil t)
  253. (read-preserving-whitespace stream t nil t))
  254. collect dir
  255. while (eql (peek-char nil stream nil nil t) #\\/))))
  256. (set-macro-character #\\/ #'slash-reader)
  257. \endcode
  258. %% 22.2.1 16
  259. Consider now calling \funref{read} on this expression:
  260. \code
  261. (zyedh /usr/games/zork /usr/games/boggle)
  262. \endcode
  263. The \f{/} macro reads objects separated by more \f{/} characters;
  264. thus \f{/usr/games/zork} is intended to read as \f{(path usr games zork)}.
  265. The entire example expression should therefore be read as
  266. \code
  267. (zyedh (path usr games zork) (path usr games boggle))
  268. \endcode
  269. However, if \funref{read} had been used instead of
  270. \funref{read-preserving-whitespace}, then after the reading of the symbol
  271. \f{zork}, the following space would be discarded; the next call
  272. to \funref{peek-char} would see the following \f{/}, and the loop would
  273. continue, producing this interpretation:
  274. \code
  275. (zyedh (path usr games zork usr games boggle))
  276. \endcode
  277. There are times when \term{whitespace}\meaning{2} should be discarded.
  278. If a command interpreter takes single-character commands,
  279. but occasionally reads an \term{object} then if the \term{whitespace}\meaning{2}
  280. after a \term{symbol}
  281. is not discarded it might be interpreted as a command
  282. some time later after the \term{symbol} had been read.
  283. \label Affected By::
  284. \varref{*standard-input*},
  285. \varref{*terminal-io*},
  286. \varref{*readtable*},
  287. \varref{*read-default-float-format*},
  288. \varref{*read-base*},
  289. \varref{*read-suppress*},
  290. \varref{*package*},
  291. \varref{*read-eval*}.
  292. \label Exceptional Situations::
  293. %% 22.2.1 3
  294. \funref{read} signals an error \oftype{end-of-file},
  295. regardless of \param{eof-error-p}, if
  296. the file ends in the middle of an \term{object} representation.
  297. For example, if a file does
  298. not contain enough right parentheses to balance the left parentheses in
  299. it, \funref{read} signals an error.
  300. This is detected when \funref{read} or \funref{read-preserving-whitespace}
  301. is called with \param{recursive-p} and \param{eof-error-p} \term{non-nil},
  302. and end-of-file is reached before the beginning of an \term{object}.
  303. If \param{eof-error-p} is \term{true}, an error \oftype{end-of-file}
  304. is signaled at the end of file.
  305. \label See Also::
  306. \funref{peek-char},
  307. \funref{read-char},
  308. \funref{unread-char},
  309. \funref{read-from-string},
  310. \funref{read-delimited-list},
  311. \funref{parse-integer},
  312. {\chapref\Syntax},
  313. {\chapref\ReaderConcepts}
  314. \label Notes:\None.
  315. %% Sandra: Just cross-reference "Reader Concepts".
  316. % \param{Recursive-p} should be true if the call to \funref{read} is
  317. % from within some function that itself
  318. % has been called from \funref{read} or from a similar input function, rather
  319. % than from the top level. For
  320. % instance, a reader macro function that has to read from the input stream
  321. % beyond the \term{macro character} should specify \param{recursive-p} as true. The
  322. % reasons for this are as follows. First of all, the scoping of the
  323. % notations \f{\#\i{n}=} and \f{\#\i{n}\#} occurs within a
  324. % top-level call, so calls to \funref{read}
  325. % from reader macro functions must
  326. % specify \param{recursive-p} as true to ensure that these notations are
  327. % interpreted correctly. Second, for white space to be preserved correctly
  328. % by low-level calls to \funref{read} occurring within a call to
  329. % \funref{read-preserving-whitespace}, \param{recursive-p} must be true.
  330. % Otherwise a low-level call to \funref{read} does not know that it needs to
  331. % preserve white space for the higher-level call.
  332. % Third, this is necessary to distinguish end-of-file within an \term{object}
  333. % from end-of-file between \term{objects}.
  334. \endcom
  335. %%% ========== READ-DELIMITED-LIST
  336. \begincom{read-delimited-list}\ftype{Function}
  337. \label Syntax::
  338. \DefunWithValues read-delimited-list
  339. {char {\opt} input-stream recursive-p}
  340. {list}
  341. \label Arguments and Values::
  342. \param{char}---a \term{character}.
  343. \param{input-stream}---an \term{input} \term{stream designator}.
  344. \Default{\term{standard input}}
  345. \param{recursive-p}---a \term{generalized boolean}.
  346. \Default{\term{false}}
  347. \param{list}---a \term{list} of the \term{objects} read.
  348. \label Description::
  349. %% 22.2.1 18
  350. \funref{read-delimited-list} reads \term{objects} from \param{input-stream}
  351. until the next character after an \term{object}'s
  352. representation (ignoring \term{whitespace}\meaning{2} characters and comments) is \param{char}.
  353. %% 22.2.1 19
  354. \funref{read-delimited-list} looks ahead at each step
  355. for the next non-\term{whitespace}\meaning{2} \term{character}
  356. and peeks at it as if with \funref{peek-char}.
  357. If it is \param{char},
  358. then the \term{character} is consumed and the \term{list} of \term{objects} is returned.
  359. If it is a \term{constituent} or \term{escape} \term{character},
  360. then \funref{read} is used to read an \term{object},
  361. which is added to the end of the \term{list}.
  362. If it is a \term{macro character},
  363. its \term{reader macro function} is called;
  364. if the function returns a \term{value},
  365. that \term{value} is added to the \term{list}.
  366. The peek-ahead process is then repeated.
  367. If \param{recursive-p} is \term{true},
  368. this call is expected to be embedded in a higher-level call to \funref{read}
  369. or a similar function.
  370. %% 22.2.1 25
  371. It is an error to reach end-of-file during the operation of
  372. \funref{read-delimited-list}.
  373. The consequences are undefined
  374. if \param{char} has a \term{syntax type} of \term{whitespace}\meaning{2}
  375. in the \term{current readtable}.
  376. \label Examples::
  377. \code
  378. (read-delimited-list #\\\rbracket) 1 2 3 4 5 6 \rbracket
  379. \EV (1 2 3 4 5 6)
  380. \endcode
  381. %% 22.2.1 22
  382. Suppose you wanted \f{\#\{\i{a} \i{b} \i{c} $\ldots$ \i{z}\}}
  383. to read as a list of all pairs of the elements \i{a}, \i{b}, \i{c},
  384. $\ldots$, \i{z}, for example.
  385. \code
  386. #\{p q z a\} reads as ((p q) (p z) (p a) (q z) (q a) (z a))
  387. \endcode
  388. This can be done by specifying a macro-character definition for \f{\#\{}
  389. that does two things: reads in all the items up to the \f{\}},
  390. and constructs the pairs. \funref{read-delimited-list} performs
  391. the first task.
  392. % (
  393. \code
  394. (defun |#\{-reader| (stream char arg)
  395. (declare (ignore char arg))
  396. (mapcon #'(lambda (x)
  397. (mapcar #'(lambda (y) (list (car x) y)) (cdr x)))
  398. (read-delimited-list #\\\} stream t))) \EV |#\{-reader|
  399. (set-dispatch-macro-character #\\# #\\\{ #'|#\{-reader|) \EV T
  400. (set-macro-character #\\\} (get-macro-character #\\) \nil))
  401. \endcode
  402. Note that \term{true} is supplied for the \param{recursive-p} argument.
  403. %% 22.2.1 23
  404. It is necessary here to give a definition to the character \f{\}} as
  405. well to prevent it from being a constituent.
  406. If the line
  407. % (
  408. \code
  409. (set-macro-character #\\\} (get-macro-character #\\) \nil))
  410. \endcode
  411. shown above were not included, then the \f{\}} in
  412. \code
  413. #\{ p q z a\}
  414. \endcode
  415. would be considered a constituent character, part of the symbol named
  416. \f{a\}}. This could be corrected by putting a space before
  417. the \f{\}}, but it is better to call
  418. \funref{set-macro-character}.
  419. %% 22.2.1 24
  420. Giving \f{\}} the same % (
  421. definition as the standard definition of the character \f{)} has the
  422. twin benefit of making it terminate tokens for use with
  423. \funref{read-delimited-list} and also making it invalid for use in any
  424. other context. Attempting to read a stray \f{\}} will signal an error.
  425. \label Affected By::
  426. \varref{*standard-input*},
  427. \varref{*readtable*},
  428. \varref{*terminal-io*}.
  429. \label Exceptional Situations:\None.
  430. \label See Also::
  431. \funref{read},
  432. \funref{peek-char},
  433. \funref{read-char},
  434. \funref{unread-char}.
  435. \label Notes::
  436. %% 22.2.1 20
  437. \funref{read-delimited-list} is intended for use in implementing \term{reader macros}.
  438. Usually it is desirable for \param{char} to be a \term{terminating} \term{macro character}
  439. so that it can be used to delimit tokens; however, \funref{read-delimited-list}
  440. makes no attempt to alter the syntax specified for \param{char} by the current
  441. readtable. The caller must make any necessary changes to the readtable syntax
  442. explicitly.
  443. \endcom
  444. %%% ========== READ-FROM-STRING
  445. \begincom{read-from-string}\ftype{Function}
  446. \label Syntax::
  447. \DefunWithValuesNewline
  448. read-from-string
  449. {string \vtop{\hbox{{\opt} eof-error-p eof-value}
  450. \hbox{{\key} start end preserve-whitespace}}}
  451. {object, position}
  452. \label Arguments and Values::
  453. \param{string}---a \term{string}.
  454. \param{eof-error-p}---a \term{generalized boolean}.
  455. \Default{\term{true}}
  456. \issue{ARGUMENTS-UNDERSPECIFIED:SPECIFY}
  457. \param{eof-value}---an \term{object}.
  458. \endissue{ARGUMENTS-UNDERSPECIFIED:SPECIFY}
  459. \Default{\nil}
  460. \issue{SUBSEQ-OUT-OF-BOUNDS}
  461. \issue{RANGE-OF-START-AND-END-PARAMETERS:INTEGER-AND-INTEGER-NIL}
  462. \param{start}, \param{end}---\term{bounding index designators} of \param{string}.
  463. \Defaults{\param{start} and \param{end}}{\f{0} and \nil}
  464. \endissue{RANGE-OF-START-AND-END-PARAMETERS:INTEGER-AND-INTEGER-NIL}
  465. \endissue{SUBSEQ-OUT-OF-BOUNDS}
  466. \param{preserve-whitespace}---a \term{generalized boolean}.
  467. \Default{\term{false}}
  468. \param{object}---an \term{object} (parsed by the \term{Lisp reader})
  469. or the \param{eof-value}.
  470. \param{position}---an \term{integer} greater than or equal to zero,
  471. and less than or equal to
  472. one more than the \term{length} of the \param{string}.
  473. \label Description::
  474. %% 22.2.1 40
  475. Parses the printed representation of an \term{object}
  476. from the subsequence of \param{string} \term{bounded} by \param{start} and \param{end},
  477. as if \funref{read} had been called on an \term{input} \term{stream}
  478. containing those same \term{characters}.
  479. % This seems unnecessary/redundant to me.
  480. % %% 22.2.1 39
  481. % The characters of \param{string} are given successively to the \term{Lisp reader},
  482. % and the \term{object} is built by the reader.
  483. %% 22.2.1 41
  484. If \param{preserve-whitespace} is \term{true},
  485. the operation will preserve \term{whitespace}\meaning{2}
  486. as \funref{read-preserving-whitespace} would do.
  487. %% 22.2.1 43
  488. If an \term{object} is successfully parsed, the \term{primary value}, \param{object},
  489. is the \term{object} that was parsed.
  490. If \param{eof-error-p} is \term{false} and if the end of the \param{substring} is reached,
  491. \param{eof-value} is returned.
  492. The \term{secondary value}, \param{position}, is the index of the first \term{character}
  493. in the \term{bounded} \param{string} that was not read.
  494. The \param{position} may depend upon the value of \param{preserve-whitespace}.
  495. % Amazing. CLtL really says this. I wonder why. -kmp 23-Jan-92
  496. If the entire \param{string} was read,
  497. the \param{position} returned is either the \param{length} of the \param{string}
  498. or one greater than the \param{length} of the \param{string}.
  499. \label Examples::
  500. %% 22.2.1 44
  501. \code
  502. (read-from-string " 1 3 5" t nil :start 2) \EV 3, 5
  503. (read-from-string "(a b c)") \EV (A B C), 7
  504. \endcode
  505. \label Side Effects:\None.
  506. \label Affected By:\None.
  507. \label Exceptional Situations::
  508. %% 22.2.1 42
  509. If the end of the supplied substring
  510. occurs before an \term{object} can be read, an
  511. error is signaled if \param{eof-error-p} is \term{true}.
  512. An error is signaled if the end of the \param{substring} occurs
  513. in the middle of an incomplete \term{object}.
  514. \label See Also::
  515. \funref{read},
  516. \funref{read-preserving-whitespace}
  517. \label Notes::
  518. % Moon and Sandra seemed to believe this was the motivation.
  519. % I felt we should record the fact. -kmp 24-Jan-92
  520. The reason that \param{position} is allowed to be beyond the
  521. \term{length} of the \param{string} is to permit (but not require)
  522. the \term{implementation} to work by simulating the effect of a
  523. trailing delimiter at the end of the \term{bounded} \param{string}.
  524. When \param{preserve-whitespace} is \term{true},
  525. the \param{position} might count the simulated delimiter.
  526. \endcom
  527. %%% ========== READTABLE-CASE
  528. \begincom{readtable-case}\ftype{Accessor}
  529. \issue{READ-CASE-SENSITIVITY:READTABLE-KEYWORDS}
  530. \label Syntax::
  531. \DefunWithValues readtable-case {readtable} {mode}
  532. % Fixed broken syntax. --sjl 16 Mar 92
  533. %\Defsetf readtable-case {readtable mode} {mode}
  534. \Defsetf readtable-case {readtable} {mode}
  535. \label Arguments and Values::
  536. \param{readtable}---a \term{readtable}.
  537. \param{mode}---a \term{case sensitivity mode}.
  538. \label Description::
  539. \term{Accesses} the \term{readtable case} of \param{readtable},
  540. which affects the way in which the \term{Lisp Reader} reads \term{symbols}
  541. and the way in which the \term{Lisp Printer} writes \term{symbols}.
  542. \label Examples::
  543. \Seesection\ReadtableCaseReadExamples\ and \secref\ReadtableCasePrintExamples.
  544. \label Affected By:\None.
  545. \label Exceptional Situations::
  546. \Shouldchecktype{readtable}{a \term{readtable}}
  547. \Shouldchecktype{mode}{a \term{case sensitivity mode}}
  548. \label See Also::
  549. \varref{*readtable*},
  550. \varref{*print-escape*},
  551. {\secref\ReaderAlgorithm},
  552. {\secref\ReadtableCaseReadEffect},
  553. {\secref\ReadtableCasePrintEffect}
  554. \label Notes::
  555. \funref{copy-readtable} copies the \term{readtable case} of the \param{readtable}.
  556. \endissue{READ-CASE-SENSITIVITY:READTABLE-KEYWORDS}
  557. \endcom
  558. %%% ========== READTABLEP
  559. \begincom{readtablep}\ftype{Function}
  560. \label Syntax::
  561. \DefunWithValues readtablep {object} {generalized-boolean}
  562. \label Arguments and Values::
  563. \param{object}---an \term{object}.
  564. \param{generalized-boolean}---a \term{generalized boolean}.
  565. \label Description::
  566. %% 22.1.5 8
  567. \TypePredicate{object}{readtable}
  568. \label Examples::
  569. \code
  570. (readtablep *readtable*) \EV \term{true}
  571. (readtablep (copy-readtable)) \EV \term{true}
  572. (readtablep '*readtable*) \EV \term{false}
  573. \endcode
  574. \label Side Effects:\None.
  575. \label Affected By:\None.
  576. \label Exceptional Situations:\None!
  577. \label See Also:\None.
  578. \label Notes::
  579. \code
  580. (readtablep \param{object}) \EQ (typep \param{object} 'readtable)
  581. \endcode
  582. \endcom
  583. %%% ========== GET-DISPATCH-MACRO-CHARACTER
  584. %%% ========== SET-DISPATCH-MACRO-CHARACTER
  585. \begincom{set-dispatch-macro-character, get-dispatch-macro-character}\ftype{Function}
  586. \label Syntax::
  587. %% 22.1.5 24
  588. %!!! Name this function1 argument something better. -kmp 15-Oct-91
  589. \DefunWithValues get-dispatch-macro-character
  590. {disp-char sub-char {\opt} readtable}
  591. {function}
  592. %% 22.1.5 23
  593. \DefunWithValues set-dispatch-macro-character
  594. {disp-char sub-char new-function {\opt} readtable}
  595. {\t}
  596. \label Arguments and Values::
  597. \param{disp-char}---a \term{character}.
  598. \param{sub-char}---a \term{character}.
  599. \issue{GET-MACRO-CHARACTER-READTABLE:NIL-STANDARD}
  600. \param{readtable}---a \term{readtable designator}.
  601. \endissue{GET-MACRO-CHARACTER-READTABLE:NIL-STANDARD}
  602. \Default{the \term{current readtable}}
  603. \param{function}---a \term{function designator} or \nil.
  604. %I made this a function designator. See reasoning for get-macro-character. -kmp 20-Sep-91
  605. \param{new-function}---a \term{function designator}.
  606. \label Description::
  607. \funref{set-dispatch-macro-character} causes \param{new-function} to be called
  608. when \param{disp-char} followed by \param{sub-char} is read.
  609. %% 22.1.5 22
  610. If \param{sub-char} is a lowercase letter,
  611. it is converted to its uppercase equivalent.
  612. It is an error if \param{sub-char} is one of the ten decimal digits.
  613. \funref{set-dispatch-macro-character} installs a \param{new-function} to be called
  614. when a particular \term{dispatching macro character} pair is read.
  615. \param{New-function} is installed as the dispatch function to be
  616. called when \param{readtable} is in use and when \param{disp-char} is followed by
  617. \param{sub-char}.
  618. %% This information is now available elsewhere.
  619. %
  620. % %!!! current input stream? this means the stream on which the char was seen.
  621. % % be more specific so people don't think this is standard input or something
  622. % % weird like that.
  623. % The three arguments to \param{new-function} are the current input \term{stream},
  624. % \param{sub-char}, and
  625. % the \term{integer} whose decimal representation appeared between
  626. % \param{disp-char} and \param{sub-char},
  627. % or \nil\ if no decimal integer appeared there; .
  628. For more information about how the \param{new-function} is invoked,
  629. \seesection\MacroChars.
  630. \funref{get-dispatch-macro-character} retrieves
  631. the dispatch function associated with \param{disp-char} and \param{sub-char}
  632. in \param{readtable}.
  633. \funref{get-dispatch-macro-character} returns the macro-character function
  634. for \param{sub-char} under \param{disp-char}, or \nil\ if there is no
  635. function associated with \param{sub-char}.
  636. If \param{sub-char} is a decimal digit, \funref{get-dispatch-macro-character}
  637. returns \nil.
  638. \label Examples::
  639. %!!! The use of (values) here is really questionable! -kmp 1-May-91
  640. \code
  641. (get-dispatch-macro-character #\\# #\\\{) \EV NIL
  642. (set-dispatch-macro-character #\\# #\\\{ ;dispatch on #\{
  643. #'(lambda(s c n)
  644. (let ((list (read s nil (values) t))) ;list is object after #n\{
  645. (when (consp list) ;return nth element of list
  646. (unless (and n (< 0 n (length list))) (setq n 0))
  647. (setq list (nth n list)))
  648. list))) \EV T
  649. #\{(1 2 3 4) \EV 1
  650. #3\{(0 1 2 3) \EV 3
  651. #\{123 \EV 123
  652. \endcode
  653. %% 22.1.5 27
  654. If it is desired that \f{\#\$\i{foo}} :
  655. as if it were \f{(dollars \i{foo})}.
  656. \code
  657. (defun |#$-reader| (stream subchar arg)
  658. (declare (ignore subchar arg))
  659. (list 'dollars (read stream t nil t))) \EV |#$-reader|
  660. (set-dispatch-macro-character #\\# #\\\$ #'|#\$-reader|) \EV T
  661. \endcode
  662. %\code
  663. % (get-dispatch-macro-character #\\# #\\\{) \EV NIL
  664. % (unless (get-dispatch-macro-character #\\# #\\x)
  665. % (warn "Hexadecimal input (#x<ddd>) is disabled")) \EV NIL
  666. % (let ((previous-fun (get-dispatch-macro-character #\\# #\\\{)))
  667. % (when previous-fun
  668. % (set-dispatch-macro-character #\\# #\\\{
  669. % #'(lambda (stream char arg)
  670. % (setq stream *debug-io*)
  671. % (when *debug-macro-chars*
  672. % (format *trace-output*
  673. % "~&Occurrence of ~C~C on stream ~S"
  674. % #\\# #\\\{ stream))
  675. % (list (funcall previous-fun stream char)))))) \EV NIL
  676. %\endcode
  677. \label See Also::
  678. {\secref\MacroChars}
  679. \label Side Effects::
  680. The \param{readtable} is modified.
  681. \label Affected By::
  682. \varref{*readtable*}.
  683. \label Exceptional Situations::
  684. %% 22.1.5 26
  685. For either function, an error is signaled if \param{disp-char} is not
  686. a \term{dispatching macro character} in \param{readtable}.
  687. \label See Also::
  688. \varref{*readtable*}
  689. \label Notes::
  690. It is necessary
  691. to use \funref{make-dispatch-macro-character} to set up the
  692. dispatch character before specifying its sub-characters.
  693. \endcom
  694. %%% ========== GET-MACRO-CHARACTER
  695. %%% ========== SET-MACRO-CHARACTER
  696. \begincom{set-macro-character, get-macro-character}\ftype{Function}
  697. \label Syntax::
  698. %% 22.1.5 13
  699. \DefunWithValues get-macro-character
  700. {char {\opt} readtable}
  701. {function, non-terminating-p}
  702. \DefunWithValues set-macro-character
  703. {char new-function {\opt} non-terminating-p readtable}
  704. {\t}
  705. \label Arguments and Values::
  706. \param{char}---a \term{character}.
  707. \param{non-terminating-p}---a \term{generalized boolean}.
  708. \Default{\term{false}}
  709. \issue{GET-MACRO-CHARACTER-READTABLE:NIL-STANDARD}
  710. \param{readtable}---a \term{readtable designator}.
  711. \endissue{GET-MACRO-CHARACTER-READTABLE:NIL-STANDARD}
  712. \Default{the \term{current readtable}}
  713. \param{function}---\nil,
  714. or a \term{designator} for a \term{function} of two \term{arguments}.
  715. \param{new-function}---a \term{function designator}.
  716. \label Description::
  717. %%function or function designator? -kmp 29-Apr-91
  718. %%I made it be a function designator since this is consistent with the CLtL
  719. %%treatment of symbols as functions, and since some implementation might consider
  720. %%it a feature to carry around the name instead of the definition, so the user
  721. %%could redefine the function and have his new definition take automatically.
  722. %% -kmp 20-Sep-91
  723. \funref{get-macro-character} returns as its \term{primary value}, \param{function},
  724. the \term{reader macro function} associated with \param{char} in \param{readtable} (if any),
  725. or else \nil\ if \param{char} is not a \term{macro character} in \param{readtable}.
  726. The \term{secondary value}, \param{non-terminating-p}, is \term{true}
  727. if \param{char} is a \term{non-terminating} \term{macro character};
  728. otherwise, it is \term{false}.
  729. \funref{set-macro-character} causes \param{char} to be a \term{macro character}
  730. associated with the \term{reader macro function} \param{new-function}
  731. (or the \term{designator} for \param{new-function}) in \param{readtable}.
  732. If \param{non-terminating-p} is \term{true},
  733. \param{char} becomes a \term{non-terminating} \term{macro character};
  734. otherwise it becomes a \term{terminating} \term{macro character}.
  735. %% This information can be gotten from the Reader Algorithm. -kmp 23-Jan-92
  736. % In the simplest case, \param{new-function} may return an \term{object}.
  737. % This \term{object} is taken to be that whose printed representation
  738. % was \param{char} and any following characters read by \param{new-function}.
  739. % %% 22.1.5 15
  740. % \param{New-function} may choose instead to return zero values.
  741. % In this case, \param{char} and whatever it may have read
  742. % contribute nothing to the \term{object} being read.
  743. % %% 22.1.5 16
  744. % \param{New-function} should not have any side effects other than on the
  745. % \term{stream};
  746. % because of backtracking and restarting of the \funref{read} operation,
  747. % front ends (such as editors and
  748. % rubout handlers) to the reader may cause
  749. % \param{new-function} to be called repeatedly during the
  750. % reading of a single expression in which \param{char} only appears once.
  751. \label Examples::
  752. \code
  753. (get-macro-character #\\\lbr) \EV NIL, \term{false}
  754. (not (get-macro-character #\\;)) \EV \term{false}
  755. \endcode
  756. The following is a possible definition for the \term{single-quote} \term{reader macro}
  757. in \term{standard syntax}:
  758. \code
  759. (defun single-quote-reader (stream char)
  760. (declare (ignore char))
  761. (list 'quote (read stream t nil t))) \EV SINGLE-QUOTE-READER
  762. (set-macro-character #\\' #'single-quote-reader) \EV T
  763. \endcode
  764. Here \f{single-quote-reader} reads an \term{object} following the \term{single-quote}
  765. and returns a \term{list} of \specref{quote} and that \term{object}.
  766. The \param{char} argument is ignored.
  767. The following is a possible definition for the \term{semicolon} \term{reader macro}
  768. in \term{standard syntax}:
  769. \code
  770. (defun semicolon-reader (stream char)
  771. (declare (ignore char))
  772. ;; First swallow the rest of the current input line.
  773. ;; End-of-file is acceptable for terminating the comment.
  774. (do () ((char= (read-char stream nil #\\Newline t) #\\Newline)))
  775. ;; Return zero values.
  776. (values)) \EV SEMICOLON-READER
  777. (set-macro-character #\\; #'semicolon-reader) \EV T
  778. \endcode
  779. \label Side Effects::
  780. The \param{readtable} is modified.
  781. \label Affected By:\None.
  782. \label Exceptional Situations:\None.
  783. \label See Also::
  784. \varref{*readtable*}
  785. \label Notes:\None.
  786. %% Sandra thinks this is useless. Enough is said in the argument info
  787. %% above for people to figure it out. (I agree.) -kmp 23-Jan-92
  788. % \issue{GET-MACRO-CHARACTER-READTABLE:NIL-STANDARD}
  789. % \f{(get-macro-character \i{char} nil)}
  790. %
  791. % is equivalent to
  792. %
  793. % \f{(get-macro-character \i{char} (copy-readtable))},
  794. %
  795. % but without \term{consing}.
  796. % \endissue{GET-MACRO-CHARACTER-READTABLE:NIL-STANDARD}
  797. \endcom
  798. %%% ========== SET-SYNTAX-FROM-CHAR
  799. \begincom{set-syntax-from-char}\ftype{Function}
  800. \label Syntax::
  801. \issue{RETURN-VALUES-UNSPECIFIED:SPECIFY}
  802. \DefunWithValues set-syntax-from-char
  803. {to-char from-char {\opt} to-readtable from-readtable}
  804. {\t}
  805. \endissue{RETURN-VALUES-UNSPECIFIED:SPECIFY}
  806. \label Arguments and Values::
  807. \issue{ARGUMENTS-UNDERSPECIFIED:SPECIFY}
  808. \param{to-char}---a \term{character}.
  809. \param{from-char}---a \term{character}.
  810. \endissue{ARGUMENTS-UNDERSPECIFIED:SPECIFY}
  811. \param{to-readtable}---a \term{readtable}.
  812. \Default{the \term{current readtable}}
  813. \param{from-readtable}---a \term{readtable designator}.
  814. \Default{the \term{standard readtable}}
  815. \label Description::
  816. %% 22.1.5 9
  817. \funref{set-syntax-from-char} makes
  818. the syntax of \param{to-char} in \param{to-readtable} be the same as
  819. the syntax of \param{from-char} in \param{from-readtable}.
  820. %% 22.1.5 10
  821. \funref{set-syntax-from-char} copies the \term{syntax types} of \param{from-char}.
  822. If \param{from-char} is a \term{macro character},
  823. its \term{reader macro function} is copied also.
  824. If the character is a \term{dispatching macro character},
  825. its entire dispatch table of \term{reader macro functions} is copied.
  826. The \term{constituent traits} of \param{from-char} are not copied.
  827. %% 22.1.5 12
  828. A macro definition from a character such as
  829. \f{"} can be copied to another character; the standard definition for \f{"}
  830. looks for another character that is the same as the character that
  831. invoked it. The definition of \f{(} can not be meaningfully copied
  832. to \f{\{}, on the other hand.
  833. The result is that \term{lists} are of the form
  834. \f{\{a b c)}, not \f{\{a b c\}},
  835. because the definition
  836. always looks for a closing parenthesis, not a closing brace.
  837. \label Examples::
  838. \code
  839. (set-syntax-from-char #\\7 #\\;) \EV T
  840. 123579 \EV 1235
  841. \endcode
  842. \label Side Effects::
  843. The \param{to-readtable} is modified.
  844. \label Affected By::
  845. The existing values in the \param{from-readtable}.
  846. \label Exceptional Situations:\None.
  847. \label See Also::
  848. \funref{set-macro-character},
  849. \funref{make-dispatch-macro-character},
  850. {\secref\CharacterSyntaxTypes}
  851. \label Notes::
  852. The \term{constituent traits} of a \term{character} are ``hard wired''
  853. into the parser for extended \term{tokens}. For example, if the definition
  854. of \f{S} is copied to \f{*}, then \f{*} will become a \term{constituent}
  855. that is \term{alphabetic}\meaning{2} but that cannot be used as a
  856. \term{short float} \term{exponent marker}.
  857. For further information, \seesection\ConstituentTraits.
  858. \endcom
  859. %%% ========== WITH-STANDARD-IO-SYNTAX
  860. \begincom{with-standard-io-syntax}\ftype{Macro}
  861. \label Syntax::
  862. \DefmacWithValues with-standard-io-syntax
  863. {\starparam{form}}
  864. {\starparam{result}}
  865. \label Arguments and Values::
  866. \param{forms}---an \term{implicit progn}.
  867. \param{results}---the \term{values} returned by the \term{forms}.
  868. \label Description::
  869. Within the dynamic extent of the body of \param{forms}, all reader/printer control
  870. variables, including any \term{implementation-defined} ones not specified by
  871. this standard, are bound to values that produce standard read/print
  872. behavior. The values for the variables specified by this standard are listed in
  873. \thenextfigure.
  874. \reviewer{Barrett: *print-pprint-dispatch* should probably be mentioned here, too.}%!!!
  875. % We've opened issue WITH-STANDARD-IO-SYNTAX-INCOMPLETE to clarify this. -kmp 1-Sep-91
  876. % I added *print-lines*, *print-miser-width*, *print-pprint-dispatch*, and
  877. % *print-right-margin* to this table. --sjl 16 Mar 1992
  878. \tablefigtwo{Values of standard control variables}{Variable}{Value}{
  879. \varref{*package*} & \Thepackage{cl-user} \cr
  880. \varref{*print-array*} & \t \cr
  881. \varref{*print-base*} & \f{10} \cr
  882. \varref{*print-case*} & \kwd{upcase} \cr
  883. \varref{*print-circle*} & \nil \cr
  884. \varref{*print-escape*} & \t \cr
  885. \varref{*print-gensym*} & \t \cr
  886. \varref{*print-length*} & \nil \cr
  887. \varref{*print-level*} & \nil \cr
  888. \varref{*print-lines*} & \nil \cr
  889. \varref{*print-miser-width*} & \nil \cr
  890. \varref{*print-pprint-dispatch*} & The \term{standard pprint dispatch table} \cr
  891. \varref{*print-pretty*} & \nil \cr
  892. \varref{*print-radix*} & \nil \cr
  893. \varref{*print-readably*} & \t \cr
  894. \varref{*print-right-margin*} & \nil \cr
  895. \varref{*read-base*} & \f{10} \cr
  896. \varref{*read-default-float-format*} & \typeref{single-float} \cr
  897. \varref{*read-eval*} & \t \cr
  898. \varref{*read-suppress*} & \nil \cr
  899. \varref{*readtable*} & The \term{standard readtable} \cr
  900. }
  901. \label Examples::
  902. \code
  903. (with-open-file (file pathname :direction :output)
  904. (with-standard-io-syntax
  905. (print data file)))
  906. ;;; ... Later, in another Lisp:
  907. (with-open-file (file pathname :direction :input)
  908. (with-standard-io-syntax
  909. (setq data (read file))))
  910. \endcode
  911. \label Affected By:\None.
  912. \label Exceptional Situations:\None.
  913. \label See Also:\None.
  914. \label Notes:\None.
  915. \endcom
  916. %-------------------- Reader Variables --------------------
  917. %%% ========== *READ-BASE*
  918. \begincom{*read-base*}\ftype{Variable}
  919. \label Value Type::
  920. a \term{radix}.
  921. \label Initial Value::
  922. \f{10}.
  923. \label Description::
  924. %% 22.1.2 21
  925. Controls the interpretation of tokens by \funref{read} as being
  926. \term{integers} or \term{ratios}.
  927. \Thevalueof{*read-base*}, called the \newterm{current input base},
  928. is the radix in which \term{integers} and
  929. \term{ratios} are to be read by the \term{Lisp reader}.
  930. The parsing of other numeric \term{types} (\eg \term{floats}) is
  931. not affected by this option.
  932. The effect of \varref{*read-base*} on the reading of any particular
  933. \term{rational} number can be locally overridden by explicit use of the
  934. \f{\#O}, \f{\#X}, \f{\#B}, or {\tt \#\i{n}R} syntax
  935. or by a trailing decimal point.
  936. \label Examples::
  937. \code
  938. (dotimes (i 6)
  939. (let ((*read-base* (+ 10. i)))
  940. (let ((object (read-from-string "(\\\\DAD DAD |BEE| BEE 123. 123)")))
  941. (print (list *read-base* object)))))
  942. \OUT (10 (DAD DAD BEE BEE 123 123))
  943. \OUT (11 (DAD DAD BEE BEE 123 146))
  944. \OUT (12 (DAD DAD BEE BEE 123 171))
  945. \OUT (13 (DAD DAD BEE BEE 123 198))
  946. \OUT (14 (DAD 2701 BEE BEE 123 227))
  947. \OUT (15 (DAD 3088 BEE 2699 123 258))
  948. \EV NIL
  949. \endcode
  950. \label Affected By:\None.
  951. \label See Also:\None.
  952. \label Notes::
  953. %% 22.1.2 22
  954. Altering the input radix can be useful when reading data files in special formats.
  955. \endcom
  956. %%% ========== *READ-DEFAULT-FLOAT-FORMAT*
  957. \begincom{*read-default-float-format*}\ftype{Variable}
  958. \label Value Type::
  959. %% 22.2.1 11
  960. one of the \term{atomic type specifiers}
  961. \typeref{short-float},
  962. \typeref{single-float},
  963. \typeref{double-float},
  964. or \typeref{long-float},
  965. or else some other \term{type specifier} defined
  966. by the \term{implementation} to be acceptable.
  967. \label Initial Value::
  968. The \term{symbol} \typeref{single-float}.
  969. \label Description::
  970. %% 22.2.1 12
  971. Controls the floating-point format that is to be used when reading a
  972. floating-point number that has no \term{exponent marker} or that has
  973. \f{e} or \f{E} for an \term{exponent marker}. Other \term{exponent markers}
  974. explicitly prescribe the floating-point format to be used.
  975. The printer uses \varref{*read-default-float-format*} to guide the
  976. choice of \term{exponent markers} when printing floating-point numbers.
  977. \label Examples::
  978. \code
  979. (let ((*read-default-float-format* 'double-float))
  980. (read-from-string "(1.0 1.0e0 1.0s0 1.0f0 1.0d0 1.0L0)"))
  981. \EV (1.0 1.0 1.0 1.0 1.0 1.0) ;Implementation has float format F.
  982. \EV (1.0 1.0 1.0s0 1.0 1.0 1.0) ;Implementation has float formats S and F.
  983. \EV (1.0d0 1.0d0 1.0 1.0 1.0d0 1.0d0) ;Implementation has float formats F and D.
  984. \EV (1.0d0 1.0d0 1.0s0 1.0 1.0d0 1.0d0) ;Implementation has float formats S, F, D.
  985. \EV (1.0d0 1.0d0 1.0 1.0 1.0d0 1.0L0) ;Implementation has float formats F, D, L.
  986. \EV (1.0d0 1.0d0 1.0s0 1.0 1.0d0 1.0L0) ;Implementation has formats S, F, D, L.
  987. \endcode
  988. \label Affected By:\None.
  989. \label See Also:\None.
  990. \label Notes:\None.
  991. \endcom
  992. %%% ========== *READ-EVAL*
  993. \begincom{*read-eval*}\ftype{Variable}
  994. \issue{DATA-IO:ADD-SUPPORT}
  995. \label Value Type::
  996. a \term{generalized boolean}.
  997. \label Initial Value::
  998. \term{true}.
  999. \label Description::
  1000. If it is \term{true}, the \f{\#.} \term{reader macro} has its normal effect.
  1001. Otherwise, that \term{reader macro} signals an error \oftype{reader-error}.
  1002. \label Examples:\None.
  1003. \label Affected By:\None.
  1004. \label See Also::
  1005. \varref{*print-readably*}
  1006. \label Notes::
  1007. If \varref{*read-eval*} is \term{false} and \varref{*print-readably*} is \term{true},
  1008. any \term{method} for \funref{print-object} that would output a reference
  1009. to the \f{\#.} \term{reader macro} either outputs something different
  1010. or signals an error \oftype{print-not-readable}.
  1011. \endissue{DATA-IO:ADD-SUPPORT}
  1012. \endcom
  1013. %%% ========== *READ-SUPPRESS*
  1014. \begincom{*read-suppress*}\ftype{Variable}
  1015. \label Value Type::
  1016. a \term{generalized boolean}.
  1017. \label Initial Value::
  1018. \term{false}.
  1019. \label Description::
  1020. %% 22.1.2 25
  1021. This variable is intended primarily to support the operation of the
  1022. read-time conditional notations \f{\#+} and \f{\#-}. It is important for the
  1023. \term{reader macros} which implement these notations
  1024. to be able to skip over the printed representation of an
  1025. \term{expression} despite the possibility that the syntax of the skipped
  1026. \term{expression} may not be entirely valid for the current implementation,
  1027. since \f{\#+} and \f{\#-} exist in order to allow the same program to be
  1028. shared among several \Lisp\ implementations (including dialects other than \clisp)
  1029. despite small incompatibilities of syntax.
  1030. %% 22.1.2 24
  1031. %% 22.1.2 26
  1032. If it is \term{false}, the \term{Lisp reader} operates normally.
  1033. \issue{READ-SUPPRESS-CONFUSING:GENERALIZE}
  1034. % Otherwise, many of the normal operations of the \term{Lisp reader}
  1035. % are suppressed; specifically:
  1036. %
  1037. % %% 22.1.2 27
  1038. % \beginlist
  1039. % \itemitem{Extended tokens}
  1040. %
  1041. % An extended token is discarded and treated as if it were \nil;
  1042. % that is, reading an extended token when \varref{*read-suppress*} is \term{true} returns \nil.
  1043. %
  1044. % %% 22.1.2 28
  1045. % \itemitem{\f{\#}}
  1046. %
  1047. % Any standard \f{\#} \term{dispatching macro character} notation
  1048. % that requires, permits, or disallows an infix numerical argument,
  1049. % such as \f{\#\i{n}R}, does not enforce any constraint on the presence,
  1050. % absence, or value of such an argument.
  1051. %
  1052. % %% 22.1.2 29
  1053. % \itemitem{\tt \#\\}
  1054. %
  1055. % The \f{\#\\} notation parses as \nil.
  1056. % It does not signal an error even if an unknown character name is seen.
  1057. %
  1058. % %% 22.1.2 30
  1059. % \itemitem{\tt \#B, \#O, \#X, \#R}
  1060. %
  1061. % Each of the \f{\#B}, \f{\#O}, \f{\#X}, and \f{\#R} notations
  1062. % scans over a following token and produces the value \nil.
  1063. % None of these notations signals an error
  1064. % even if the token does not have the syntax of a rational number.
  1065. %
  1066. % %% 22.1.2 31
  1067. % \itemitem{\f{\#*}}
  1068. %
  1069. % \issue{SHARP-STAR-DELIMITER:NORMAL-DELIMITER}
  1070. % The \f{\#*} notation scans a (possibly null) token until a normal delimiter appears
  1071. % and produces the value \nil. It does not signal an error even if the token
  1072. % contains characters other of the characters \f{0} and \f{1}, or is of the wrong length.
  1073. % \endissue{SHARP-STAR-DELIMITER:NORMAL-DELIMITER}
  1074. %
  1075. % %% 22.1.2 32
  1076. % \issue{SHARP-COMMA-CONFUSION:REMOVE}
  1077. % \itemitem{\tt \#.}
  1078. %
  1079. % The \f{\#.} notation reads the following \term{object} in
  1080. % suppressed mode but does not evaluate it.
  1081. % The \term{object} is discarded and \nil\ is produced.
  1082. % \endissue{SHARP-COMMA-CONFUSION:REMOVE}
  1083. %
  1084. % %% 22.1.2 33
  1085. % \itemitem{\tt \#A, \#C, \#S, \#:}
  1086. %
  1087. % Each of the \f{\#A}, \f{\#C}, \f{\#S}, and \f{\#:} notations reads the following
  1088. % \term{object} in suppressed mode but does not interpret it in any way;
  1089. % it need not even be a \term{list} in the case of \f{\#C} or \f{\#S}, or a
  1090. % \term{symbol} in the case of \f{\#:}. The \term{object} is
  1091. % discarded and \nil\ is produced.
  1092. If \thevalueof{*read-suppress*} is \term{true},
  1093. \funref{read},
  1094. \funref{read-preserving-whitespace},
  1095. \funref{read-delimited-list},
  1096. and \funref{read-from-string}
  1097. all return a \term{primary value} of \nil\ when they complete successfully;
  1098. however, they continue to parse the representation of an \term{object}
  1099. in the normal way, in order to skip over the \term{object},
  1100. and continue to indicate \term{end of file} in the normal way.
  1101. Except as noted below,
  1102. any \term{standardized} \term{reader macro}\meaning{2}
  1103. that is defined to \term{read}\meaning{2}
  1104. a following \term{object} or \term{token}
  1105. will do so,
  1106. but not signal an error if the \term{object}
  1107. read is not of an appropriate type or syntax.
  1108. The \term{standard syntax} and its associated \term{reader macros}
  1109. will not construct any new \term{objects}
  1110. (\eg when reading the representation of a \term{symbol},
  1111. no \term{symbol} will be constructed or interned).
  1112. %% 22.1.2 27
  1113. \beginlist
  1114. %% The cleanup issue did not ask me to put this entry for Extended
  1115. %% Tokens here, but people have complained to me personally that this
  1116. %% passage (present in CLtL1) was omitted in the dpANS and that they
  1117. %% were worried that these items were not guaranteed. I believe that
  1118. %% issue READ-SUPPRESS-CONFUSING asks to omit this information because
  1119. %% it thinks it is redundant, not because it thinks it is incorrect.
  1120. %% But I disagree on the redundancy issue, so I am ignoring it and
  1121. %% including this data regardless. Refer to p345 of CLtL1 for
  1122. %% supporting documentation. -kmp 23-Aug-93
  1123. \itemitem{Extended tokens}
  1124. All extended tokens are completely uninterpreted.
  1125. Errors such as those that might otherwise be signaled due to
  1126. detection of invalid \term{potential numbers},
  1127. invalid patterns of \term{package markers},
  1128. and invalid uses of the \term{dot} character are suppressed.
  1129. \itemitem{Dispatching macro characters (including \term{sharpsign})}
  1130. \term{Dispatching macro characters} continue to parse an infix numerical
  1131. argument, and invoke the dispatch function. The \term{standardized}
  1132. \term{sharpsign} \term{reader macros} do not enforce any constraints
  1133. on either the presence of or the value of the numerical argument.
  1134. \endissue{READ-SUPPRESS-CONFUSING:GENERALIZE}
  1135. %% 22.1.2 34
  1136. \itemitem{\tt \#=}
  1137. The \f{\#=} notation is totally ignored. It does not read
  1138. a following \term{object}. It produces no \term{object},
  1139. but is treated as \term{whitespace}\meaning{2}.
  1140. %% 22.1.2 35
  1141. \itemitem{\tt \#\#}
  1142. The \f{\#\#} notation always produces \nil.
  1143. \endlist
  1144. No matter what \thevalueof{*read-suppress*},
  1145. parentheses still continue to delimit and construct \term{lists};
  1146. the \f{\#(} notation continues to delimit \term{vectors};
  1147. and comments, \term{strings},
  1148. and the \term{single-quote} and \term{backquote} notations continue to be
  1149. interpreted properly. Such situations as
  1150. \f{')}, \f{\#<}, % (
  1151. \f{\#)}, and \f{\#\SpaceChar} continue to signal errors.
  1152. \label Examples::
  1153. \issue{READ-SUPPRESS-CONFUSING:GENERALIZE}
  1154. % \code
  1155. % (let ((*read-suppress* t))
  1156. % (dotimes (i 4)
  1157. % (format t "~&input here> ")
  1158. % (format t "~&parsed as: ~S~%" (read))))
  1159. % \OUT input here> 101
  1160. % \OUT parsed as: NIL
  1161. % \OUT input here> (#\\a :test)
  1162. % \OUT parsed as: (NIL NIL)
  1163. % \OUT input here> '("xyz" #(a b c))
  1164. % \OUT parsed as: (QUOTE ("xyz" #(NIL NIL NIL)))
  1165. % \OUT input here> (list 1 2 '3)
  1166. % \OUT parsed as: (NIL NIL NIL (QUOTE NIL))
  1167. % \EV NIL
  1168. % \endcode
  1169. \code
  1170. (let ((*read-suppress* t))
  1171. (mapcar #'read-from-string
  1172. '("#(foo bar baz)" "#P(:type :lisp)" "#c1.2"
  1173. "#.(PRINT 'FOO)" "#3AHELLO" "#S(INTEGER)"
  1174. "#*ABC" "#\\GARBAGE" "#RALPHA" "#3R444")))
  1175. \EV (NIL NIL NIL NIL NIL NIL NIL NIL NIL NIL)
  1176. \endcode
  1177. \endissue{READ-SUPPRESS-CONFUSING:GENERALIZE}
  1178. \label Affected By:\None.
  1179. \label See Also::
  1180. \funref{read},
  1181. {\chapref\Syntax}
  1182. \label Notes::
  1183. \issue{READ-SUPPRESS-CONFUSING:GENERALIZE}
  1184. \term{Programmers} and \term{implementations} that define additional
  1185. \term{macro characters} are strongly encouraged to make them respect
  1186. \varref{*read-suppress*} just as \term{standardized} \term{macro characters} do.
  1187. That is, when \thevalueof{*read-suppress*} is \term{true},
  1188. they should ignore type errors when reading a following \term{object}
  1189. and the \term{functions} that implement \term{dispatching macro characters}
  1190. should tolerate \nil\ as their infix \term{parameter} value even if a numeric
  1191. value would ordinarily be required.
  1192. \endissue{READ-SUPPRESS-CONFUSING:GENERALIZE}
  1193. \endcom
  1194. %%% ========== *READTABLE*
  1195. \begincom{*readtable*}\ftype{Variable}
  1196. \label Value Type::
  1197. a \term{readtable}.
  1198. \label Initial Value::
  1199. A \term{readtable} that conforms to the description of \clisp\ syntax in \chapref\Syntax.
  1200. \label Description::
  1201. %% 22.1.5 4
  1202. \Thevalueof{*readtable*} is called the \term{current readtable}.
  1203. It controls the parsing behavior of the \term{Lisp reader},
  1204. and can also influence the \term{Lisp printer} (\eg \seefun{readtable-case}).
  1205. \label Examples::
  1206. %!!! This example needs work.
  1207. \code
  1208. (readtablep *readtable*) \EV \term{true}
  1209. (setq zvar 123) \EV 123
  1210. (set-syntax-from-char #\\z #\\' (setq table2 (copy-readtable))) \EV T
  1211. zvar \EV 123
  1212. (setq *readtable* table2) \EV #<READTABLE>
  1213. zvar \EV VAR
  1214. (setq *readtable* (copy-readtable nil)) \EV #<READTABLE>
  1215. zvar \EV 123
  1216. \endcode
  1217. \label Affected By::
  1218. \funref{compile-file},
  1219. \funref{load}
  1220. \label See Also::
  1221. \funref{compile-file},
  1222. \funref{load},
  1223. \funref{readtable},
  1224. {\secref\CurrentReadtable}
  1225. \label Notes:\None.
  1226. \endcom
  1227. %%% ========== READER-ERROR
  1228. \begincom{reader-error}\ftype{Condition Type}
  1229. \issue{PARSE-ERROR-STREAM:SPLIT-TYPES}
  1230. \label Class Precedence List::
  1231. \typeref{reader-error},
  1232. \typeref{parse-error},
  1233. \typeref{stream-error},
  1234. \typeref{error},
  1235. \typeref{serious-condition},
  1236. \typeref{condition},
  1237. \typeref{t}
  1238. \label Description::
  1239. \Thetype{reader-error} consists of
  1240. error conditions that are related to tokenization and parsing
  1241. done by the \term{Lisp reader}.
  1242. \label See Also::
  1243. \funref{read},
  1244. \funref{stream-error-stream},
  1245. {\secref\ReaderConcepts}
  1246. \endissue{PARSE-ERROR-STREAM:SPLIT-TYPES}
  1247. \endcom%{reader-error}\ftype{Condition Type}