concept-print.tex 40 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085
  1. % -*- Mode: TeX -*-
  2. \beginsubsection{Overview of The Lisp Printer}
  3. %% 22.1.0 1
  4. \clisp\ provides a representation of most \term{objects} in the form
  5. of printed text called the printed representation.
  6. Functions such as \funref{print} take an \term{object}
  7. and send the characters of its printed representation to a \term{stream}.
  8. The collection of routines that does this is known as the (\clisp) printer.
  9. %% 22.1.0 2
  10. Reading a printed representation
  11. %Added qualifier, since clearly this is just rule of thumb.
  12. %e.g., Waters complained that this is mostly only true for `simple things'
  13. typically
  14. produces an \term{object} that is \funref{equal} to the
  15. originally printed \term{object}.
  16. \beginsubsubsection{Multiple Possible Textual Representations}
  17. %% 22.1.0 3
  18. Most \term{objects} have more than one possible textual representation.
  19. For example, the positive \term{integer} with a magnitude of twenty-seven
  20. can be textually expressed in any of these ways:
  21. \code
  22. 27 27. #o33 #x1B #b11011 #.(* 3 3 3) 81/3
  23. \endcode
  24. A list containing the two symbols \f{A} and \f{B} can also be textually
  25. expressed in a variety of ways:
  26. \code
  27. (A B) (a b) ( a b ) (\\A |B|)
  28. (|\\A|
  29. B
  30. )
  31. \endcode
  32. In general,
  33. \issue{PRINTER-WHITESPACE:JUST-ONE-SPACE}
  34. %% Added extra constraint about reader to make it clear that we aren't
  35. %% trying to override other printer behavior specified elsewhere.
  36. %% -kmp 22-Aug-93
  37. from the point of view of the \term{Lisp reader},
  38. \endissue{PRINTER-WHITESPACE:JUST-ONE-SPACE}
  39. wherever \term{whitespace} is permissible in a textual representation,
  40. any number of \term{spaces} and \term{newlines} can appear in \term{standard syntax}.
  41. %% 22.1.0 4
  42. When a function such as \funref{print} produces a printed representation,
  43. it must choose
  44. %% It's not totally arbitrary! -kmp 22-Aug-93
  45. %arbitrarily
  46. from among many possible textual representations.
  47. In most cases, it chooses a
  48. %Waters thought this meant human-readable, so I added the qualifier "program",
  49. %and then some exposition which follows here. -kmp 11-Feb-91
  50. program readable representation,
  51. but in certain cases it might use a more compact notation that is not
  52. program-readable.
  53. A number of option variables, called
  54. \newtermidx{printer control variables}{printer control variable},
  55. are provided to permit control of individual aspects of the
  56. printed representation of \term{objects}.
  57. \Thenextfigure\ shows the \term{standardized} \term{printer control variables};
  58. there might also be \term{implementation-defined} \term{printer control variables}.
  59. \DefineFigure{StdPrinterControlVars}
  60. \displaythree{Standardized Printer Control Variables}{
  61. *print-array*&*print-gensym*&*print-pprint-dispatch*\cr
  62. *print-base*&*print-length*&*print-pretty*\cr
  63. *print-case*&*print-level*&*print-radix*\cr
  64. *print-circle*&*print-lines*&*print-readably*\cr
  65. *print-escape*&*print-miser-width*&*print-right-margin*\cr
  66. }
  67. In addition to the \term{printer control variables},
  68. the following additional \term{defined names}
  69. relate to or affect the behavior of the \term{Lisp printer}:
  70. \displaythree{Additional Influences on the Lisp printer.}{
  71. *package*&*read-eval*&readtable-case\cr
  72. *read-default-float-format*&*readtable*&\cr
  73. }
  74. \beginsubsubsubsection{Printer Escaping}
  75. \Thevariable{*print-escape*} controls whether the \term{Lisp printer}
  76. tries to produce notations such as escape characters and package prefixes.
  77. \Thevariable{*print-readably*} can be used to override
  78. many of the individual aspects controlled by the other
  79. \term{printer control variables} when program-readable output
  80. is especially important.
  81. \issue{PRINT-READABLY-BEHAVIOR:CLARIFY}
  82. One of the many effects of making \thevalueof{*print-readably*} be \term{true}
  83. is that the \term{Lisp printer} behaves as if \varref{*print-escape*} were also \term{true}.
  84. For notational convenience, we say that
  85. if the value of either \varref{*print-readably*} or \varref{*print-escape*} is \term{true},
  86. then \newterm{printer escaping} is ``enabled'';
  87. and we say that
  88. if the values of both \varref{*print-readably*} and \varref{*print-escape*} are \term{false},
  89. then \term{printer escaping} is ``disabled''.
  90. \endissue{PRINT-READABLY-BEHAVIOR:CLARIFY}
  91. \endsubsubsubsection%{Printer Escaping}
  92. \endsubsubsection%{Multiple Possible Textual Representations}
  93. \endsubsection%{Overview of The Lisp Printer}
  94. \beginsubsection{Printer Dispatching}
  95. \DefineSection{PrinterDispatch}
  96. \issue{DEFSTRUCT-PRINT-FUNCTION-AGAIN:X3J13-MAR-93}
  97. % The \term{Lisp printer} makes its determination of how to print an
  98. % \term{object} as follows:
  99. %
  100. % If \thevalueof{*print-pretty*} is \term{true}:
  101. %
  102. % \beginlist
  103. % \item{} Printing is controlled by the \term{pprint dispatch table}
  104. % contained in the variable \varref{*print-pprint-dispatch*};
  105. % \seesection\PPrintDispatchTables.
  106. % \endlist
  107. %
  108. % Otherwise (if \thevalueof{*print-pretty*} is \term{false}):
  109. %
  110. % \beginlist
  111. % \item{} If the \term{object} is a \term{structure} for which a
  112. % \kwd{print-function} option is in effect (either directly or by inheritance),
  113. % that function is used; \seefun{defstruct}.
  114. %
  115. % \item{} Otherwise (if the \term{object} is not a \term{structure} or
  116. % if it is a \term{structure} but has no \kwd{print-function} option in effect),
  117. % its \funref{print-object} method is used; \seesection\DefaultPrintObjMeths.
  118. % \endlist
  119. The \term{Lisp printer} makes its determination of how to print an
  120. \term{object} as follows:
  121. If \thevalueof{*print-pretty*} is \term{true},
  122. printing is controlled by the \term{current pprint dispatch table};
  123. %contained in the variable \varref{*print-pprint-dispatch*};
  124. \seesection\PPrintDispatchTables.
  125. Otherwise (if \thevalueof{*print-pretty*} is \term{false}),
  126. the object's \funref{print-object} method is used;
  127. \seesection\DefaultPrintObjMeths.
  128. \endissue{DEFSTRUCT-PRINT-FUNCTION-AGAIN:X3J13-MAR-93}
  129. \endsubsection%{Printer Dispatching}
  130. \beginsubsection{Default Print-Object Methods}
  131. \DefineSection{DefaultPrintObjMeths}
  132. %% 22.1.6 3
  133. % How an expression is printed depends on its \term{type},
  134. % as described in the following sections.
  135. This section describes the default behavior of
  136. \funref{print-object} methods for the \term{standardized} \term{types}.
  137. \beginsubsubsection{Printing Numbers}
  138. \beginsubsubsubsection{Printing Integers}
  139. \DefineSection{PrintingIntegers}
  140. %% 22.1.6 4
  141. \term{Integers} are printed in the radix specified by the \term{current output base}
  142. in positional notation, most significant digit first.
  143. If appropriate, a radix specifier can be printed; see \varref{*print-radix*}.
  144. If an \term{integer} is negative, a minus sign is printed and then the
  145. absolute value of the \term{integer} is printed.
  146. The \term{integer} zero is represented
  147. by the single digit \f{0} and never has a sign.
  148. A decimal point might be printed,
  149. depending on \thevalueof{*print-radix*}.
  150. For related information about the syntax of an \term{integer},
  151. \seesection\SyntaxOfIntegers.
  152. \endsubsubsubsection%{Printing Integers}
  153. \beginsubsubsubsection{Printing Ratios}
  154. \DefineSection{PrintingRatios}\idxref{ratio}
  155. %% 22.1.6 5
  156. \term{Ratios} are printed as follows:
  157. the absolute value of the numerator is printed, as for an \term{integer};
  158. then a \f{/}; then the denominator. The numerator and denominator are
  159. both printed in the radix specified by the \term{current output base};
  160. they are obtained as if by
  161. \funref{numerator} and \funref{denominator}, and so \term{ratios}
  162. are printed in reduced form (lowest terms).
  163. If appropriate, a radix specifier can be printed; see
  164. \varref{*print-radix*}.
  165. If the ratio is negative, a minus sign is printed before the numerator.
  166. For related information about the syntax of a \term{ratio},
  167. \seesection\SyntaxOfRatios.
  168. \endsubsubsubsection%{Printing Ratios}
  169. \beginsubsubsubsection{Printing Floats}
  170. \DefineSection{PrintingFloats}\idxref{float}
  171. %% 22.1.6 6
  172. If the magnitude of the \term{float} is either zero or between $10^{-3}$ (inclusive)
  173. and $10^7$ (exclusive), it is printed as the integer part of the number,
  174. then a decimal point,
  175. followed by the fractional part of the number;
  176. there is always at least one
  177. digit on each side of the decimal point.
  178. If the sign of the number
  179. (as determined by \funref{float-sign})
  180. is negative, then a minus sign is printed before the number.
  181. If the format of the number
  182. does not match that specified by
  183. \varref{*read-default-float-format*}, then the \term{exponent marker} for
  184. that format and the digit \f{0} are also printed.
  185. For example, the base of the natural logarithms as a \term{short float}
  186. might be printed as \f{2.71828S0}.
  187. %% 22.1.6 7
  188. For non-zero magnitudes outside of the range $10^{-3}$ to $10^7$,
  189. a \term{float} is printed in computerized scientific notation.
  190. The representation of the number is scaled to be between
  191. 1 (inclusive) and 10 (exclusive) and then printed, with one digit
  192. before the decimal point and at least one digit after the decimal point.
  193. Next the \term{exponent marker} for the format is printed,
  194. except that
  195. if the format of the number matches that specified by
  196. \varref{*read-default-float-format*}, then the \term{exponent marker} \f{E}
  197. is used.
  198. Finally, the power of ten by which the fraction must be multiplied
  199. to equal the original number is printed as a decimal integer.
  200. For example, Avogadro's number as a \term{short float}
  201. is printed as \f{6.02S23}.
  202. For related information about the syntax of a \term{float},
  203. \seesection\SyntaxOfFloats.
  204. \endsubsubsubsection%{Printing Floats}
  205. \beginsubsubsubsection{Printing Complexes}
  206. \DefineSection{PrintingComplexes}\idxref{complex}
  207. %% 22.1.6 8
  208. A \term{complex} is printed as \f{\#C}, an open parenthesis,
  209. the printed representation of its real part, a space,
  210. the printed representation of its imaginary part, and finally
  211. a close parenthesis.
  212. For related information about the syntax of a \term{complex},
  213. \seesection\SyntaxOfComplexes\ and \secref\SharpsignC.
  214. \endsubsubsubsection%{Printing Complexes}
  215. \beginsubsubsubsection{Note about Printing Numbers}
  216. The printed representation of a number must not contain \term{escape} \term{characters};
  217. \seesection\EscCharsAndPotentialNums.
  218. \endsubsubsubsection%{Note about Printing Numbers}
  219. \endsubsubsection%{Printing Numbers}
  220. \beginsubsubsection{Printing Characters}
  221. \DefineSection{PrintingCharacters}
  222. %% 22.1.6 9
  223. \issue{PRINT-READABLY-BEHAVIOR:CLARIFY}
  224. %When \varref{*print-escape*} is \term{false},
  225. When \term{printer escaping} is disabled,
  226. \endissue{PRINT-READABLY-BEHAVIOR:CLARIFY}
  227. a \term{character} prints as itself;
  228. it is sent directly to the output \term{stream}.
  229. \issue{PRINT-READABLY-BEHAVIOR:CLARIFY}
  230. %When \varref{*print-escape*} is \term{true},
  231. When \term{printer escaping} is enabled,
  232. \endissue{PRINT-READABLY-BEHAVIOR:CLARIFY}
  233. then \f{\#\\} syntax is used.
  234. %% 22.1.4 16
  235. %% Some wording clarifications here per Loosemore #16 (first public review). -kmp 15-May-93
  236. When the printer types out the name of a \term{character},
  237. it uses the same table as the \f{\#\\} \term{reader macro} would use;
  238. therefore any \term{character} name that is typed out
  239. is acceptable as input (in that \term{implementation}).
  240. If a \term{non-graphic} \term{character} has a \term{standardized} \term{name}\meaning{5},
  241. that \term{name} is preferred over non-standard \term{names}
  242. for printing in \f{\#\\} notation.
  243. For the \term{graphic} \term{standard characters},
  244. the \term{character} itself is always used
  245. for printing in \f{\#\\} notation---even if
  246. the \term{character} also has a \term{name}\meaning{5}.
  247. For details about the \f{\#\\} \term{reader macro}, \seesection\SharpsignBackslash.
  248. \endsubsubsection%{Printing Characters}
  249. \beginsubsubsection{Printing Symbols}
  250. \DefineSection{PrintingSymbols}
  251. %% 22.1.6 10
  252. %!!! Is this affected by READ-CASE-SENSITIVITY? -kmp 14-May-91
  253. \issue{PRINT-READABLY-BEHAVIOR:CLARIFY}
  254. %When \varref{*print-escape*} is \term{false},
  255. When \term{printer escaping} is disabled,
  256. \endissue{PRINT-READABLY-BEHAVIOR:CLARIFY}
  257. only the characters of the \term{symbol}'s \term{name} are output
  258. % 22.1.6 17
  259. \issue{PRINT-CASE-BEHAVIOR:CLARIFY}
  260. %(but the case in which to print any uppercase characters in the \term{name} is
  261. %controlled by \thevariable{*print-case*}).
  262. (but the case in which to print characters in the \term{name} is
  263. controlled by \varref{*print-case*};
  264. \seesection\ReadtableCasePrintEffect).
  265. \endissue{PRINT-CASE-BEHAVIOR:CLARIFY}
  266. %% 22.1.6 11
  267. The remainder of \thissection\ applies only
  268. \issue{PRINT-READABLY-BEHAVIOR:CLARIFY}
  269. %when \varref{*print-escape*} is \term{true}.
  270. when \term{printer escaping} is enabled.
  271. \endissue{PRINT-READABLY-BEHAVIOR:CLARIFY}
  272. %% 22.1.6 12
  273. \issue{SYMBOL-PRINT-ESCAPE-BEHAVIOR:CLARIFY}
  274. % \term{Backslashes} and \term{vertical-bars} are included as required.
  275. % The \term{current output base} at the time of printing might be relevant.
  276. % For example, if \thevalueof{*print-base*} were \f{16}
  277. % when printing the symbol \f{face}, it would have to be printed as
  278. % \f{\\FACE} or \f{\\Face} or \f{|FACE|},
  279. % because the token \f{face} would be read as a hexadecimal
  280. % number (decimal value 64206) if \thevalueof{*read-base*} were \f{16}.
  281. When printing a \term{symbol}, the printer inserts enough
  282. \term{single escape} and/or \term{multiple escape}
  283. characters (\term{backslashes} and/or \term{vertical-bars}) so that if
  284. \funref{read} were called with the same \varref{*readtable*} and
  285. with \varref{*read-base*} bound to the \term{current output base}, it
  286. would return the same \term{symbol} (if it is not
  287. \term{apparently uninterned}) or an \term{uninterned} \term{symbol}
  288. with the same \term{print name} (otherwise).
  289. For example, if \thevalueof{*print-base*} were \f{16}
  290. when printing the symbol \f{face}, it would have to be printed as
  291. \f{\\FACE} or \f{\\Face} or \f{|FACE|},
  292. because the token \f{face} would be read as a hexadecimal
  293. number (decimal value 64206) if \thevalueof{*read-base*} were \f{16}.
  294. For additional restrictions concerning characters with nonstandard
  295. \term{syntax types} in the \term{current readtable}, \seevar{*print-readably*}
  296. \endissue{SYMBOL-PRINT-ESCAPE-BEHAVIOR:CLARIFY}
  297. For information about how the \term{Lisp reader} parses \term{symbols},
  298. \seesection\SymbolTokens\ and \secref\SharpsignColon.
  299. %!!! Somewhat redundant with what's above--also, is this also affected
  300. % by READ-CASE-SENSITIVITY? -kmp 14-May-91
  301. %% 22.1.6 13
  302. % already said above. --sjl 16 Mar 92
  303. %The case in which to print any uppercase characters in the \term{symbol}'s \term{name} is
  304. %controlled by \varref{*print-case*}.
  305. \nil\ might be printed as \f{()}
  306. \issue{PRINT-READABLY-BEHAVIOR:CLARIFY}
  307. %when \varref{*print-escape*} and \varref{*print-pretty*} are both \term{true}.
  308. when \varref{*print-pretty*} is \term{true}
  309. and \term{printer escaping} is enabled.
  310. \endissue{PRINT-READABLY-BEHAVIOR:CLARIFY}
  311. \beginsubsubsubsection{Package Prefixes for Symbols}
  312. %% 22.1.6 14
  313. %% 11.0.0 28
  314. \term{Package prefixes} are printed if necessary.
  315. The rules for \term{package prefixes} are as follows.
  316. When the \term{symbol} is printed, if it is in \thepackage{keyword},
  317. % should this be ``colon'' or ``package marker''? --sjl 16 Mar 92
  318. then it is printed with a preceding \term{colon}; otherwise, if
  319. it is \term{accessible} in the \term{current package}, it is printed without any
  320. \term{package prefix}; otherwise, it is printed with a \term{package prefix}.
  321. %% 22.1.6 15
  322. A \term{symbol} that is \term{apparently uninterned} is printed
  323. preceded by ``\f{\#:}''
  324. \issue{PRINT-READABLY-BEHAVIOR:CLARIFY}
  325. % if \varref{*print-gensym*} and \varref{*print-escape*} are both \term{non-nil};
  326. % if either is \nil,
  327. if \varref{*print-gensym*} is \term{true} and \term{printer escaping} is enabled;
  328. if \varref{*print-gensym*} is \term{false} or \term{printer escaping} is disabled,
  329. \endissue{PRINT-READABLY-BEHAVIOR:CLARIFY}
  330. then the \term{symbol} is printed without a prefix,
  331. as if it were in the \term{current package}.
  332. %% 22.1.6 16
  333. Because the \f{\#:} syntax does not intern the
  334. following symbol, it is necessary to use circular-list syntax
  335. if \varref{*print-circle*} is \term{true} and
  336. the same uninterned symbol appears several times in an expression
  337. to be printed. For example, the result of
  338. \code
  339. (let ((x (make-symbol "FOO"))) (list x x))
  340. \endcode
  341. would be printed as \f{(\#:foo \#:foo)} if \varref{*print-circle*}
  342. were \term{false}, but as \f{(\#1=\#:foo \#1\#)} if \varref{*print-circle*}
  343. were \term{true}.
  344. A summary of the preceding package prefix rules follows:
  345. \beginlist
  346. \itemitem{\f{foo:bar}}
  347. \f{foo:bar} is printed when \term{symbol} \f{bar}
  348. is external in its \term{home package} \f{foo}
  349. and is not \term{accessible} in the \term{current package}.
  350. \itemitem{\f{foo::bar}}
  351. \f{foo::bar} is printed when \f{bar} is internal in its \term{home package}
  352. \f{foo} and is not \term{accessible} in the \term{current package}.
  353. \itemitem{\f{:bar}}
  354. \f{:bar} is printed when the home package of \f{bar} is \thepackage{keyword}.
  355. \itemitem{\tt \#:bar}
  356. \f{\#:bar} is printed when \f{bar} is \term{apparently uninterned},
  357. even in the pathological case that \f{bar}
  358. has no \term{home package} but is nevertheless somehow \term{accessible}
  359. in the \term{current package}.
  360. \endlist
  361. % Waters points out that this was already said above.
  362. % %% 22.1.6 17
  363. % The case in which symbols are printed is controlled by
  364. % \varref{*print-case*}.
  365. \endsubsubsubsection%{Package Prefixes for Symbols}
  366. \beginsubsubsubsection{Effect of Readtable Case on the Lisp Printer}
  367. \DefineSection{ReadtableCasePrintEffect}
  368. \issue{PRINT-CASE-BEHAVIOR:CLARIFY}
  369. % When \term{escape} syntax is not being used,
  370. When
  371. %both \varref{*print-escape*} and \varref{*print-readably*} are \term{false},
  372. \term{printer escaping} is disabled,
  373. or the characters under consideration are not already
  374. quoted specifically by \term{single escape} or \term{multiple escape}
  375. syntax,
  376. \endissue{PRINT-CASE-BEHAVIOR:CLARIFY}
  377. the \term{readtable case} of the \term{current readtable}
  378. affects the way the \term{Lisp printer} writes \term{symbols}
  379. in the following ways:
  380. \beginlist
  381. \itemitem{\kwd{upcase}}
  382. When the \term{readtable case} is \kwd{upcase},
  383. \term{uppercase} \term{characters}
  384. are printed in the case specified by \varref{*print-case*}, and
  385. \term{lowercase} \term{characters} are printed in their own case.
  386. \itemitem{\kwd{downcase}}
  387. When the \term{readtable case} is \kwd{downcase},
  388. \term{uppercase} \term{characters} are printed in their own case, and
  389. \term{lowercase} \term{characters}
  390. are printed in the case specified by \varref{*print-case*}.
  391. \itemitem{\kwd{preserve}}
  392. When the \term{readtable case} is \kwd{preserve},
  393. all \term{alphabetic} \term{characters} are printed in their own case.
  394. \itemitem{\kwd{invert}}
  395. When the \term{readtable case} is \kwd{invert},
  396. the case of all \term{alphabetic} \term{characters}
  397. in single case symbol names is inverted.
  398. Mixed-case symbol names are printed as is.
  399. \endlist
  400. The rules for escaping \term{alphabetic} \term{characters} in symbol names are affected by
  401. the \funref{readtable-case}
  402. \issue{PRINT-READABLY-BEHAVIOR:CLARIFY}
  403. %if \varref{*print-escape*} is \term{true}.
  404. if \term{printer escaping} is enabled.
  405. \endissue{PRINT-READABLY-BEHAVIOR:CLARIFY}
  406. \term{Alphabetic} \term{characters} are escaped as follows:
  407. \beginlist
  408. \itemitem{\kwd{upcase}}
  409. When the \term{readtable case} is \kwd{upcase},
  410. all \term{lowercase} \term{characters} must be escaped.
  411. \itemitem{\kwd{downcase}}
  412. When the \term{readtable case} is \kwd{downcase},
  413. all \term{uppercase} \term{characters} must be escaped.
  414. \itemitem{\kwd{preserve}}
  415. When the \term{readtable case} is \kwd{preserve},
  416. no \term{alphabetic} \term{characters} need be escaped.
  417. \itemitem{\kwd{invert}}
  418. When the \term{readtable case} is \kwd{invert},
  419. no \term{alphabetic} \term{characters} need be escaped.
  420. \endlist
  421. \beginsubsubsubsubsection{Examples of Effect of Readtable Case on the Lisp Printer}
  422. \DefineSection{ReadtableCasePrintExamples}
  423. \code
  424. (defun test-readtable-case-printing ()
  425. (let ((*readtable* (copy-readtable nil))
  426. (*print-case* *print-case*))
  427. (format t "READTABLE-CASE *PRINT-CASE* Symbol-name Output~
  428. ~%--------------------------------------------------~
  429. ~%")
  430. (dolist (readtable-case '(:upcase :downcase :preserve :invert))
  431. (setf (readtable-case *readtable*) readtable-case)
  432. (dolist (print-case '(:upcase :downcase :capitalize))
  433. (dolist (symbol '(|ZEBRA| |Zebra| |zebra|))
  434. (setq *print-case* print-case)
  435. (format t "~&:~A~15T:~A~29T~A~42T~A"
  436. (string-upcase readtable-case)
  437. (string-upcase print-case)
  438. (symbol-name symbol)
  439. (prin1-to-string symbol)))))))
  440. \endcode
  441. The output from \f{(test-readtable-case-printing)} should be as follows:
  442. \code
  443. READTABLE-CASE *PRINT-CASE* Symbol-name Output
  444. --------------------------------------------------
  445. :UPCASE :UPCASE ZEBRA ZEBRA
  446. :UPCASE :UPCASE Zebra |Zebra|
  447. :UPCASE :UPCASE zebra |zebra|
  448. :UPCASE :DOWNCASE ZEBRA zebra
  449. :UPCASE :DOWNCASE Zebra |Zebra|
  450. :UPCASE :DOWNCASE zebra |zebra|
  451. :UPCASE :CAPITALIZE ZEBRA Zebra
  452. :UPCASE :CAPITALIZE Zebra |Zebra|
  453. :UPCASE :CAPITALIZE zebra |zebra|
  454. :DOWNCASE :UPCASE ZEBRA |ZEBRA|
  455. :DOWNCASE :UPCASE Zebra |Zebra|
  456. :DOWNCASE :UPCASE zebra ZEBRA
  457. :DOWNCASE :DOWNCASE ZEBRA |ZEBRA|
  458. :DOWNCASE :DOWNCASE Zebra |Zebra|
  459. :DOWNCASE :DOWNCASE zebra zebra
  460. :DOWNCASE :CAPITALIZE ZEBRA |ZEBRA|
  461. :DOWNCASE :CAPITALIZE Zebra |Zebra|
  462. :DOWNCASE :CAPITALIZE zebra Zebra
  463. :PRESERVE :UPCASE ZEBRA ZEBRA
  464. :PRESERVE :UPCASE Zebra Zebra
  465. :PRESERVE :UPCASE zebra zebra
  466. :PRESERVE :DOWNCASE ZEBRA ZEBRA
  467. :PRESERVE :DOWNCASE Zebra Zebra
  468. :PRESERVE :DOWNCASE zebra zebra
  469. :PRESERVE :CAPITALIZE ZEBRA ZEBRA
  470. :PRESERVE :CAPITALIZE Zebra Zebra
  471. :PRESERVE :CAPITALIZE zebra zebra
  472. :INVERT :UPCASE ZEBRA zebra
  473. :INVERT :UPCASE Zebra Zebra
  474. :INVERT :UPCASE zebra ZEBRA
  475. :INVERT :DOWNCASE ZEBRA zebra
  476. :INVERT :DOWNCASE Zebra Zebra
  477. :INVERT :DOWNCASE zebra ZEBRA
  478. :INVERT :CAPITALIZE ZEBRA zebra
  479. :INVERT :CAPITALIZE Zebra Zebra
  480. :INVERT :CAPITALIZE zebra ZEBRA
  481. \endcode
  482. \endsubsubsubsubsection%{Examples of Effect of Readtable Case on the Lisp Printer}
  483. \endsubsubsubsection%{Effect of Readtable Case on the Lisp Printer}
  484. \endsubsubsection%{Printing Symbols}
  485. \beginsubsubsection{Printing Strings}
  486. \DefineSection{PrintingStrings}
  487. %% 22.1.6 18
  488. The characters of the \term{string} are output in order.
  489. \issue{PRINT-READABLY-BEHAVIOR:CLARIFY}
  490. %If \varref{*print-escape*} is \term{true},
  491. If \term{printer escaping} is enabled,
  492. \endissue{PRINT-READABLY-BEHAVIOR:CLARIFY}
  493. a \term{double-quote} is output before and after, and all
  494. \term{double-quotes} and \term{single escapes} are preceded by \term{backslash}.
  495. The printing of \term{strings} is not affected by \varref{*print-array*}.
  496. Only the \term{active} \term{elements} of the \term{string} are printed.
  497. For information on how the \term{Lisp reader} parses \term{strings},
  498. \seesection\Doublequote.
  499. \endsubsubsection%{Printing Strings}
  500. \beginsubsubsection{Printing Lists and Conses}
  501. \DefineSection{PrintingListsAndConses}
  502. %% 22.1.6 19
  503. Wherever possible, list notation is preferred over dot notation.
  504. Therefore the following algorithm is used to print a \term{cons} $x$:
  505. \goodbreak
  506. \beginlist
  507. \item{1.} A \term{left-parenthesis} is printed.
  508. \medbreak
  509. \item{2.} The \term{car} of $x$ is printed.
  510. \medbreak
  511. \item{3.} If the \term{cdr} of $x$ is itself a \term{cons},
  512. it is made to be the current \term{cons}
  513. (\ie $x$ becomes that \term{cons}),
  514. \issue{PRINT-WHITESPACE:JUST-ONE-SPACE}
  515. a \term{space}
  516. % \term{whitespace}\meaning{1}
  517. \endissue{PRINT-WHITESPACE:JUST-ONE-SPACE}
  518. is printed,
  519. and step 2 is re-entered.
  520. \medbreak
  521. \item{4.} If the \term{cdr} of $x$ is not \term{null},
  522. \issue{PRINT-WHITESPACE:JUST-ONE-SPACE}
  523. a \term{space},
  524. % \term{whitespace}\meaning{1},
  525. \endissue{PRINT-WHITESPACE:JUST-ONE-SPACE}
  526. a \term{dot},
  527. \issue{PRINT-WHITESPACE:JUST-ONE-SPACE}
  528. a \term{space},
  529. % \term{whitespace}\meaning{1},
  530. \endissue{PRINT-WHITESPACE:JUST-ONE-SPACE}
  531. and the \term{cdr} of $x$ are printed.
  532. \medbreak
  533. \item{5.} A \term{right-parenthesis} is printed.
  534. \endlist
  535. \issue{PRINT-WHITESPACE:JUST-ONE-SPACE}
  536. Actually, the above algorithm is only used when \varref{*print-pretty*}
  537. is \term{false}. When \varref{*print-pretty*} is \term{true} (or
  538. when \funref{pprint} is used),
  539. additional \term{whitespace}\meaning{1}
  540. may replace the use of a single \term{space},
  541. and a more elaborate algorithm with similar goals but more presentational
  542. flexibility is used; \seesection\PrinterDispatch.
  543. \endissue{PRINT-WHITESPACE:JUST-ONE-SPACE}
  544. %% 2.4.0 6
  545. %% 22.1.6 20
  546. Although the two expressions below are equivalent,
  547. and the reader accepts
  548. either one and
  549. %% Per X3J13. -kmp 05-Oct-93
  550. %produce
  551. produces
  552. the same \term{cons}, the printer
  553. always prints such a \term{cons} in the second form.
  554. \code
  555. (a . (b . ((c . (d . nil)) . (e . nil))))
  556. (a b (c d) e)
  557. \endcode
  558. The printing of \term{conses} is affected by \varref{*print-level*},
  559. \varref{*print-length*}, and \varref{*print-circle*}.
  560. \goodbreak
  561. Following are examples of printed representations of \term{lists}:
  562. \code
  563. (a . b) ;A dotted pair of a and b
  564. (a.b) ;A list of one element, the symbol named a.b
  565. (a. b) ;A list of two elements a. and b
  566. (a .b) ;A list of two elements a and .b
  567. (a b . c) ;A dotted list of a and b with c at the end; two conses
  568. .iot ;The symbol whose name is .iot
  569. (. b) ;Invalid -- an error is signaled if an attempt is made to read
  570. ;this syntax.
  571. (a .) ;Invalid -- an error is signaled.
  572. (a .. b) ;Invalid -- an error is signaled.
  573. (a . . b) ;Invalid -- an error is signaled.
  574. (a b c ...) ;Invalid -- an error is signaled.
  575. (a \\. b) ;A list of three elements a, ., and b
  576. (a |.| b) ;A list of three elements a, ., and b
  577. (a \\... b) ;A list of three elements a, ..., and b
  578. (a |...| b) ;A list of three elements a, ..., and b
  579. \endcode
  580. For information on how the \term{Lisp reader} parses \term{lists} and \term{conses},
  581. \seesection\LeftParen.
  582. \endsubsubsection%{Printing Lists and Conses}
  583. \beginsubsubsection{Printing Bit Vectors}
  584. \DefineSection{PrintingBitVectors}
  585. %% 22.1.6 21
  586. A \term{bit vector} is printed as \f{\#*} followed by the bits of the \term{bit vector}
  587. in order. If \varref{*print-array*} is \term{false}, then the \term{bit vector} is
  588. printed in a format (using \f{\#<}) that is concise but not readable.
  589. Only the \term{active} \term{elements} of the \term{bit vector} are printed.
  590. \reviewer{Barrett: Need to provide for \f{\#5*0} as an alternate
  591. notation for \f{\#*00000}.}%!!!
  592. %% Reworded to avoid awkward line break. -kmp 24-Apr-93
  593. For information on \term{Lisp reader} parsing of \term{bit vectors},
  594. \seesection\SharpsignStar.
  595. \endsubsubsection%{Printing Bit Vectors}
  596. \beginsubsubsection{Printing Other Vectors}
  597. \DefineSection{PrintingOtherVectors}
  598. %% 22.1.6 22
  599. \issue{PRINT-READABLY-BEHAVIOR:CLARIFY}
  600. %Any
  601. If \varref{*print-array*} is \term{true}
  602. and \varref{*print-readably*} is \term{false},
  603. any
  604. \endissue{PRINT-READABLY-BEHAVIOR:CLARIFY}
  605. \term{vector}
  606. other than a \term{string} or \term{bit vector} is printed using
  607. general-vector syntax; this means that information
  608. about specialized vector representations does not appear.
  609. The printed representation of a zero-length \term{vector} is \f{\#()}.
  610. The printed representation of a non-zero-length \term{vector} begins with \f{\#(}.
  611. Following that, the first element of the \term{vector} is printed.
  612. \issue{PRINTER-WHITESPACE:JUST-ONE-SPACE}
  613. If there are any other elements, they are printed in turn, with
  614. each such additional element preceded by
  615. a \term{space} if \varref{*print-pretty*} is \term{false},
  616. or \term{whitespace}\meaning{1} if \varref{*print-pretty*} is \term{true}.
  617. \endissue{PRINTER-WHITESPACE:JUST-ONE-SPACE}
  618. A \term{right-parenthesis} after the last element
  619. terminates the printed representation of the \term{vector}.
  620. The printing of \term{vectors}
  621. is affected by \varref{*print-level*} and \varref{*print-length*}.
  622. If the \term{vector} has a \term{fill pointer},
  623. then only those elements below
  624. the \term{fill pointer} are printed.
  625. %% 22.1.6 23
  626. \issue{PRINT-READABLY-BEHAVIOR:CLARIFY}
  627. %If \varref{*print-array*} is \term{false}
  628. If both \varref{*print-array*} and \varref{*print-readably*} are \term{false},
  629. \endissue{PRINT-READABLY-BEHAVIOR:CLARIFY}
  630. the \term{vector} is not printed as described above,
  631. but in a format (using \f{\#<}) that is concise but not readable.
  632. \issue{PRINT-READABLY-BEHAVIOR:CLARIFY}
  633. If \varref{*print-readably*} is \term{true},
  634. the \term{vector} prints in an \term{implementation-defined} manner;
  635. \seevar{*print-readably*}.
  636. \endissue{PRINT-READABLY-BEHAVIOR:CLARIFY}
  637. For information on how the \term{Lisp reader} parses these ``other \term{vectors},''
  638. \seesection\SharpsignLeftParen.
  639. \endsubsubsection%{Printing Other Vectors}
  640. \beginsubsubsection{Printing Other Arrays}
  641. \DefineSection{PrintingOtherArrays}
  642. %% 22.1.6 24
  643. \issue{PRINT-READABLY-BEHAVIOR:CLARIFY}
  644. %Any
  645. If \varref{*print-array*} is \term{true}
  646. and \varref{*print-readably*} is \term{false},
  647. any
  648. \endissue{PRINT-READABLY-BEHAVIOR:CLARIFY}
  649. \term{array} other than a \term{vector} is printed
  650. using \f{\#}\f{n}\f{A} format.
  651. Let \f{n} be the \term{rank} of the \term{array}.
  652. Then \f{\#} is printed, then \f{n} as a decimal integer,
  653. then \f{A}, then \f{n} open parentheses.
  654. Next the \term{elements} are scanned in row-major order,
  655. % Added for Barmar:
  656. using \funref{write} on each \term{element},
  657. and separating \term{elements} from each other with \term{whitespace}\meaning{1}.
  658. %% Barrett didn't like the odometer thing (probably for good reason).
  659. %% I've rewritten it. -kmp 12-Oct-91
  660. The array's dimensions are numbered 0 to \f{n}-1 from left to right,
  661. and are enumerated with the rightmost index changing fastest.
  662. %Imagine the \term{array} indices being enumerated in odometer fashion,
  663. %recalling that the dimensions are numbered from 0 to \f{n}-1.
  664. Every time the index for dimension \f{j} is incremented,
  665. the following actions are taken:
  666. %% 22.1.6 25
  667. \beginlist
  668. \itemitem{\bull}
  669. If \f{j} < \f{n}-1, then a close parenthesis is printed.
  670. %% 22.1.6 26
  671. \itemitem{\bull}
  672. If incrementing the index for dimension \f{j} caused it to equal
  673. dimension \f{j}, that index is reset to zero and the
  674. index for dimension \f{j}-1 is incremented (thereby performing these three steps recursively),
  675. unless \f{j}=0, in which case the entire algorithm is terminated.
  676. If incrementing the index for dimension \f{j} did not cause it to
  677. equal dimension \f{j}, then a space is printed.
  678. %% 22.1.6 27
  679. \itemitem{\bull}
  680. If \f{j} < \f{n}-1, then an open parenthesis is printed.
  681. \endlist
  682. This causes the contents to be printed in a format suitable for
  683. \kwd{initial-contents} to \funref{make-array}.
  684. The lists effectively printed by this procedure are subject to
  685. truncation by \varref{*print-level*} and \varref{*print-length*}.
  686. %% 22.1.6 28
  687. If the \term{array}
  688. is of a specialized \term{type}, containing bits or characters,
  689. then the innermost lists generated by the algorithm given above can instead
  690. be printed using bit-vector or string syntax, provided that these innermost
  691. lists would not be subject to truncation by \varref{*print-length*}.
  692. %For example,
  693. %a 3-by-2-by-4 \term{array}
  694. %of characters that would ordinarily be printed as
  695. %
  696. %\code
  697. % #3A(
  698. % ((#\\s #\\t #\\o #\\p) (#\\s #\\p #\\o #\\t))
  699. % ((#\\p #\\o #\\s #\\t) (#\\p #\\o #\\t #\\s))
  700. % ((#\\t #\\o #\\p #\\s) (#\\o #\\p #\\t #\\s)))
  701. %\endcode
  702. %
  703. %may instead be printed more concisely as
  704. %
  705. %\code
  706. % #3A(("stop" "spot") ("post" "pots") ("tops" "opts"))
  707. %\endcode
  708. %% 22.1.6 29
  709. \issue{PRINT-READABLY-BEHAVIOR:CLARIFY}
  710. %If \varref{*print-array*} is \term{false},
  711. If both \varref{*print-array*} and \varref{*print-readably*} are \term{false},
  712. \endissue{PRINT-READABLY-BEHAVIOR:CLARIFY}
  713. then the \term{array} is printed
  714. in a format (using \f{\#<}) that is concise but not readable.
  715. \issue{PRINT-READABLY-BEHAVIOR:CLARIFY}
  716. If \varref{*print-readably*} is \term{true},
  717. the \term{array} prints in an \term{implementation-defined} manner;
  718. \seevar{*print-readably*}.
  719. \endissue{PRINT-READABLY-BEHAVIOR:CLARIFY}
  720. %% Per X3J13. -kmp 05-Oct-93
  721. In particular,
  722. this may be important for arrays having some dimension \f{0}.
  723. For information on how the \term{Lisp reader} parses these ``other \term{arrays},''
  724. see \secref\SharpsignA.
  725. \beginsubsubsection{Examples of Printing Arrays}
  726. \code
  727. (let ((a (make-array '(3 3)))
  728. (*print-pretty* t)
  729. (*print-array* t))
  730. (dotimes (i 3) (dotimes (j 3) (setf (aref a i j) (format nil "<~D,~D>" i j))))
  731. (print a)
  732. (print (make-array 9 :displaced-to a)))
  733. \OUT #2A(("<0,0>" "<0,1>" "<0,2>")
  734. \OUT ("<1,0>" "<1,1>" "<1,2>")
  735. \OUT ("<2,0>" "<2,1>" "<2,2>"))
  736. \OUT #("<0,0>" "<0,1>" "<0,2>" "<1,0>" "<1,1>" "<1,2>" "<2,0>" "<2,1>" "<2,2>")
  737. \EV #<ARRAY 9 indirect 36363476>
  738. \endcode
  739. \endsubsubsection%{Examples of Printing Arrays}
  740. \endsubsubsection%{Printing Other Arrays}
  741. \beginsubsubsection{Printing Random States}
  742. \DefineSection{PrintingRandomStates}
  743. %% 12.9.0 18
  744. %% 22.1.6 30
  745. A specific syntax for printing \term{objects} \oftype{random-state} is
  746. not specified. However, every \term{implementation}
  747. must arrange to print a \term{random state} \term{object} in such a way that,
  748. within the same implementation, \funref{read}
  749. can construct from the printed representation a copy of the
  750. \term{random state}
  751. object as if the copy had been made by \funref{make-random-state}.
  752. If the type \term{random state} is effectively implemented
  753. by using the machinery for \macref{defstruct},
  754. the usual structure syntax can then be used for printing
  755. \term{random state}
  756. objects; one might look something like
  757. % Use of non-keyword #S keywords is deprecated. --sjl 16 Mar 92
  758. %\code
  759. % #S(RANDOM-STATE DATA #(14 49 98436589 786345 8734658324 ... ))
  760. %\endcode
  761. \code
  762. #S(RANDOM-STATE :DATA #(14 49 98436589 786345 8734658324 ... ))
  763. \endcode
  764. where the components are \term{implementation-dependent}.
  765. \endsubsubsection%{Printing Random States}
  766. \beginsubsubsection{Printing Pathnames}
  767. \DefineSection{PrintingPathnames}
  768. %% 22.1.6 31
  769. \issue{PATHNAME-PRINT-READ:SHARPSIGN-P}
  770. \issue{PRINT-READABLY-BEHAVIOR:CLARIFY}
  771. %When \varref{*print-escape*} is \term{true},
  772. When \term{printer escaping} is enabled,
  773. \endissue{PRINT-READABLY-BEHAVIOR:CLARIFY}
  774. the syntax \f{\#P"..."} is how a
  775. \term{pathname} is printed by \funref{write} and the other functions herein described.
  776. %!!! Probably "a" rather than "the" would go better here?? -kmp 11-Feb-91
  777. The \f{"..."} is the namestring representation of the pathname.
  778. %% !!! I'm thinking about adding the following.
  779. %% Mail sent to get other opinions. -kmp 11-Feb-92
  780. %
  781. % If a suitable \term{namestring} representation for the \term{pathname} cannot be
  782. % constructed (\eg for pathname that is missing components required by
  783. % the \term{file system}), an \term{implementation} is permitted (but not required)
  784. % to use an alternate (\term{implementation-dependent}) printed representation,
  785. % such as \f{\#S(PATHNAME ...)}.
  786. \issue{PRINT-READABLY-BEHAVIOR:CLARIFY}
  787. %When \varref{*print-escape*} is \term{false},
  788. When \term{printer escaping} is disabled,
  789. \endissue{PRINT-READABLY-BEHAVIOR:CLARIFY}
  790. \funref{write} writes a \term{pathname} \i{P}
  791. by writing \f{(namestring \i{P})} instead.
  792. % The following will be deleted:
  793. %
  794. % A specific syntax for printing \term{objects} \oftype{pathname} is not specified.
  795. % However, every implementation must arrange to print a \term{pathname} in such a way that,
  796. % within the same implementation of \clisp,
  797. % \funref{read} can construct from the printed representation an equivalent
  798. % instance of the \term{pathname} \term{object}.
  799. %
  800. % The printed representation of a pathname
  801. % typically designates \kwd{wild} by an asterisk; however, this is
  802. % \term{implementation-dependent}.
  803. %
  804. % End of deletion.
  805. For information on how the \term{Lisp reader} parses \term{pathnames},
  806. see \secref\SharpsignP.
  807. \endissue{PATHNAME-PRINT-READ:SHARPSIGN-P}
  808. \endsubsubsection%{Printing Pathnames}
  809. \beginsubsubsection{Printing Structures}
  810. \DefineSection{PrintingStructures}
  811. \issue{DEFSTRUCT-PRINT-FUNCTION-AGAIN:X3J13-MAR-93}
  812. %% 19.1.0 10
  813. %% 22.1.6 32
  814. % \term{Structures} defined by \macref{defstruct} are printed under the
  815. % control of the keyword \kwd{print-function} to \macref{defstruct}.
  816. % A default printing \term{function} is supplied that prints the
  817. % \term{structure} using \f{\#S} syntax.
  818. By default, a \term{structure} of type $S$ is printed using \f{\#S} syntax.
  819. This behavior can be customized by specifying a \kwd{print-function}
  820. or \kwd{print-object} option to the \macref{defstruct} \term{form} that defines $S$,
  821. or by writing a \funref{print-object} \term{method}
  822. that is \term{specialized} for \term{objects} of type $S$.
  823. \endissue{DEFSTRUCT-PRINT-FUNCTION-AGAIN:X3J13-MAR-93}
  824. \issue{STRUCTURE-READ-PRINT-SYNTAX:KEYWORDS}
  825. %% 2.12.0 2
  826. Different structures might print out in different ways;
  827. the default notation for structures is:
  828. \code
  829. #S(\param{structure-name} \star{\curly{\param{slot-key} \param{slot-value}}})
  830. \endcode
  831. where \f{\#S} indicates structure syntax,
  832. \param{structure-name} is a \term{structure name},
  833. each \param{slot-key} is an initialization argument \term{name}
  834. for a \term{slot} in the \term{structure},
  835. and each corresponding \param{slot-value} is a representation
  836. of the \term{object} in that \term{slot}.
  837. %The slot names need not be written with \term{package prefixes}.
  838. \endissue{STRUCTURE-READ-PRINT-SYNTAX:KEYWORDS}
  839. For information on how the \term{Lisp reader} parses \term{structures},
  840. see \secref\SharpsignS.
  841. \endsubsubsection%{Printing Structures}
  842. \beginsubsubsection{Printing Other Objects}
  843. \DefineSection{PrintingOtherObjects}
  844. %% 2.14.0 1
  845. %% 22.1.6 33
  846. Other \term{objects} are printed in an \term{implementation-dependent} manner.
  847. It is not required that an \term{implementation} print those \term{objects}
  848. \term{readably}.
  849. For example, \term{hash tables},
  850. \term{readtables},
  851. \term{packages},
  852. \term{streams},
  853. and \term{functions}
  854. might not print \term{readably}.
  855. A common notation to use in this circumstance is \f{\#<...>}.
  856. Since \f{\#<} is not readable by the \term{Lisp reader},
  857. the precise format of the text which follows is not important,
  858. but a common format to use is that provided by \themacro{print-unreadable-object}.
  859. For information on how the \term{Lisp reader} treats this notation,
  860. \seesection\SharpsignLeftAngle.
  861. For information on how to notate \term{objects} that cannot be printed \term{readably},
  862. \seesection\SharpsignDot.
  863. \endsubsubsection%{Printing Other Objects}
  864. \endsubsection%{Default Print-Object Methods}
  865. %% 22.1.6 34
  866. %% this paragraph left out
  867. \beginsubSection{Examples of Printer Behavior}
  868. \code
  869. (let ((*print-escape* t)) (fresh-line) (write #\\a))
  870. \OUT #\\a
  871. \EV #\\a
  872. (let ((*print-escape* nil) (*print-readably* nil))
  873. (fresh-line)
  874. (write #\\a))
  875. \OUT a
  876. \EV #\\a
  877. (progn (fresh-line) (prin1 #\\a))
  878. \OUT #\\a
  879. \EV #\\a
  880. (progn (fresh-line) (print #\\a))
  881. \OUT
  882. \OUT #\\a
  883. \EV #\\a
  884. (progn (fresh-line) (princ #\\a))
  885. \OUT a
  886. \EV #\\a
  887. \medbreak
  888. (dolist (val '(t nil))
  889. (let ((*print-escape* val) (*print-readably* val))
  890. (print '#\\a)
  891. (prin1 #\\a) (write-char #\\Space)
  892. (princ #\\a) (write-char #\\Space)
  893. (write #\\a)))
  894. \OUT #\\a #\\a a #\\a
  895. \OUT #\\a #\\a a a
  896. \EV NIL
  897. \medbreak
  898. (progn (fresh-line) (write '(let ((a 1) (b 2)) (+ a b))))
  899. \OUT (LET ((A 1) (B 2)) (+ A B))
  900. \EV (LET ((A 1) (B 2)) (+ A B))
  901. \medbreak
  902. (progn (fresh-line) (pprint '(let ((a 1) (b 2)) (+ a b))))
  903. \OUT (LET ((A 1)
  904. \OUT (B 2))
  905. \OUT (+ A B))
  906. \EV (LET ((A 1) (B 2)) (+ A B))
  907. \medbreak
  908. (progn (fresh-line)
  909. (write '(let ((a 1) (b 2)) (+ a b)) :pretty t))
  910. \OUT (LET ((A 1)
  911. \OUT (B 2))
  912. \OUT (+ A B))
  913. \EV (LET ((A 1) (B 2)) (+ A B))
  914. \medbreak
  915. (with-output-to-string (s)
  916. (write 'write :stream s)
  917. (prin1 'prin1 s))
  918. \EV "WRITEPRIN1"
  919. \endcode
  920. \endsubSection%{Examples of Printer Behavior}