dict-printer.tex 83 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688
  1. % -*- Mode: TeX -*-
  2. % Pretty Printer Concepts
  3. % Printer
  4. % Printer Variables
  5. \def\writekeys#1{\vtop{\hbox{array base case circle escape gensym}
  6. \hbox{length level lines miser-width pprint-dispatch}
  7. \hbox{pretty radix readably right-margin #1}}}
  8. \def\writekeydescriptions#1{\param{array}---a \term{generalized boolean}.
  9. \param{base}---a \term{radix}.
  10. \param{case}---a \term{symbol} of \term{type} \f{(member :upcase :downcase :capitalize)}.
  11. \param{circle}---a \term{generalized boolean}.
  12. \param{escape}---a \term{generalized boolean}.
  13. \param{gensym}---a \term{generalized boolean}.
  14. \param{length}---a non-negative \term{integer}, or \nil.
  15. \param{level}---a non-negative \term{integer}, or \nil.
  16. \param{lines}---a non-negative \term{integer}, or \nil.
  17. \param{miser-width}---a non-negative \term{integer}, or \nil.
  18. \param{pprint-dispatch}---a \term{pprint dispatch table}.
  19. \param{pretty}---a \term{generalized boolean}.
  20. \param{radix}---a \term{generalized boolean}.
  21. \param{readably}---a \term{generalized boolean}.
  22. \param{right-margin}---a non-negative \term{integer}, or \nil.
  23. #1}
  24. %-------------------- Printer --------------------
  25. %%% ========== COPY-PPRINT-DISPATCH
  26. \begincom{copy-pprint-dispatch}\ftype{Function}
  27. %KMP: I'd like to change the name of this function to COPY-PPRINT-DISPATCH-TABLE.
  28. \issue{PRETTY-PRINT-INTERFACE}
  29. \label Syntax::
  30. \DefunWithValues copy-pprint-dispatch {{\opt} table} {new-table}
  31. \label Arguments and Values::
  32. \param{table}---a \term{pprint dispatch table}, or \nil.
  33. \param{new-table}---a \term{fresh} \term{pprint dispatch table}.
  34. \label Description::
  35. Creates and returns a copy of the specified \param{table},
  36. or of \thevalueof{*print-pprint-dispatch*} if no \param{table} is specified,
  37. or of the initial \term{value} of \varref{*print-pprint-dispatch*} if \nil\ is specified.
  38. \label Examples:\None.
  39. \label Side Effects:\None.
  40. %% Sandra thinks this is excessive.
  41. %Creates a \term{pprint dispatch table}.
  42. \label Affected By:\None.
  43. \label Exceptional Situations::
  44. Should signal an error \oftype{type-error} if \param{table}
  45. is not a \term{pprint dispatch table}.
  46. \label See Also:\None.
  47. \label Notes:\None.
  48. \endissue{PRETTY-PRINT-INTERFACE}
  49. \endcom
  50. %%% ========== FORMATTER
  51. \begincom{formatter}\ftype{Macro}
  52. \issue{PRETTY-PRINT-INTERFACE}
  53. \label Syntax::
  54. \DefmacWithValues formatter {control-string} {function}
  55. \label Arguments and Values::
  56. \param{control-string}---a \term{format string}; \noeval.
  57. \param{function}---a \term{function}.
  58. \label Description::
  59. Returns a \term{function} which has behavior equivalent to:
  60. \code
  61. #'(lambda (*standard-output* &rest arguments)
  62. (apply #'format t \i{control-string} arguments)
  63. \i{arguments-tail})
  64. \endcode
  65. where \i{arguments-tail} is either the tail of \i{arguments}
  66. which has as its \term{car} the argument that would be processed next
  67. if there were more format directives in the \param{control-string},
  68. or else \nil\ if no more \i{arguments} follow the most recently
  69. processed argument.
  70. \label Examples::
  71. %This doesn't look like valid syntax to me. --sjl 16 mar 92
  72. %\code
  73. %((formatter "~&~A~A") *standard-output* 'a 'b 'c)
  74. %\OUT AB
  75. %\EV (C)
  76. \code
  77. (funcall (formatter "~&~A~A") *standard-output* 'a 'b 'c)
  78. \OUT AB
  79. \EV (C)
  80. (format t (formatter "~&~A~A") 'a 'b 'c)
  81. \OUT AB
  82. \EV NIL
  83. \endcode
  84. \label Side Effects:\None.
  85. %% Sandra thinks this is excessive.
  86. %Might create a \term{closure} at run time.
  87. \label Affected By:\None.
  88. \label Exceptional Situations::
  89. Might signal an error (at macro expansion time or at run time) if the argument
  90. is not a valid \term{format string}.
  91. \label See Also::
  92. \funref{format}
  93. \label Notes:\None.
  94. \endissue{PRETTY-PRINT-INTERFACE}
  95. \endcom
  96. %%% ========== PPRINT-DISPATCH
  97. \begincom{pprint-dispatch}\ftype{Function}
  98. \issue{PRETTY-PRINT-INTERFACE}
  99. \label Syntax::
  100. \DefunWithValues pprint-dispatch {object {\opt} table} {function, found-p}
  101. \label Arguments and Values::
  102. \param{object}---an \term{object}.
  103. %!!! pprint dispatch table designator?? -kmp 16-Oct-91
  104. \param{table}---a \term{pprint dispatch table}, or \nil.
  105. \Default{\thevalueof{*print-pprint-dispatch*}}
  106. % It wasn't obvious if this should be a "function" or "function designator".
  107. % I asked x3j13 with issue PPRINT-DISPATCH-RETURN-VALUE, but rather than vote
  108. % on it, they just told me to use my discretion. Which is basically the same
  109. % as if they had approved the issue. "function designator" it is. -kmp 11-Feb-92
  110. \param{function}---a \term{function designator}.
  111. \param{found-p}---a \term{generalized boolean}.
  112. \label Description::
  113. Retrieves the highest priority function in \param{table} that is
  114. associated with a \term{type specifier} that matches \param{object}.
  115. The function is chosen by finding all of the \term{type specifiers} in \param{table}
  116. that match the \param{object} and
  117. selecting the highest priority function associated with any of these
  118. \term{type specifiers}. If there is more than one highest priority function,
  119. an arbitrary choice is made. If no \term{type specifiers} match the
  120. \param{object}, a function is returned that prints \param{object}
  121. \issue{GENERALIZE-PRETTY-PRINTER:UNIFY}
  122. %with \varref{*print-pretty*} bound to \nil.
  123. using \funref{print-object}.
  124. \endissue{GENERALIZE-PRETTY-PRINTER:UNIFY}
  125. The \term{secondary value}, \param{found-p}, is \term{true} if a matching
  126. \term{type specifier} was found in \param{table}, or \term{false} otherwise.
  127. If \param{table} is \nil,
  128. retrieval is done in the
  129. %initial value of \varref{*print-pprint-dispatch*}.
  130. \term{initial pprint dispatch table}.
  131. \label Examples:\None.
  132. \label Side Effects:\None.
  133. \label Affected By::
  134. The state of the \param{table}.
  135. \label Exceptional Situations::
  136. Should signal an error \oftype{type-error} if \term{table} is neither a
  137. \term{pprint-dispatch-table} nor \nil.
  138. \label See Also:\None.
  139. \label Notes::
  140. \code
  141. (let ((*print-pretty* t))
  142. (write object :stream s))
  143. \EQ (funcall (pprint-dispatch object) s object)
  144. \endcode
  145. \endissue{PRETTY-PRINT-INTERFACE}
  146. \endcom
  147. %%% ========== PPRINT-EXIT-IF-LIST-EXHAUSTED
  148. \begincom{pprint-exit-if-list-exhausted}\ftype{Local Macro}
  149. \issue{PRETTY-PRINT-INTERFACE}
  150. \label Syntax::
  151. \DefmacWithValues pprint-exit-if-list-exhausted {\noargs} {\nil}
  152. \label Arguments and Values:\None.
  153. \label Description::
  154. Tests whether or not the \param{list} passed to
  155. the \term{lexically current logical block}
  156. has been exhausted; \seesection\DynamicControlofOutput.
  157. If this \param{list} has been
  158. reduced to \nil, \funref{pprint-exit-if-list-exhausted} terminates the execution
  159. of the \term{lexically current logical block} except for the printing
  160. of the suffix. Otherwise \funref{pprint-exit-if-list-exhausted} returns \nil.
  161. \issue{LEXICAL-CONSTRUCT-GLOBAL-DEFINITION:UNDEFINED}
  162. Whether or not \macref{pprint-exit-if-list-exhausted} is \term{fbound} in the
  163. \term{global environment} is \term{implementation-dependent};
  164. however, the restrictions on redefinition and \term{shadowing} of
  165. \macref{pprint-exit-if-list-exhausted} are the same as for \term{symbols} in \thepackage{common-lisp}
  166. which are \term{fbound} in the \term{global environment}.
  167. The consequences of attempting to use \macref{pprint-exit-if-list-exhausted} outside
  168. of \macref{pprint-logical-block} are undefined.
  169. \endissue{LEXICAL-CONSTRUCT-GLOBAL-DEFINITION:UNDEFINED}
  170. \label Examples:\None.
  171. \label Side Effects:\None.
  172. \label Affected By:\None.
  173. \label Exceptional Situations::
  174. An error is signaled (at macro expansion time or at run time) if
  175. \funref{pprint-exit-if-list-exhausted} is used anywhere other than
  176. %syntactically nested
  177. lexically within a call on \macref{pprint-logical-block}.
  178. % It is undefined what happens if \funref{pprint-if-list-exhausted} is executed outside
  179. % of the dynamic extent of this \funref{pprint-logical-block}.
  180. Also, the consequences of executing \funref{pprint-if-list-exhausted} outside
  181. of the dynamic extent of the \macref{pprint-logical-block} which lexically
  182. contains it are undefined.
  183. \label See Also::
  184. \macref{pprint-logical-block}, \funref{pprint-pop}.
  185. \label Notes:\None.
  186. \endissue{PRETTY-PRINT-INTERFACE}
  187. \endcom
  188. %%% ========== PPRINT-FILL
  189. %%% ========== PPRINT-LINEAR
  190. %%% ========== PPRINT-TABULAR
  191. \begincom{pprint-fill, pprint-linear, pprint-tabular}\ftype{Function}
  192. \issue{PRETTY-PRINT-INTERFACE}
  193. \label Syntax::
  194. \DefunWithValues pprint-fill {stream object {\opt} colon-p at-sign-p} {\nil}
  195. \DefunWithValues pprint-linear {stream object {\opt} colon-p at-sign-p} {\nil}
  196. \DefunWithValues pprint-tabular {stream object {\opt} colon-p at-sign-p tabsize} {\nil}
  197. \label Arguments and Values::
  198. \param{stream}---an \term{output} \term{stream designator}.
  199. \param{object}---an \term{object}.
  200. \param{colon-p}---a \term{generalized boolean}.
  201. \Default{\term{true}}
  202. \param{at-sign-p}---a \term{generalized boolean}.
  203. \Default{\term{implementation-dependent}}
  204. \param{tabsize}---a non-negative \term{integer}.
  205. \Default{\f{16}}
  206. \label Description::
  207. The functions \funref{pprint-fill}, \funref{pprint-linear}, and
  208. \funref{pprint-tabular} specify particular ways of \term{pretty printing}
  209. a \term{list} to \param{stream}.
  210. Each function prints parentheses around the output if and only
  211. if \param{colon-p} is \term{true}.
  212. Each function ignores its \param{at-sign-p} argument.
  213. (Both arguments are included even though only one is needed
  214. so that these functions can be used via \formatOp{/.../}
  215. and as \funref{set-pprint-dispatch} functions, as well as directly.)
  216. Each function handles abbreviation and the detection of circularity
  217. and sharing correctly, and uses \funref{write} to print \param{object}
  218. when it is a \term{non-list}.
  219. % KMP: The pretty printer proposal as adopted was ambiguous
  220. % in the preceding sentence. I tried to resolve the ambiguity
  221. % by changing the argument name and doing some rewording.
  222. % Dick Waters should double-check this interpretation.
  223. % Waters: Is ok.
  224. \issue{GENERALIZE-PRETTY-PRINTER:UNIFY}
  225. If \param{object} is a \term{list} and
  226. if \thevalueof{*print-pretty*} is \term{false},
  227. each of these functions prints \param{object}
  228. using a minimum of \term{whitespace},
  229. as described in \secref\PrintingListsAndConses.
  230. Otherwise (if \param{object} is a \term{list} and
  231. if \thevalueof{*print-pretty*} is \term{true}):
  232. \beginlist
  233. \itemitem{\bull}
  234. \Thefunction{pprint-linear} prints a \term{list} either all on one line,
  235. or with each \term{element} on a separate line.
  236. \itemitem{\bull}
  237. \Thefunction{pprint-fill} prints a \term{list} with as many \term{elements}
  238. as possible on each line.
  239. \itemitem{\bull}
  240. \Thefunction{pprint-tabular} is the same as \funref{pprint-fill}
  241. except that it prints the \term{elements} so that they line up in columns.
  242. The \param{tabsize} specifies the column spacing in \term{ems},
  243. % KMP: Is this (1) the minimum intercolumn spacing, or
  244. % (2) the total spacing from the left edge of one column
  245. % to the left edge of the next?
  246. % Waters: (2)
  247. which is the total spacing from the leading edge of one column to
  248. the leading edge of the next.
  249. \endlist
  250. \endissue{GENERALIZE-PRETTY-PRINTER:UNIFY}
  251. \label Examples::
  252. Evaluating the following with a line length of \f{25} produces the output shown.
  253. \code
  254. (progn (princ "Roads ")
  255. (pprint-tabular *standard-output* '(elm main maple center) nil nil 8))
  256. Roads ELM MAIN
  257. MAPLE CENTER
  258. \endcode
  259. \label Side Effects::
  260. Performs output to the indicated \term{stream}.
  261. \label Affected By::
  262. The cursor position on the indicated \term{stream}, if it can be determined.
  263. \label Exceptional Situations:\None.
  264. \label See Also:\None.
  265. \label Notes::
  266. \Thefunction{pprint-tabular} could be defined as follows:
  267. \code
  268. (defun pprint-tabular (s list &optional (colon-p t) at-sign-p (tabsize nil))
  269. (declare (ignore at-sign-p))
  270. (when (null tabsize) (setq tabsize 16))
  271. (pprint-logical-block (s list :prefix (if colon-p "(" "")
  272. :suffix (if colon-p ")" ""))
  273. (pprint-exit-if-list-exhausted)
  274. (loop (write (pprint-pop) :stream s)
  275. (pprint-exit-if-list-exhausted)
  276. (write-char #\\Space s)
  277. (pprint-tab :section-relative 0 tabsize s)
  278. (pprint-newline :fill s))))
  279. \endcode
  280. Note that it would have been inconvenient to specify this function
  281. using \funref{format}, because of the need to pass its \param{tabsize} argument
  282. through to a \formatdirective{:T} nested within an iteration over a list.
  283. \endissue{PRETTY-PRINT-INTERFACE}
  284. \endcom
  285. %%% ========== PPRINT-INDENT
  286. \begincom{pprint-indent}\ftype{Function}
  287. \issue{PRETTY-PRINT-INTERFACE}
  288. \label Syntax::
  289. \DefunWithValues pprint-indent {relative-to n {\opt} stream} {\nil}
  290. \label Arguments and Values::
  291. \param{relative-to}---either \kwd{block} or \kwd{current}.
  292. \param{n}---a \term{real}.
  293. \param{stream}---an \term{output} \term{stream designator}.
  294. \Default{\term{standard output}}
  295. \label Description::
  296. \funref{pprint-indent} specifies the indentation to use in a logical block on \term{stream}.
  297. \issue{GENERALIZE-PRETTY-PRINTER:UNIFY}
  298. If \param{stream} is a \term{pretty printing stream}
  299. and \thevalueof{*print-pretty*} is \term{true},
  300. \funref{pprint-indent} sets the indentation in the innermost
  301. dynamically enclosing logical block;
  302. otherwise, \funref{pprint-indent} has no effect.
  303. \endissue{GENERALIZE-PRETTY-PRINTER:UNIFY}
  304. \param{N} specifies the indentation in
  305. \term{ems}. If \param{relative-to} is \kwd{block}, the indentation is set
  306. to the horizontal position of the first character in the \term{dynamically current logical block} plus \param{n}
  307. \term{ems}. If \param{relative-to} is \kwd{current}, the indentation is set
  308. to the current output position plus \param{n} \term{ems}. (For robustness
  309. in the face of variable-width fonts, it is advisable to use \kwd{current}
  310. with an \param{n} of zero whenever possible.)
  311. \param{N} can be negative;
  312. however, the total indentation cannot be moved
  313. left of the beginning of the line
  314. or left of the end of the rightmost per-line prefix---an attempt to move beyond
  315. one of these limits is treated
  316. % KMP: How?
  317. % (1) Is an error signaled,
  318. % or (2) or do we just min out at 0?
  319. % Waters: (2).
  320. the same as an attempt to move to that limit.
  321. Changes in indentation caused by \param{pprint-indent}
  322. do not take effect until after the next line break. In addition, in
  323. miser mode all calls to \funref{pprint-indent} are ignored, forcing the lines
  324. corresponding to the logical block to line up under the first character in
  325. the block.
  326. \label Examples:\None.
  327. \label Side Effects:\None.
  328. \label Affected By:\None.
  329. \label Exceptional Situations::
  330. An error is signaled if \param{relative-to} is any \term{object} other
  331. than \kwd{block} or \kwd{current}.
  332. \label See Also::
  333. {\secref\TildeI}
  334. \label Notes:\None.
  335. \endissue{PRETTY-PRINT-INTERFACE}
  336. \endcom
  337. %%% ========== PPRINT-LOGICAL-BLOCK
  338. \begincom{pprint-logical-block}\ftype{Macro}
  339. \issue{DECLS-AND-DOC}
  340. \issue{PRETTY-PRINT-INTERFACE}
  341. \label Syntax::
  342. \DefmacWithValuesNewline pprint-logical-block
  343. {\vtop{\hbox{\paren{stream-symbol object
  344. {\key} prefix per-line-prefix suffix}}
  345. \hbox{\starparam{declaration} \starparam{form}}}}
  346. {\nil}
  347. \label Arguments and Values::
  348. \param{stream-symbol}---a \term{stream variable designator}.
  349. \param{object}---an \term{object}; \eval.
  350. \kwd{prefix}---a \term{string}; \eval.
  351. \HairyDefault.
  352. \kwd{per-line-prefix}---a \term{string}; \eval.
  353. \HairyDefault.
  354. \kwd{suffix}---a \term{string}; \eval.
  355. \Default{the \term{null} \term{string}}
  356. \param{declaration}---a \misc{declare} \term{expression}; \noeval.
  357. \param{forms}---an \term{implicit progn}.
  358. \label Description::
  359. Causes printing to be grouped into a logical block.
  360. The logical block is printed to the \term{stream} that is the \term{value}
  361. of the \term{variable} denoted by \param{stream-symbol}.
  362. During the execution of the \term{forms},
  363. that \term{variable} is \term{bound} to a \term{pretty printing stream}
  364. that supports decisions about the arrangement of output
  365. and then forwards the output to the destination stream.
  366. \issue{GENERALIZE-PRETTY-PRINTER:UNIFY}
  367. % If, during that context, \varref{*print-pretty*} becomes bound to \nil,
  368. % the stream ceases to behave as a \term{pretty printing stream}.
  369. \endissue{GENERALIZE-PRETTY-PRINTER:UNIFY}
  370. All the standard printing functions
  371. (\eg \funref{write},
  372. \funref{princ},
  373. and \funref{terpri})
  374. can be used to print output to the \term{pretty printing stream}.
  375. All and only the output sent to this \term{pretty printing stream}
  376. is treated as being in the logical block.
  377. The \param{prefix} specifies a prefix to be printed before the beginning of
  378. the logical block.
  379. The \param{per-line-prefix} specifies a prefix that is printed before the block
  380. and at the beginning of each new line in the block.
  381. The \kwd{prefix} and \kwd{pre-line-prefix} \term{arguments} are mutually exclusive.
  382. If neither \kwd{prefix} nor \kwd{per-line-prefix} is specified,
  383. a \param{prefix} of the \term{null} \term{string} is assumed.
  384. The \param{suffix} specifies a suffix that is printed just after the logical block.
  385. The \param{object} is
  386. %interpreted as
  387. normally
  388. a \term{list} that the body \param{forms} are responsible for printing.
  389. If \param{object} is not a \term{list},
  390. it is printed using \funref{write}.
  391. (This makes it easier to write printing functions that are robust
  392. in the face of malformed arguments.)
  393. If \varref{*print-circle*}
  394. %%There's no such var. -kmp 14-Jan-91
  395. %(and possibly \varref{*print-shared*})
  396. is \term{non-nil} and \param{object} is a circular (or shared) reference to a \term{cons},
  397. then an appropriate ``\f{\#\i{n}\#}'' marker is printed. (This
  398. makes it easy to write printing functions that provide full support
  399. for circularity and sharing abbreviation.) If \varref{*print-level*} is not
  400. \nil\ and the logical block is at a dynamic nesting depth of greater
  401. than \varref{*print-level*} in logical blocks, ``\f{\#}'' is printed.
  402. (This makes easy to write printing functions that provide full support for depth
  403. abbreviation.)
  404. If either of the three conditions above occurs, the indicated output is
  405. printed on \param{stream-symbol} and the body \param{forms} are skipped
  406. along with the printing of the \kwd{prefix} and \kwd{suffix}.
  407. (If the body \param{forms} are not to be responsible for printing a list,
  408. then the first two tests above can be turned off by supplying \nil\ for
  409. the \param{object} argument.)
  410. In addition to the \param{object} argument of \macref{pprint-logical-block},
  411. the arguments of the standard printing functions (such as \funref{write},
  412. \funref{print}, \funref{prin1}, and \funref{pprint}, as well as the arguments
  413. of the standard \term{format directives} such as \formatOp{A}, \formatOp{S},
  414. (and \formatOp{W}) are all checked (when necessary) for circularity and sharing.
  415. However, such checking is not applied to the arguments of the
  416. functions \funref{write-line}, \funref{write-string}, and \funref{write-char}
  417. or to the literal text output by \funref{format}. A consequence of this is
  418. that you must use one of the latter functions if you want to print some
  419. literal text in the output that is not supposed to be checked for circularity
  420. or sharing.
  421. % (See the examples below.)
  422. The body \param{forms} of a \macref{pprint-logical-block} \term{form}
  423. must not perform any side-effects on the surrounding environment; for
  424. example, no \term{variables} must be assigned which have not been
  425. \term{bound} within its scope.
  426. % (See notes below for rationale.)
  427. \issue{GENERALIZE-PRETTY-PRINTER:UNIFY}
  428. \Themacro{pprint-logical-block} may be used regardless of \thevalueof{*print-pretty*}.
  429. \endissue{GENERALIZE-PRETTY-PRINTER:UNIFY}
  430. \label Examples:\None.
  431. \label Side Effects:\None.
  432. \label Affected By::
  433. \varref{*print-circle*}, \varref{*print-level*}.
  434. \label Exceptional Situations::
  435. An error \oftype{type-error} is signaled if any of the \kwd{suffix},
  436. \kwd{prefix}, or \kwd{per-line-prefix} is supplied but does not evaluate
  437. to a \term{string}.
  438. An error is signaled if \kwd{prefix} and \kwd{pre-line-prefix} are both used.
  439. \macref{pprint-logical-block} and the \term{pretty printing stream} it creates
  440. have \term{dynamic extent}. The consequences are undefined if, outside
  441. of this extent, output is attempted to the \term{pretty printing stream} it creates.
  442. It is also unspecified what happens if, within this extent, any output is
  443. sent directly to the underlying destination stream.
  444. \label See Also::
  445. \macref{pprint-pop},
  446. \macref{pprint-exit-if-list-exhausted},
  447. {\secref\TildeLessThanLogicalBlock}
  448. \label Notes::
  449. \issue{GENERALIZE-PRETTY-PRINTER:UNIFY}
  450. One reason for using \themacro{pprint-logical-block} when \thevalueof{*print-pretty*}
  451. is \nil\ would be to allow it to perform checking for \term{dotted lists},
  452. as well as (in conjunction with \macref{pprint-pop})
  453. checking for \varref{*print-level*} or \varref{*print-length*} being exceeded.
  454. \endissue{GENERALIZE-PRETTY-PRINTER:UNIFY}
  455. Detection of circularity and sharing is supported by the \term{pretty printer}
  456. by in essence performing requested output twice. On the first pass,
  457. circularities and sharing are detected and the actual outputting of characters
  458. is suppressed. On the second pass, the appropriate ``\f{\#\param{n}=}''
  459. and ``\f{\#\param{n}\#}'' markers are inserted and characters are output.
  460. This is why the restriction on side-effects is necessary.
  461. Obeying this restriction is facilitated by using \macref{pprint-pop},
  462. instead of an ordinary \macref{pop} when traversing a list being printed by
  463. the body \param{forms} of the \macref{pprint-logical-block} \term{form}.)
  464. \endissue{PRETTY-PRINT-INTERFACE}
  465. \endissue{DECLS-AND-DOC}
  466. \endcom
  467. %%% ========== PPRINT-NEWLINE
  468. \begincom{pprint-newline}\ftype{Function}
  469. \issue{PRETTY-PRINT-INTERFACE}
  470. \label Syntax::
  471. \DefunWithValues pprint-newline {kind {\opt} stream} {\nil}
  472. \label Arguments and Values::
  473. \param{kind}---one of \kwd{linear}, \kwd{fill}, \kwd{miser}, or \kwd{mandatory}.
  474. \param{stream}---a \term{stream designator}.
  475. \Default{\term{standard output}}
  476. \label Description::
  477. %% This follows from being a stream designator. -kmp 27-Aug-93
  478. % \param{Stream} defaults to \term{standard output}.
  479. % If it is \nil, \term{standard output} is used instead.
  480. % If it is \t, \term{terminal I/O} is used instead.
  481. \issue{GENERALIZE-PRETTY-PRINTER:UNIFY}
  482. If \param{stream} is a \term{pretty printing stream}
  483. and \thevalueof{*print-pretty*} is \term{true},
  484. a line break is inserted in the output
  485. when the appropriate condition below is satisfied;
  486. otherwise, \funref{pprint-newline} has no effect.
  487. \endissue{GENERALIZE-PRETTY-PRINTER:UNIFY}
  488. \param{Kind} specifies the style of conditional newline.
  489. This \term{parameter} is treated as follows:
  490. \beginlist
  491. \item{\kwd{linear}}
  492. This specifies a
  493. ``linear-style'' \term{conditional newline}.\idxtext{linear-style conditional newline}
  494. A line break is inserted
  495. if and only if the immediately containing \term{section}
  496. cannot be printed on one line.
  497. The effect of this is that line breaks are
  498. either inserted at every linear-style conditional newline in a logical block
  499. or at none of them.
  500. \item{\kwd{miser}}
  501. This specifies a
  502. ``miser-style'' \term{conditional newline}.\idxtext{miser-style conditional newline}
  503. A line break is inserted
  504. if and only if the immediately containing \term{section}
  505. cannot be printed on one line
  506. and miser style is in effect in the immediately containing logical block.
  507. The effect of this is that miser-style conditional newlines
  508. act like linear-style conditional newlines,
  509. but only when miser style is in effect.
  510. Miser style is in effect for a logical block if and only if
  511. the starting position of the logical block
  512. is less than or equal to
  513. \varref{*print-miser-width*} \term{ems} from the right margin.
  514. \item{\kwd{fill}}
  515. This specifies a
  516. ``fill-style'' \term{conditional newline}.\idxtext{fill-style conditional newline}
  517. A line break is inserted if and only if
  518. either (a) the following \term{section} cannot be printed
  519. on the end of the current line,
  520. (b) the preceding \term{section} was not printed on a single line,
  521. or (c) the immediately containing \term{section} cannot
  522. be printed on one line and miser style is in effect
  523. in the immediately containing logical block.
  524. If a logical block is broken up into a number of subsections
  525. by fill-style conditional newlines,
  526. the basic effect is that the logical block
  527. is printed with as many subsections as possible on each line.
  528. However, if miser style is in effect,
  529. fill-style conditional newlines act like linear-style conditional newlines.
  530. \item{\kwd{mandatory}}
  531. This specifies a
  532. ``mandatory-style'' \term{conditional newline}.\idxtext{mandatory-style conditional newline}
  533. A line break is always inserted.
  534. This implies that none of the containing \term{sections}
  535. can be printed on a single line and
  536. will therefore trigger the insertion of line breaks
  537. at linear-style conditional newlines in these \term{sections}.
  538. \endlist
  539. When a line break is inserted by any type of conditional newline,
  540. any blanks that immediately precede the conditional newline are omitted
  541. from the output and indentation is introduced at the beginning of the next line.
  542. By default, the indentation causes the following line to begin
  543. in the same horizontal position
  544. as the first character in the immediately containing logical block.
  545. (The indentation can be changed via \funref{pprint-indent}.)
  546. There are a variety of ways unconditional newlines can be introduced into
  547. the output (\ie via \funref{terpri} or by printing a string containing a newline
  548. character). As with mandatory conditional newlines, this prevents any of
  549. the containing \term{sections} from being printed on one line. In general, when
  550. an unconditional newline is encountered, it is printed out without
  551. suppression of the preceding blanks and without any indentation following
  552. it. However, if a per-line prefix has been specified (see
  553. \macref{pprint-logical-block}), this prefix will always be printed no matter
  554. how a newline originates.
  555. \label Examples::
  556. \Seesection\PrettyPrinterExamples.
  557. \label Side Effects::
  558. Output to \param{stream}.
  559. \label Affected By::
  560. \varref{*print-pretty*}, \varref{*print-miser*}.
  561. The presence of containing logical blocks.
  562. The placement of newlines and conditional newlines.
  563. \label Exceptional Situations::
  564. An error \oftype{type-error} is signaled if \param{kind}
  565. is not one of \kwd{linear}, \kwd{fill}, \kwd{miser}, or \kwd{mandatory}.
  566. \label See Also::
  567. {\secref\TildeUnderscore},
  568. {\secref\PrettyPrinterExamples}
  569. \label Notes:\None.
  570. \endissue{PRETTY-PRINT-INTERFACE}
  571. \endcom
  572. %%% ========== PPRINT-POP
  573. \begincom{pprint-pop}\ftype{Local Macro}
  574. \issue{PRETTY-PRINT-INTERFACE}
  575. \label Syntax::
  576. \DefmacWithValues pprint-pop {\noargs} {object}
  577. \label Arguments and Values::
  578. \param{object}---an \term{element} of the \term{list}
  579. being printed in the \term{lexically current logical block},
  580. or \nil.
  581. \label Description::
  582. Pops one \term{element} from the \term{list} being printed
  583. in the \term{lexically current logical block}, obeying \varref{*print-length*}
  584. and \varref{*print-circle*} as described below.
  585. Each time \macref{pprint-pop} is called, it pops the next value off the
  586. \term{list} passed to the \term{lexically current logical block} and returns it.
  587. However, before doing this, it performs three tests:
  588. \beginlist
  589. \item{\bull}
  590. If the remaining `list' is not a \term{list},
  591. ``\f{. }''\idxterm{dot} is printed followed by the remaining `list.'
  592. (This makes it easier to write printing functions that
  593. are robust in the face of malformed arguments.)
  594. \item{\bull}
  595. If \varref{*print-length*} is \term{non-nil},
  596. and \macref{pprint-pop} has already been called \varref{*print-length*} times
  597. within the immediately containing logical block,
  598. ``\f{...}''\idxtext{Dot Dot Dot}\idxcode{...} is printed.
  599. (This makes it easy to write printing functions that properly handle
  600. \varref{*print-length*}.)
  601. \item{\bull}
  602. If \varref{*print-circle*} is
  603. \term{non-nil}, and the remaining list is a circular (or shared) reference,
  604. then ``\f{. }'' is printed followed by an appropriate
  605. ``\f{\#\i{n}\#}''\idxtext{Sharpsign Sharpsign (reader macro)} marker.
  606. (This catches instances of \term{cdr} circularity and sharing in lists.)
  607. \endlist
  608. If either of the three conditions above occurs, the indicated output is
  609. printed on the \term{pretty printing stream} created by the immediately containing
  610. \macref{pprint-logical-block} and the execution of the immediately containing
  611. \macref{pprint-logical-block} is terminated except for the printing of the suffix.
  612. %KMP: I find this next paragraph fairly undecipherable.
  613. If \macref{pprint-logical-block} is given a `list' argument of \nil---because
  614. it is not processing a list---\macref{pprint-pop} can still be used to obtain
  615. support for \varref{*print-length*}.
  616. In this situation, the first and third tests above are disabled and
  617. \macref{pprint-pop} always returns \nil.
  618. \Seesection\PrettyPrinterExamples---specifically, the \funref{pprint-vector} example.
  619. \issue{LEXICAL-CONSTRUCT-GLOBAL-DEFINITION:UNDEFINED}
  620. Whether or not \macref{pprint-pop} is \term{fbound} in the
  621. \term{global environment} is \term{implementation-dependent};
  622. however, the restrictions on redefinition and \term{shadowing} of
  623. \macref{pprint-pop} are the same as for \term{symbols} in \thepackage{common-lisp}
  624. which are \term{fbound} in the \term{global environment}.
  625. The consequences of attempting to use \macref{pprint-pop} outside
  626. of \macref{pprint-logical-block} are undefined.
  627. \endissue{LEXICAL-CONSTRUCT-GLOBAL-DEFINITION:UNDEFINED}
  628. \label Examples:\None.
  629. \label Side Effects::
  630. Might cause output
  631. %This next info supplied by Waters. -kmp 16-Oct-91
  632. to the \term{pretty printing stream} associated with the lexically current logical block.
  633. \label Affected By::
  634. \varref{*print-length*}, \varref{*print-circle*}.
  635. \label Exceptional Situations::
  636. An error is signaled (either at macro expansion time or at run time)
  637. if a usage of \macref{pprint-pop} occurs where there is no lexically
  638. containing \macref{pprint-logical-block} \term{form}.
  639. The consequences are undefined if \macref{pprint-pop} is executed outside
  640. of the \term{dynamic extent} of this \macref{pprint-logical-block}.
  641. \label See Also::
  642. \macref{pprint-exit-if-list-exhausted}, \macref{pprint-logical-block}.
  643. \label Notes::
  644. It is frequently a good idea to call \macref{pprint-exit-if-list-exhausted}
  645. before calling \macref{pprint-pop}.
  646. \endissue{PRETTY-PRINT-INTERFACE}
  647. \endcom
  648. %%% ========== PPRINT-TAB
  649. \begincom{pprint-tab}\ftype{Function}
  650. \issue{PRETTY-PRINT-INTERFACE}
  651. \label Syntax::
  652. \DefunWithValues pprint-tab {kind colnum colinc {\opt} stream} {\nil}
  653. \label Arguments and Values::
  654. \param{kind}---one of \kwd{line}, \kwd{section}, \kwd{line-relative},
  655. or \kwd{section-relative}.
  656. \param{colnum}---a non-negative \term{integer}.
  657. \param{colinc}---a non-negative \term{integer}.
  658. \param{stream}---an \term{output} \term{stream designator}.
  659. \label Description::
  660. Specifies tabbing to \param{stream} as performed by the standard \formatdirective{T}.
  661. \issue{GENERALIZE-PRETTY-PRINTER:UNIFY}
  662. If \param{stream} is a \term{pretty printing stream} and
  663. \thevalueof{*print-pretty*} is \term{true},
  664. \endissue{GENERALIZE-PRETTY-PRINTER:UNIFY}
  665. tabbing is performed;
  666. otherwise, \funref{pprint-tab} has no effect.
  667. The arguments \param{colnum} and \param{colinc} correspond to the two
  668. \param{parameters} to \formatOp{T} and are in terms of \term{ems}.
  669. The \param{kind} argument specifies the style of tabbing. It must be one of
  670. \kwd{line} (tab as by \formatOp{T}),
  671. \kwd{section} (tab as by \formatOp{:T},
  672. but measuring horizontal positions relative to
  673. the start of the dynamically enclosing section),
  674. \kwd{line-relative} (tab as by \formatOp{@T}), or
  675. \kwd{section-relative} (tab as by \formatOp{:@T},
  676. but measuring horizontal positions relative to
  677. the start of the dynamically enclosing section).
  678. \label Examples:\None.
  679. \label Side Effects:\None.
  680. \label Affected By:\None.
  681. \label Exceptional Situations::
  682. An error is signaled if \param{kind} is not one of \kwd{line},
  683. \kwd{section}, \kwd{line-relative}, or \kwd{section-relative}.
  684. \label See Also::
  685. \macref{pprint-logical-block}
  686. \label Notes:\None.
  687. \endissue{PRETTY-PRINT-INTERFACE}
  688. \endcom
  689. %%% ========== PRINT-OBJECT
  690. \begincom{print-object}\ftype{Standard Generic Function}
  691. \label Syntax::
  692. \DefgenWithValues print-object {object stream} {object}
  693. \label Method Signatures::
  694. \Defmeth {print-object} {\paren{\param{object} standard-object} \param{stream}}
  695. \issue{DEFSTRUCT-PRINT-FUNCTION-AGAIN:X3J13-MAR-93}
  696. \Defmeth {print-object} {\paren{\param{object} structure-object} \param{stream}}
  697. \endissue{DEFSTRUCT-PRINT-FUNCTION-AGAIN:X3J13-MAR-93}
  698. \label Arguments and Values::
  699. \param{object}---an \term{object}.
  700. \param{stream}---a \term{stream}.
  701. %% KMP: It should not be necessary to say this.
  702. % it cannot be the \term{symbols} \t\ or \nil.
  703. \label Description::
  704. \TheGF{print-object} writes the printed representation of \param{object}
  705. to \param{stream}.
  706. \Thefunction{print-object} is called by the \term{Lisp printer};
  707. it should not be called by the user.
  708. \issue{DEFSTRUCT-PRINT-FUNCTION-AGAIN:X3J13-MAR-93}
  709. Each implementation is required to provide a \term{method} on
  710. \theclass{standard-object} and on \theclass{structure-object}.
  711. In addition, each \term{implementation} must provide
  712. \term{methods} on enough other \term{classes}
  713. so as to ensure that there is always an applicable \term{method}.
  714. Implementations are free to add \term{methods} for other \term{classes}.
  715. Users may write \term{methods} for \funref{print-object} for their own
  716. \term{classes} if they do not wish to inherit an
  717. \term{implementation-dependent} \term{method}.
  718. The \term{method} on \theclass{structure-object} prints the object in the
  719. default \f{\#S} notation; \seesection\PrintingStructures.
  720. \endissue{DEFSTRUCT-PRINT-FUNCTION-AGAIN:X3J13-MAR-93}
  721. %\term{Methods} on \funref{print-object} must
  722. %obey the print control special variables.
  723. %The specific details are the following:
  724. \term{Methods} on \funref{print-object} are responsible for implementing
  725. their part of the semantics of the \term{printer control variables}, as follows:
  726. \beginlist
  727. \issue{DATA-IO:ADD-SUPPORT}
  728. \item{\varref{*print-readably*}}
  729. All methods for \funref{print-object} must obey \varref{*print-readably*}.
  730. This includes both user-defined methods and \term{implementation-defined} methods.
  731. Readable printing of \term{structures} and \term{standard objects}
  732. is controlled by their \funref{print-object} method,
  733. not by their \funref{make-load-form} \term{method}.
  734. \term{Similarity} for these \term{objects} is application dependent
  735. and hence is defined to be whatever these \term{methods} do;
  736. \seesection\Similarity.
  737. \endissue{DATA-IO:ADD-SUPPORT}
  738. \item{\varref{*print-escape*}}
  739. Each \term{method} must implement \varref{*print-escape*}.
  740. \item{\varref{*print-pretty*}}
  741. \issue{GENERALIZE-PRETTY-PRINTER:UNIFY}
  742. % The \varref{*print-pretty*} control variable can be ignored
  743. % by most \term{methods} other than the one for \term{lists}.
  744. The \term{method} may wish to perform specialized line breaking
  745. or other output conditional on \thevalueof{*print-pretty*}.
  746. For further information,
  747. see (for example) the \term{macro} \macref{pprint-fill}.
  748. See also \secref\PPrintDispatchTables\ and \secref\PrettyPrinterExamples.
  749. \endissue{GENERALIZE-PRETTY-PRINTER:UNIFY}
  750. \item{\varref{*print-length*}}
  751. \term{Methods} that produce output of indefinite length must obey
  752. \varref{*print-length*}.
  753. \issue{GENERALIZE-PRETTY-PRINTER:UNIFY}
  754. %, but most \term{methods} other than the one for
  755. %\term{lists} can ignore it.
  756. For further information,
  757. see (for example) the \term{macros} \macref{pprint-logical-block}
  758. and \macref{pprint-pop}.
  759. See also \secref\PPrintDispatchTables\ and \secref\PrettyPrinterExamples.
  760. \endissue{GENERALIZE-PRETTY-PRINTER:UNIFY}
  761. \item{\varref{*print-level*}}
  762. The printer takes care of \varref{*print-level*} automatically,
  763. provided that each \term{method} handles exactly one level of structure and
  764. calls \funref{write} (or an equivalent \term{function}) recursively if
  765. there are more structural levels. The printer's decision of whether an
  766. \term{object} has components (and therefore should not be printed when the
  767. printing depth is not less than \varref{*print-level*}) is
  768. \term{implementation-dependent}. In some implementations its
  769. \funref{print-object} \term{method} is not called;
  770. in others the \term{method} is called,
  771. and the determination that the \term{object} has components is based on what
  772. it tries to write to the \param{stream}.
  773. \item{\varref{*print-circle*}}
  774. \issue{PRINT-CIRCLE-STRUCTURE:USER-FUNCTIONS-WORK}
  775. When \thevalueof{*print-circle*} is \term{true},
  776. a user-defined
  777. \issue{DEFSTRUCT-PRINT-FUNCTION-AGAIN:X3J13-MAR-93}
  778. %print function
  779. \funref{print-object} \term{method}
  780. \endissue{DEFSTRUCT-PRINT-FUNCTION-AGAIN:X3J13-MAR-93}
  781. can print \term{objects} to the supplied \term{stream}
  782. using \funref{write},
  783. \funref{prin1},
  784. \funref{princ},
  785. or \funref{format}
  786. and expect circularities to be detected
  787. and printed using the \f{\#\i{n}\#} syntax.
  788. If a user-defined
  789. \issue{DEFSTRUCT-PRINT-FUNCTION-AGAIN:X3J13-MAR-93}
  790. %print function
  791. \funref{print-object} \term{method}
  792. \endissue{DEFSTRUCT-PRINT-FUNCTION-AGAIN:X3J13-MAR-93}
  793. prints to a \term{stream} other than the one
  794. that was supplied, then circularity detection starts over for that
  795. \term{stream}. See \varref{*print-circle*}.
  796. \endissue{PRINT-CIRCLE-STRUCTURE:USER-FUNCTIONS-WORK}
  797. \item{\varref{*print-base*},
  798. \varref{*print-radix*},
  799. \varref{*print-case*},
  800. \varref{*print-gensym*},
  801. and \varref{*print-array*}}
  802. These \term{printer control variables} apply to specific types of \term{objects}
  803. and are handled by the \term{methods} for those \term{objects}.
  804. \endlist
  805. If these rules are not obeyed, the results are undefined.
  806. %!!! What is the motivation for this?
  807. In general, the printer and the \funref{print-object} methods should not
  808. rebind the print control variables as they operate recursively through the
  809. structure, but this is \term{implementation-dependent}.
  810. In some implementations the \param{stream} argument passed to a
  811. \funref{print-object} \term{method} is not the original \term{stream},
  812. but is an intermediate \term{stream} that implements part of the printer.
  813. \term{methods} should therefore not depend on the identity of this \term{stream}.
  814. %All of the existing printing functions (\funref{write},
  815. %\funref{prin1}, \funref{print}, \funref{princ}, \funref{pprint},
  816. %\funref{write-to-string}, \funref{prin1-to-string},
  817. %\funref{princ-to-string}, the \formatOp{S} and \formatOp{A}
  818. %format operations, and the \formatOp{B}, \formatOp{D},
  819. %\formatOp{E}, \formatOp{F}, \formatOp{G}, \formatOp{\$},
  820. %\formatOp{O}, \formatOp{R}, and \formatOp{X}
  821. %format operations when they encounter a non-numeric
  822. %value) are required to be changed to go through the \funref{print-object}
  823. %generic function. Each implementation is required to
  824. %replace its former implementation of printing with one or more
  825. %\funref{print-object} methods.
  826. %% Flushed per X3J13. -kmp 05-Oct-93
  827. % Exactly which \term{classes} have \term{methods} for \funref{print-object}
  828. % is not specified; it would be valid for an implementation to have one
  829. % default \term{method} that is inherited by all system-defined \term{classes}.
  830. %% Per X3J13. -kmp 05-Oct-93
  831. \label Examples:\None.
  832. \label Affected By:\None.
  833. \label Exceptional Situations:\None.
  834. \label See Also::
  835. \funref{pprint-fill},
  836. \macref{pprint-logical-block},
  837. \macref{pprint-pop},
  838. \funref{write},
  839. \varref{*print-readably*},
  840. \varref{*print-escape*},
  841. \varref{*print-pretty*},
  842. \varref{*print-length*},
  843. {\secref\DefaultPrintObjMeths},
  844. \issue{DEFSTRUCT-PRINT-FUNCTION-AGAIN:X3J13-MAR-93}
  845. {\secref\PrintingStructures},
  846. \endissue{DEFSTRUCT-PRINT-FUNCTION-AGAIN:X3J13-MAR-93}
  847. {\secref\PPrintDispatchTables},
  848. {\secref\PrettyPrinterExamples}
  849. \label Notes:\None.
  850. \endcom
  851. %%% ========== PRINT-UNREADABLE-OBJECT
  852. \begincom{print-unreadable-object}\ftype{Macro}
  853. \issue{DATA-IO:ADD-SUPPORT}
  854. \label Syntax::
  855. \DefmacWithValues print-unreadable-object
  856. {\paren{object stream {\key} type identity} \starparam{form}}
  857. {\nil}
  858. \label Arguments and Values::
  859. \param{object}---an \term{object}; \eval.
  860. \param{stream}---%
  861. %% Changed per Barrett #8 (first public review) -kmp 14-May-93
  862. % the \term{name} of a \term{lexical variable} or \term{dynamic variable},
  863. % the \term{value} of which is a \term{stream};
  864. % used both unevaluated and evaluated.
  865. a \term{stream designator}; \eval.
  866. \param{type}---a \term{generalized boolean}; \eval.
  867. \param{identity}---a \term{generalized boolean}; \eval.
  868. \param{forms}---an \term{implicit progn}.
  869. %!!! it is evaluated. also used unevaluated to determine if any forms were present. hmmm...
  870. \label Description::
  871. Outputs a printed representation of \param{object} on \param{stream},
  872. beginning with ``\f{\#<}'' and ending with ``\f{>}''.
  873. Everything output to \param{stream} by the body \param{forms}
  874. is enclosed in the the angle brackets.
  875. If \param{type} is \term{true}, the output from \param{forms}
  876. is preceded by a brief description of the \param{object}'s
  877. \term{type} and a space character.
  878. If \param{identity} is \term{true},
  879. the output from \param{forms} is followed by a space character
  880. and a representation of the \param{object}'s identity,
  881. typically a storage address.
  882. If either \param{type} or \param{identity} is not supplied,
  883. its value is \term{false}. It is valid to omit the body \param{forms}.
  884. If \param{type} and \param{identity} are both true and there are no
  885. body \param{forms}, only one space character separates the type
  886. and the identity.
  887. \label Examples::
  888. ;; Note that in this example, the precise form of the output
  889. ;; is \term{implementation-dependent}.
  890. \code
  891. (defmethod print-object ((obj airplane) stream)
  892. (print-unreadable-object (obj stream :type t :identity t)
  893. (princ (tail-number obj) stream)))
  894. (prin1-to-string my-airplane)
  895. \EV "#<Airplane NW0773 36000123135>"
  896. \OV "#<FAA:AIRPLANE NW0773 17>"
  897. \endcode
  898. \label Affected By:\None.
  899. \label Exceptional Situations::
  900. If \varref{*print-readably*} is \term{true}, \funref{print-unreadable-object}
  901. signals an error \oftype{print-not-readable} without printing anything.
  902. \label See Also:\None.
  903. \label Notes:\None.
  904. \endissue{DATA-IO:ADD-SUPPORT}
  905. \endcom
  906. %%% ========== SET-PPRINT-DISPATCH
  907. \begincom{set-pprint-dispatch}\ftype{Function}
  908. \issue{PRETTY-PRINT-INTERFACE}
  909. \label Syntax::
  910. \DefunWithValues set-pprint-dispatch {type-specifier function {\opt} priority table} {\nil}
  911. \label Arguments and Values::
  912. \param{type-specifier}---a \term{type specifier}.
  913. % %This is now a valid type specifier! -kmp 30-Apr-91
  914. % or a list of the form
  915. % \f{(cons \param{type-specifier} \param{type-specifier})}
  916. % or {\tt (cons \param{type-specifier})}.
  917. % \editornote{KMP: Can the type-specifier in a cons specifier also be a
  918. % usage of CONS? Why don't we extend the CONS type specifier
  919. % rather than make this special case?}
  920. \param{function}---a \term{function}, a \term{function name}, or \nil.
  921. \param{priority}---a \term{real}.
  922. \Default{\f{0}}
  923. \param{table}---a \term{pprint dispatch table}.
  924. \Default{\thevalueof{*print-pprint-dispatch*}}
  925. \label Description::
  926. Installs an entry into the \term{pprint dispatch table} which is \param{table}.
  927. \param{Type-specifier}
  928. %% already said above. -kmp
  929. %must be a valid \term{type specifier} and
  930. is the \term{key}
  931. of the entry. The first action of \funref{set-pprint-dispatch} is to remove any
  932. pre-existing entry associated with \param{type-specifier}. This guarantees that
  933. there will never be two entries associated with the same \term{type specifier}
  934. in a given \term{pprint dispatch table}. Equality of \term{type specifiers} is
  935. tested by \funref{equal}.
  936. Two values are associated with each \term{type specifier} in a
  937. \term{pprint dispatch table}: a \param{function} and a \param{priority}.
  938. The \param{function} must accept two arguments: the \term{stream} to which output
  939. is sent and the \term{object} to be printed. The \param{function} should
  940. \term{pretty print} the \term{object} to the \param{stream}. The \param{function}
  941. can assume that object satisfies the \term{type} given by \term{type-specifier}.
  942. The \param{function} must obey \varref{*print-readably*}.
  943. %(see issue DATA-IO)
  944. Any values returned by the \param{function} are ignored.
  945. \param{Priority} is a priority to resolve conflicts
  946. when an object matches more than one entry.
  947. It is permissible for \param{function} to be \nil. In this situation,
  948. there will be no \param{type-specifier} entry in \param{table} after
  949. \funref{set-pprint-dispatch} returns.
  950. \label Examples:\None.
  951. \label Side Effects:\None.
  952. \label Affected By:\None.
  953. \label Exceptional Situations::
  954. An error is signaled if \param{priority} is not a \term{real}.
  955. \label See Also:\None.
  956. \label Notes::
  957. Since \term{pprint dispatch tables} are often used to control the pretty
  958. printing of Lisp code, it is common for the \param{type-specifier} to be
  959. an \term{expression} of the form
  960. \code
  961. (cons \param{car-type} \param{cdr-type})
  962. \endcode
  963. This signifies that the corresponding object must be a cons cell
  964. whose \term{car} matches the \term{type specifier} \param{car-type}
  965. and whose \term{cdr} matches the \term{type specifier} \param{cdr-type}.
  966. The \param{cdr-type} can be omitted in which case it defaults to \misc{t}.
  967. %% I don't think this note had any content. -kmp 13-Jan-91
  968. % ----------------------------------------------------------------------
  969. %
  970. % Implementation note: The restriction above is very useful to users
  971. % without actually limiting what Common Lisp implementors can do. It is
  972. % possible for implementors to set up any kind of pretty printing they
  973. % desire using the range of priorities available to them.
  974. %
  975. % ----------------------------------------------------------------------
  976. \endissue{PRETTY-PRINT-INTERFACE}
  977. \endcom
  978. %%% ========== PRIN1
  979. %%% ========== PRINC
  980. %%% ========== PRINT
  981. %%% ========== PPRINT
  982. %%% ========== WRITE
  983. \begincom{write, prin1, print, pprint, princ}\ftype{Function}
  984. %% 22.3.1 2
  985. \label Syntax::
  986. %% 22.3.1 5
  987. \DefunWithValuesNewline write
  988. {\param{object} {\key} \writekeys{stream}}
  989. {object}
  990. \DefunWithValues prin1 {object {\opt} output-stream} {object}
  991. \DefunWithValues princ {object {\opt} output-stream} {object}
  992. \DefunWithValues print {object {\opt} output-stream} {object}
  993. \DefunWithValues pprint {object {\opt} output-stream} {\novalues}
  994. %% 22.3.1 1
  995. %% 22.3.1 3
  996. \label Arguments and Values::
  997. \param{object}---an \term{object}.
  998. \param{output-stream}---an \term{output} \term{stream designator}.
  999. \Default{\term{standard output}}
  1000. \writekeydescriptions{\param{stream}---an \term{output} \term{stream designator}.
  1001. \Default{\term{standard output}}}
  1002. \label Description::
  1003. \funref{write}, \funref{prin1}, \funref{princ}, \funref{print}, and \funref{pprint}
  1004. write the printed representation of \param{object} to \param{output-stream}.
  1005. %!!! Does WRITE actually bind all the vars?? -kmp 8-May-91
  1006. \funref{write} is the general entry point to the \term{Lisp printer}.
  1007. For each explicitly supplied \term{keyword parameter} named in \thenextfigure,
  1008. the corresponding \term{printer control variable} is dynamically bound to its \term{value}
  1009. while printing goes on;
  1010. for each \term{keyword parameter} in \thenextfigure\ that is not explicitly supplied,
  1011. the value of the corresponding \term{printer control variable} is the same as it was
  1012. at the time \funref{write} was invoked.
  1013. Once the appropriate \term{bindings} are \term{established},
  1014. the \term{object} is output by the \term{Lisp printer}.
  1015. \tablefigtwo{Argument correspondences for the WRITE function.}{Parameter}{Corresponding Dynamic Variable}{
  1016. \param{array} & \varref{*print-array*} \cr
  1017. \param{base} & \varref{*print-base*} \cr
  1018. \param{case} & \varref{*print-case*} \cr
  1019. \param{circle} & \varref{*print-circle*} \cr
  1020. \param{escape} & \varref{*print-escape*} \cr
  1021. \param{gensym} & \varref{*print-gensym*} \cr
  1022. \param{length} & \varref{*print-length*} \cr
  1023. \param{level} & \varref{*print-level*} \cr
  1024. \param{lines} & \varref{*print-lines*} \cr
  1025. \param{miser-width} & \varref{*print-miser-width*} \cr
  1026. \param{pprint-dispatch} & \varref{*print-pprint-dispatch*} \cr
  1027. \param{pretty} & \varref{*print-pretty*} \cr
  1028. \param{radix} & \varref{*print-radix*} \cr
  1029. \param{readably} & \varref{*print-readably*} \cr
  1030. \param{right-margin} & \varref{*print-right-margin*} \cr
  1031. }
  1032. \issue{PRETTY-PRINT-INTERFACE}
  1033. \funref{prin1}, \funref{princ}, \funref{print}, and \funref{pprint} implicitly
  1034. \term{bind} certain print parameters to particular values. The remaining parameter
  1035. values are taken from
  1036. \varref{*print-array*},
  1037. \varref{*print-base*},
  1038. \varref{*print-case*},
  1039. \varref{*print-circle*},
  1040. \varref{*print-escape*},
  1041. \varref{*print-gensym*},
  1042. \varref{*print-length*},
  1043. \varref{*print-level*},
  1044. \varref{*print-lines*},
  1045. \varref{*print-miser-width*},
  1046. \varref{*print-pprint-dispatch*},
  1047. \varref{*print-pretty*},
  1048. \varref{*print-radix*},
  1049. and \varref{*print-right-margin*}.
  1050. \endissue{PRETTY-PRINT-INTERFACE}
  1051. \funref{prin1} produces output suitable for input to \funref{read}.
  1052. It binds \varref{*print-escape*} to \term{true}.
  1053. %% 2.5.2 3
  1054. %% 2.5.3 2
  1055. % I don't think this belongs here. --sjl 16 Mar 92
  1056. %\funref{prin1} prints any \term{string}
  1057. %or \term{bit vector}, not just a simple one, but \funref{read} will
  1058. %always construct a \term{simple string} or \term{simple bit vector}
  1059. %when it reads the appropriate syntax.
  1060. %% 22.3.1 8
  1061. \funref{princ} is just like \funref{prin1} except that the
  1062. output has no \term{escape} \term{characters}.
  1063. It binds \varref{*print-escape*} to \term{false}
  1064. \issue{PRINC-READABLY:X3J13-DEC-91}
  1065. and \varref{*print-readably*} to \term{false}.
  1066. \endissue{PRINC-READABLY:X3J13-DEC-91}
  1067. % I don't think this belongs here. --sjl 16 Mar 92
  1068. %A \term{symbol} is printed as the characters of its \term{name};
  1069. %a \term{string} is printed without surrounding \term{double-quotes};
  1070. %and there might be differences for other \term{types} as well.
  1071. The general rule is that output from \funref{princ} is intended to look
  1072. good to people, while output from \funref{prin1} is intended to
  1073. be acceptable to \funref{read}.
  1074. % I don't think this belongs here. --sjl 16 Mar 92
  1075. %\issue{PRINC-CHARACTER}
  1076. %For \term{characters},
  1077. %
  1078. %\code
  1079. % (princ character output-stream) \EQ (write-char character output-stream)
  1080. %\endcode
  1081. %\endissue{PRINC-CHARACTER}
  1082. %% 22.3.1 6
  1083. \funref{print} is just like \funref{prin1}
  1084. except that the printed representation
  1085. of \param{object} is preceded by a newline
  1086. and followed by a space.
  1087. %% 22.3.1 7
  1088. \funref{pprint} is just like \funref{print} except that the trailing
  1089. space is omitted and
  1090. \param{object} is printed with the \varref{*print-pretty*} flag \term{non-nil}
  1091. to produce pretty output.
  1092. \param{Output-stream} specifies the \term{stream} to which
  1093. output is to be sent.
  1094. \label Affected By::
  1095. \varref{*standard-output*},
  1096. \varref{*terminal-io*},
  1097. \varref{*print-escape*},
  1098. \varref{*print-radix*},
  1099. \varref{*print-base*},
  1100. \varref{*print-circle*},
  1101. \varref{*print-pretty*},
  1102. \varref{*print-level*},
  1103. \varref{*print-length*},
  1104. \varref{*print-case*},
  1105. \varref{*print-gensym*},
  1106. \varref{*print-array*},
  1107. \varref{*read-default-float-format*}.
  1108. \label Exceptional Situations:\None.
  1109. \label See Also::
  1110. \funref{readtable-case},
  1111. {\secref\FORMATPrinterOps}
  1112. \label Notes::
  1113. \Thefunctions{prin1} and \funref{print} do not bind \varref{*print-readably*}.
  1114. \code
  1115. (prin1 object output-stream)
  1116. \EQ (write object :stream output-stream :escape t)
  1117. \endcode
  1118. \issue{PRINC-READABLY:X3J13-DEC-91}
  1119. \code
  1120. (princ object output-stream)
  1121. \EQ (write object stream output-stream :escape nil :readably nil)
  1122. \endcode
  1123. \endissue{PRINC-READABLY:X3J13-DEC-91}
  1124. \code
  1125. (print object output-stream)
  1126. \EQ (progn (terpri output-stream)
  1127. (write object :stream output-stream
  1128. :escape t)
  1129. (write-char #\\space output-stream))
  1130. \endcode
  1131. \code
  1132. (pprint object output-stream)
  1133. \EQ (write object :stream output-stream :escape t :pretty t)
  1134. \endcode
  1135. \endcom
  1136. %%% ========== PRIN1-TO-STRING
  1137. %%% ========== PRINC-TO-STRING
  1138. %%% ========== WRITE-TO-STRING
  1139. \begincom{write-to-string, prin1-to-string, princ-to-string}\ftype{Function}
  1140. \label Syntax::
  1141. \DefunWithValuesNewline write-to-string
  1142. {object {\key} \writekeys{}}
  1143. {string}
  1144. \DefunWithValues prin1-to-string {object} {string}
  1145. \DefunWithValues princ-to-string {object} {string}
  1146. \label Arguments and Values::
  1147. \param{object}---an \term{object}.
  1148. \writekeydescriptions{}
  1149. \param{string}---a \term{string}.
  1150. \label Description::
  1151. \funref{write-to-string}, \funref{prin1-to-string}, and \funref{princ-to-string}
  1152. are used to create a \term{string} consisting of the printed representation
  1153. of \param{object}.
  1154. %% 22.3.1 11
  1155. \param{Object} is effectively printed as if by \funref{write},
  1156. \funref{prin1}, or \funref{princ}, respectively,
  1157. and the \term{characters} that would be output are made
  1158. into a \term{string}.
  1159. \funref{write-to-string} is the general output function.
  1160. It has the ability to specify all the parameters applicable
  1161. to the printing of \param{object}.
  1162. \funref{prin1-to-string} acts like \funref{write-to-string} with
  1163. \f{:escape t}, that is, escape characters are written where appropriate.
  1164. \funref{princ-to-string} acts like \funref{write-to-string} with
  1165. \issue{PRINC-READABLY:X3J13-DEC-91}
  1166. \f{:escape nil :readably nil}.
  1167. \endissue{PRINC-READABLY:X3J13-DEC-91}
  1168. Thus no \term{escape} \term{characters} are written.
  1169. All other keywords that would be specified to \funref{write-to-string}
  1170. are default values when \funref{prin1-to-string}
  1171. or \funref{princ-to-string} is invoked.
  1172. The meanings and defaults for the keyword arguments to \funref{write-to-string}
  1173. are the same as those for \funref{write}.
  1174. \label Examples::
  1175. \code
  1176. (prin1-to-string "abc") \EV "\\"abc\\""
  1177. (princ-to-string "abc") \EV "abc"
  1178. \endcode
  1179. \label Side Effects:\None.
  1180. \label Affected By::
  1181. \varref{*print-escape*},
  1182. \varref{*print-radix*},
  1183. \varref{*print-base*},
  1184. \varref{*print-circle*},
  1185. \varref{*print-pretty*},
  1186. \varref{*print-level*},
  1187. \varref{*print-length*},
  1188. \varref{*print-case*},
  1189. \varref{*print-gensym*},
  1190. \varref{*print-array*},
  1191. \varref{*read-default-float-format*}.
  1192. \label Exceptional Situations:\None.%!!! Not likely.
  1193. \label See Also::
  1194. \funref{write}
  1195. \label Notes::
  1196. \code
  1197. (write-to-string \param{object} \star{\curly{\param{key} \param{argument}}})
  1198. \EQ (with-output-to-string (#1=#:string-stream)
  1199. (write object :stream #1# \star{\curly{\param{key} \param{argument}}}))
  1200. (princ-to-string \param{object})
  1201. \EQ (with-output-to-string (string-stream)
  1202. (princ \param{object} string-stream))
  1203. (prin1-to-string \param{object})
  1204. \EQ (with-output-to-string (string-stream)
  1205. (prin1 \param{object} string-stream))
  1206. \endcode
  1207. \endcom
  1208. %-------------------- Printer Variables --------------------
  1209. %%% ========== *PRINT-ARRAY*
  1210. \begincom{*print-array*}\ftype{Variable}
  1211. \label Value Type::
  1212. a \term{generalized boolean}.
  1213. \label Initial Value::
  1214. \term{implementation-dependent}.
  1215. \label Description::
  1216. %% 22.1.6 55
  1217. Controls the format in which \term{arrays} are printed.
  1218. If it is \term{false}, the contents of \term{arrays} other than \term{strings}
  1219. are never printed. Instead, \term{arrays} are printed in a concise form using
  1220. \f{\#<} that gives enough information for the user to be able to identify the
  1221. \term{array}, but does not include the entire \term{array} contents.
  1222. If it is \term{true}, non-\term{string} \term{arrays} are printed using
  1223. \f{\#(...)}, \f{\#*}, or \f{\#nA} syntax.
  1224. \label Examples:\None.
  1225. \label Affected By::
  1226. The \term{implementation}.
  1227. \label See Also::
  1228. {\secref\SharpsignLeftParen},
  1229. {\secref\SharpsignLeftAngle}
  1230. \label Notes:\None.
  1231. \endcom
  1232. %%% ========== *PRINT-BASE*
  1233. %%% ========== *PRINT-RADIX*
  1234. \begincom{*print-base*, *print-radix*}\ftype{Variable}
  1235. \label Value Type::
  1236. \varref{*print-base*}---a \term{radix}.
  1237. \varref{*print-radix*}---a \term{generalized boolean}.
  1238. \label Initial Value::
  1239. The initial \term{value} of \varref{*print-base*} is \f{10}.
  1240. %%It's implied. -kmp 12-Jan-91
  1241. % (decimal radix).
  1242. The initial \term{value} of \varref{*print-radix*} is \term{false}.
  1243. \label Description::
  1244. \varref{*print-base*} and \varref{*print-radix*} control the printing
  1245. of \term{rationals}.
  1246. \Thevalueof{*print-base*} is called the \newterm{current output base}.
  1247. %% 22.1.6 44
  1248. \Thevalueof{*print-base*} is the \term{radix} in which the printer
  1249. will print \term{rationals}. For radices above \f{10}, letters of
  1250. the alphabet are used to represent digits above \f{9}.
  1251. %% 22.1.6 46
  1252. If \thevalueof{*print-radix*} is \term{true},
  1253. the printer will print a radix specifier to indicate the \term{radix}
  1254. in which it is printing a \term{rational} number. The radix specifier
  1255. is always printed using lowercase letters. If \varref{*print-base*}
  1256. is \f{2}, \f{8}, or \f{16}, then the radix specifier used is \f{\#b},
  1257. \f{\#o}, or \f{\#x}, respectively. For \term{integers}, base ten is
  1258. indicated by a trailing decimal point instead of a leading radix
  1259. specifier; for \term{ratios}, \f{\#10r} is used.
  1260. \label Examples::
  1261. \code
  1262. (let ((*print-base* 24.) (*print-radix* t))
  1263. (print 23.))
  1264. \OUT #24rN
  1265. \EV 23
  1266. (setq *print-base* 10) \EV 10
  1267. (setq *print-radix* nil) \EV NIL
  1268. (dotimes (i 35)
  1269. (let ((*print-base* (+ i 2))) ;print the decimal number 40
  1270. (write 40) ;in each base from 2 to 36
  1271. (if (zerop (mod i 10)) (terpri) (format t " "))))
  1272. \OUT 101000
  1273. \OUT 1111 220 130 104 55 50 44 40 37 34
  1274. \OUT 31 2C 2A 28 26 24 22 20 1J 1I
  1275. \OUT 1H 1G 1F 1E 1D 1C 1B 1A 19 18
  1276. \OUT 17 16 15 14
  1277. \EV NIL
  1278. (dolist (pb '(2 3 8 10 16))
  1279. (let ((*print-radix* t) ;print the integer 10 and
  1280. (*print-base* pb)) ;the ratio 1/10 in bases 2,
  1281. (format t "~&~S ~S~%" 10 1/10))) ;3, 8, 10, 16
  1282. \OUT #b1010 #b1/1010
  1283. \OUT #3r101 #3r1/101
  1284. \OUT #o12 #o1/12
  1285. \OUT 10. #10r1/10
  1286. \OUT #xA #x1/A
  1287. \EV NIL
  1288. \endcode
  1289. \label Affected By::
  1290. Might be \term{bound} by \funref{format}, and \funref{write}, \funref{write-to-string}.
  1291. \label See Also::
  1292. \funref{format},
  1293. \funref{write},
  1294. \funref{write-to-string}
  1295. \label Notes:\None.
  1296. \endcom
  1297. %%% ========== *PRINT-CASE*
  1298. \begincom{*print-case*}\ftype{Variable}
  1299. \label Value Type::
  1300. One of the \term{symbols} \kwd{upcase}, \kwd{downcase}, or \kwd{capitalize}.
  1301. \label Initial Value::
  1302. The \term{symbol} \kwd{upcase}.
  1303. \label Description::
  1304. %% 22.1.6 47
  1305. \Thevalueof{*print-case*} controls the case (upper, lower, or mixed) in
  1306. which to print any uppercase characters in the names of \term{symbols}
  1307. when vertical-bar syntax is not used.
  1308. \issue{PRINT-CASE-PRINT-ESCAPE-INTERACTION:VERTICAL-BAR-RULE-NO-UPCASE}
  1309. \issue{JUN90-TRIVIAL-ISSUES:3}
  1310. \varref{*print-case*} has an effect at all times when \thevalueof{*print-escape*}
  1311. is \term{false}. \varref{*print-case*} also has an effect when
  1312. \thevalueof{*print-escape*} is \term{true} unless inside an escape context
  1313. (\ie unless between \term{vertical-bars} or after a \term{slash}).
  1314. \issue{PRINT-CASE-BEHAVIOR:CLARIFY}
  1315. % Under no circumstance is
  1316. % any character that is lowercase in the internal representation ever presented
  1317. % as uppercase due to \varref{*print-case*}.
  1318. \endissue{PRINT-CASE-BEHAVIOR:CLARIFY}
  1319. \endissue{JUN90-TRIVIAL-ISSUES:3}
  1320. \endissue{PRINT-CASE-PRINT-ESCAPE-INTERACTION:VERTICAL-BAR-RULE-NO-UPCASE}
  1321. \label Examples::
  1322. \code
  1323. (defun test-print-case ()
  1324. (dolist (*print-case* '(:upcase :downcase :capitalize))
  1325. (format t "~&~S ~S~%" 'this-and-that '|And-something-elSE|)))
  1326. \EV TEST-PC
  1327. ;; Although the choice of which characters to escape is specified by
  1328. ;; *PRINT-CASE*, the choice of how to escape those characters
  1329. ;; (i.e., whether single escapes or multiple escapes are used)
  1330. ;; is implementation-dependent. The examples here show two of the
  1331. ;; many valid ways in which escaping might appear.
  1332. (test-print-case) ;Implementation A
  1333. \OUT THIS-AND-THAT |And-something-elSE|
  1334. \OUT this-and-that a\\n\\d-\\s\\o\\m\\e\\t\\h\\i\\n\\g-\\e\\lse
  1335. \OUT This-And-That A\\n\\d-\\s\\o\\m\\e\\t\\h\\i\\n\\g-\\e\\lse
  1336. \EV NIL
  1337. (test-print-case) ;Implementation B
  1338. \OUT THIS-AND-THAT |And-something-elSE|
  1339. \OUT this-and-that a|nd-something-el|se
  1340. \OUT This-And-That A|nd-something-el|se
  1341. \EV NIL
  1342. \endcode
  1343. \label Affected By:\None.
  1344. \label See Also::
  1345. \funref{write}
  1346. \label Notes::
  1347. %!!! Does issue READ-CASE-SENSITIVITY affect any of this?
  1348. \funref{read} normally converts lowercase characters appearing
  1349. in \term{symbols} to corresponding uppercase characters,
  1350. so that internally print names normally contain only uppercase characters.
  1351. %% 22.1.6 48
  1352. If \varref{*print-escape*} is \term{true},
  1353. lowercase characters in the \term{name} of a \term{symbol}
  1354. are always printed in lowercase, and
  1355. are preceded by a single escape character
  1356. or enclosed by multiple escape characters;
  1357. uppercase characters in the \term{name} of a \term{symbol}
  1358. are printed in upper case, in lower case, or in mixed case
  1359. so as to capitalize words, according to the value of
  1360. \varref{*print-case*}. The convention for what constitutes
  1361. a ``word'' is the same as for \funref{string-capitalize}.
  1362. \endcom
  1363. %%% ========== *PRINT-CIRCLE*
  1364. \begincom{*print-circle*}\ftype{Variable}
  1365. \issue{PRINT-CIRCLE-SHARED:RESPECT-PRINT-CIRCLE}
  1366. \label Value Type::
  1367. a \term{generalized boolean}.
  1368. \label Initial Value::
  1369. \term{false}.
  1370. \label Description::
  1371. %% 22.1.6 42
  1372. Controls the attempt to detect circularity and sharing in an \term{object}
  1373. being printed.
  1374. If \term{false},
  1375. the printing process merely proceeds by recursive descent without attempting
  1376. to detect circularity and sharing.
  1377. %% 22.1.6 43
  1378. If \term{true},
  1379. the printer will endeavor to detect cycles and sharing
  1380. in the structure to be printed,
  1381. and to use \f{\#\i{n}=} and \f{\#\i{n}\#}
  1382. syntax to indicate the circularities or shared components.
  1383. \issue{PRINT-CIRCLE-STRUCTURE:USER-FUNCTIONS-WORK}
  1384. If \term{true}, a user-defined
  1385. \issue{DEFSTRUCT-PRINT-FUNCTION-AGAIN:X3J13-MAR-93}
  1386. %print function
  1387. \funref{print-object} \term{method}
  1388. \endissue{DEFSTRUCT-PRINT-FUNCTION-AGAIN:X3J13-MAR-93}
  1389. can print
  1390. \term{objects} to the supplied \term{stream} using \funref{write}, \funref{prin1},
  1391. \funref{princ}, or \funref{format} and expect circularities and sharing
  1392. to be detected and printed using the \f{\#\i{n}\#} syntax.
  1393. \issue{DEFSTRUCT-PRINT-FUNCTION-AGAIN:X3J13-MAR-93}
  1394. %This applies to \term{methods} on \funref{print-object} in addition to
  1395. %\kwd{print-function} options.
  1396. \endissue{DEFSTRUCT-PRINT-FUNCTION-AGAIN:X3J13-MAR-93}
  1397. If a user-defined
  1398. \issue{DEFSTRUCT-PRINT-FUNCTION-AGAIN:X3J13-MAR-93}
  1399. %print function
  1400. \funref{print-object} \term{method}
  1401. \endissue{DEFSTRUCT-PRINT-FUNCTION-AGAIN:X3J13-MAR-93}
  1402. prints to a \term{stream} other than the one
  1403. that was supplied, then circularity detection starts over for that \term{stream}.
  1404. \endissue{PRINT-CIRCLE-STRUCTURE:USER-FUNCTIONS-WORK}
  1405. Note that implementations should not use \f{\#\i{n}\#} notation
  1406. when the \term{Lisp reader} would automatically assure sharing without it
  1407. (\eg as happens with \term{interned} \term{symbols}).
  1408. \label Examples::
  1409. \code
  1410. (let ((a (list 1 2 3)))
  1411. (setf (cdddr a) a)
  1412. (let ((*print-circle* t))
  1413. (write a)
  1414. :done))
  1415. \OUT #1=(1 2 3 . #1#)
  1416. \EV :DONE
  1417. \endcode
  1418. \label Affected By:\None.
  1419. \label See Also::
  1420. \funref{write}
  1421. \label Notes::
  1422. An attempt to print a circular structure with \varref{*print-circle*}
  1423. set to \nil\ may lead to looping behavior and failure to terminate.
  1424. \endissue{PRINT-CIRCLE-SHARED:RESPECT-PRINT-CIRCLE}
  1425. \endcom
  1426. %%% ========== *PRINT-ESCAPE*
  1427. \begincom{*print-escape*}\ftype{Variable}
  1428. \label Value Type::
  1429. a \term{generalized boolean}.
  1430. \label Initial Value::
  1431. %% 22.1.6 38
  1432. \term{true}.
  1433. \label Description::
  1434. %% 22.1.6 35
  1435. If \term{false},
  1436. escape characters and \term{package prefixes} are not output
  1437. when an expression is printed.
  1438. %% 22.1.6 36
  1439. If \term{true}, an attempt is made to print an \term{expression}
  1440. in such a way that it can be read again to produce an \funref{equal} \term{expression}.
  1441. (This is only a guideline; not a requirement. See \varref{*print-readably*}.)
  1442. For more specific details of how \thevalueof{*print-escape*}
  1443. affects the printing of certain \term{types},
  1444. \seesection\DefaultPrintObjMeths.
  1445. \label Examples::
  1446. \code
  1447. (let ((*print-escape* t)) (write #\\a))
  1448. \OUT #\\a
  1449. \EV #\\a
  1450. (let ((*print-escape* nil)) (write #\\a))
  1451. \OUT a
  1452. \EV #\\a
  1453. \endcode
  1454. \label Affected By::
  1455. \funref{princ}, \funref{prin1}, \funref{format}
  1456. \label See Also::
  1457. \funref{write}, \funref{readtable-case}
  1458. \label Notes::
  1459. \funref{princ} effectively binds \varref{*print-escape*} to \term{false}.
  1460. \funref{prin1} effectively binds \varref{*print-escape*} to \term{true}.
  1461. \endcom
  1462. %%% ========== *PRINT-GENSYM*
  1463. \begincom{*print-gensym*}\ftype{Variable}
  1464. \label Value Type::
  1465. a \term{generalized boolean}.
  1466. \label Initial Value::
  1467. \term{true}.
  1468. \label Description::
  1469. %% 22.1.6 49
  1470. Controls whether the prefix ``\f{\#:}'' is printed before
  1471. \term{apparently uninterned} \term{symbols}.
  1472. The prefix is printed before such \term{symbols}
  1473. if and only if \thevalueof{*print-gensym*} is \term{true}.
  1474. \label Examples::
  1475. \code
  1476. (let ((*print-gensym* nil))
  1477. (print (gensym)))
  1478. \OUT G6040
  1479. \EV #:G6040
  1480. \endcode
  1481. \label Affected By:\None.
  1482. \label See Also::
  1483. \funref{write}, \varref{*print-escape*}
  1484. \label Notes:\None.
  1485. \endcom
  1486. %%% ========== *PRINT-LEVEL*
  1487. %%% ========== *PRINT-LENGTH*
  1488. \begincom{*print-level*, *print-length*}\ftype{Variable}
  1489. \label Value Type::
  1490. a non-negative \term{integer}, or \nil.
  1491. \label Initial Value::
  1492. \nil.
  1493. \label Description::
  1494. %% 22.1.6 50
  1495. \varref{*print-level*} controls how many levels deep a nested \term{object} will print.
  1496. If it is \term{false}, then no control is exercised.
  1497. Otherwise, it is an \term{integer} indicating the maximum level to be printed.
  1498. An \term{object} to be printed is at level \f{0};
  1499. its components (as of a \term{list} or \term{vector}) are at level \f{1};
  1500. and so on.
  1501. If an \term{object} to be recursively printed has components
  1502. and is at a level equal to or greater than \thevalueof{*print-level*},
  1503. then the \term{object} is printed as ``\f{\#}''.
  1504. %% 22.1.6 51
  1505. \varref{*print-length*} controls how many elements at a given level are printed.
  1506. If it is \term{false}, there is no limit to the number of components printed.
  1507. Otherwise, it is an \term{integer} indicating the maximum number of \term{elements}
  1508. of an \term{object} to be printed. If exceeded, the printer will print
  1509. ``\f{...}'' in place of the other \term{elements}. In the case of a \term{dotted list},
  1510. if the \term{list} contains exactly as many \term{elements} as \thevalueof{*print-length*},
  1511. the terminating \term{atom} is printed rather than printing ``\f{...}''
  1512. %% 22.1.6 52
  1513. \varref{*print-level*} and \varref{*print-length*} affect the printing
  1514. of an any \term{object} printed with a list-like syntax. They do not affect
  1515. the printing of \term{symbols}, \term{strings}, and \term{bit vectors}.
  1516. \label Examples::
  1517. %% 22.1.6 54
  1518. \medbreak
  1519. \code
  1520. (setq a '(1 (2 (3 (4 (5 (6))))))) \EV (1 (2 (3 (4 (5 (6))))))
  1521. (dotimes (i 8)
  1522. (let ((*print-level* i))
  1523. (format t "~&~D -- ~S~%" i a)))
  1524. \OUT 0 -- #
  1525. \OUT 1 -- (1 #)
  1526. \OUT 2 -- (1 (2 #))
  1527. \OUT 3 -- (1 (2 (3 #)))
  1528. \OUT 4 -- (1 (2 (3 (4 #))))
  1529. \OUT 5 -- (1 (2 (3 (4 (5 #)))))
  1530. \OUT 6 -- (1 (2 (3 (4 (5 (6))))))
  1531. \OUT 7 -- (1 (2 (3 (4 (5 (6))))))
  1532. \EV NIL
  1533. \medbreak
  1534. (setq a '(1 2 3 4 5 6)) \EV (1 2 3 4 5 6)
  1535. (dotimes (i 7)
  1536. (let ((*print-length* i))
  1537. (format t "~&~D -- ~S~%" i a)))
  1538. \OUT 0 -- (...)
  1539. \OUT 1 -- (1 ...)
  1540. \OUT 2 -- (1 2 ...)
  1541. \OUT 3 -- (1 2 3 ...)
  1542. \OUT 4 -- (1 2 3 4 ...)
  1543. \OUT 5 -- (1 2 3 4 5 6)
  1544. \OUT 6 -- (1 2 3 4 5 6)
  1545. \EV NIL
  1546. \medbreak
  1547. (dolist (level-length '((0 1) (1 1) (1 2) (1 3) (1 4)
  1548. (2 1) (2 2) (2 3) (3 2) (3 3) (3 4)))
  1549. (let ((*print-level* (first level-length))
  1550. (*print-length* (second level-length)))
  1551. (format t "~&~D ~D -- ~S~%"
  1552. *print-level* *print-length*
  1553. '(if (member x y) (+ (car x) 3) '(foo . #(a b c d "Baz"))))))
  1554. \OUT 0 1 -- #
  1555. \OUT 1 1 -- (IF ...)
  1556. \OUT 1 2 -- (IF # ...)
  1557. \OUT 1 3 -- (IF # # ...)
  1558. \OUT 1 4 -- (IF # # #)
  1559. \OUT 2 1 -- (IF ...)
  1560. \OUT 2 2 -- (IF (MEMBER X ...) ...)
  1561. \OUT 2 3 -- (IF (MEMBER X Y) (+ # 3) ...)
  1562. \OUT 3 2 -- (IF (MEMBER X ...) ...)
  1563. \OUT 3 3 -- (IF (MEMBER X Y) (+ (CAR X) 3) ...)
  1564. \OUT 3 4 -- (IF (MEMBER X Y) (+ (CAR X) 3) '(FOO . #(A B C D ...)))
  1565. \EV NIL
  1566. \endcode
  1567. \label Affected By:\None.
  1568. \label See Also::
  1569. \funref{write}
  1570. \label Notes:\None.
  1571. % KMP:
  1572. % There has been some debate about how strictly these abbreviation guidelines
  1573. % should be applied.
  1574. %
  1575. % (write '(1 2 3) :length 1) prints (1 ...) or (1 2 3)?
  1576. % (write '(1 2 3) :length 2) prints (1 2 ...) or (1 2 3)?
  1577. %
  1578. % Barmar:
  1579. % While I've always secretly wished that these limits were defined such
  1580. % that they would be ignored when the length of the thing being replaced
  1581. % with "..." or "#" is less than or equal to the replacement text, I
  1582. % don't seriously believe there's really a need for implementation
  1583. % flexibility. This is a fairly straightforward piece of the language.
  1584. %
  1585. % Dick:
  1586. % As the original author of GPRINT, I am probably partly responsible for
  1587. % the behavior you see. I deliberately tried to do better than the
  1588. % default length and depth processing did. I was however copying what
  1589. % the standard Lispm software did at the time.
  1590. % Nevertheless, I agree with the point of view that there is no reason
  1591. % to make this complicated. Let's just have a simple abbreviation
  1592. % algorithm and hold everybody to it. It is not worth being more
  1593. % creative than that.
  1594. \endcom
  1595. %%% ========== *PRINT-LINES*
  1596. \begincom{*print-lines*}\ftype{Variable}
  1597. \label Value Type::
  1598. a non-negative \term{integer}, or \nil.
  1599. \label Initial Value::
  1600. \nil.
  1601. \label Description::
  1602. When \thevalueof{*print-lines*} is other than \nil,
  1603. it is a limit on the number of output lines produced when something is pretty
  1604. printed. If an attempt is made to go beyond that many lines,
  1605. ``\f{..}''\idxtext{Dot Dot}\idxcode{..}
  1606. is printed at the end of the last line followed by all of the
  1607. suffixes (closing delimiters) that are pending to be printed.
  1608. \label Examples::
  1609. \code
  1610. (let ((*print-right-margin* 25) (*print-lines* 3))
  1611. (pprint '(progn (setq a 1 b 2 c 3 d 4))))
  1612. \OUT (PROGN (SETQ A 1
  1613. \OUT B 2
  1614. \OUT C 3 ..))
  1615. \EV \novalues
  1616. \endcode
  1617. \label See Also:\None.
  1618. \label Notes::
  1619. The ``\f{..}'' notation is intentionally different than
  1620. the ``\f{...}'' notation used for level abbreviation, so that the two
  1621. different situations can be visually distinguished.
  1622. This notation is used to increase the likelihood that the \term{Lisp reader}
  1623. will signal an error if an attempt is later made to read the abbreviated output.
  1624. Note however that if the truncation occurs in a \term{string},
  1625. as in \f{"This string has been trunc.."}, the problem situation cannot be
  1626. detected later and no such error will be signaled.
  1627. \endcom
  1628. %%% ========== *PRINT-MISER-WIDTH*
  1629. \begincom{*print-miser-width*}\ftype{Variable}
  1630. \issue{PRETTY-PRINT-INTERFACE}
  1631. \label Value Type::
  1632. a non-negative \term{integer}, or \nil.
  1633. \label Initial Value::
  1634. \term{implementation-dependent}
  1635. \label Description::
  1636. If it is not \nil, the \term{pretty printer} switches to a compact
  1637. style of output (called miser style) whenever the width available for
  1638. printing a substructure is less than or equal to this many \term{ems}.
  1639. \label Examples:\None.
  1640. \label See Also:\None.
  1641. \label Notes:\None.
  1642. \endissue{PRETTY-PRINT-INTERFACE}
  1643. \endcom
  1644. %%% ========== *PRINT-PPRINT-DISPATCH*
  1645. \begincom{*print-pprint-dispatch*}\ftype{Variable}
  1646. \issue{PRETTY-PRINT-INTERFACE}
  1647. \label Value Type::
  1648. a \term{pprint dispatch table}.
  1649. \label Initial Value::
  1650. \term{implementation-dependent}, but the initial entries all use a
  1651. special class of priorities that have the property that they are less
  1652. than every priority that can be specified using \funref{set-pprint-dispatch},
  1653. so that the initial contents of any entry can be overridden.
  1654. \label Description::
  1655. The \term{pprint dispatch table} which currently controls the \term{pretty printer}.
  1656. \label Examples:\None.
  1657. \label See Also::
  1658. \varref{*print-pretty*},
  1659. {\secref\PPrintDispatchTables}
  1660. \label Notes::
  1661. The intent is that the initial \term{value} of this \term{variable} should
  1662. cause `traditional' \term{pretty printing} of \term{code}.
  1663. % Added on advice of Dick Waters:
  1664. In general, however, you can put a value in \varref{*print-pprint-dispatch*}
  1665. that makes pretty-printed output look exactly like non-pretty-printed output.
  1666. \issue{GENERALIZE-PRETTY-PRINTER:UNIFY}
  1667. % Setting \varref{*print-pretty*} to \term{true} means having \varref{*print-pprint-dispatch*}
  1668. % control printing---nothing more, and nothing less.
  1669. Setting \varref{*print-pretty*} to \term{true}
  1670. just causes the functions contained in the \term{current pprint dispatch table}
  1671. to have priority over normal \funref{print-object} methods;
  1672. it has no magic way of enforcing that those functions actually produce pretty
  1673. output. For details, \seesection\PPrintDispatchTables.
  1674. \endissue{GENERALIZE-PRETTY-PRINTER:UNIFY}
  1675. \endissue{PRETTY-PRINT-INTERFACE}
  1676. \endcom
  1677. %%% ========== *PRINT-PRETTY*
  1678. \begincom{*print-pretty*}\ftype{Variable}
  1679. \label Value Type::
  1680. a \term{generalized boolean}.
  1681. \label Initial Value::
  1682. %% 22.1.6 41
  1683. \term{implementation-dependent}.
  1684. \label Description::
  1685. Controls whether the \term{Lisp printer} calls the \term{pretty printer}.
  1686. %% 22.1.6 39
  1687. If it is \term{false},
  1688. the \term{pretty printer} is not used and
  1689. \issue{PRINTER-WHITESPACE:JUST-ONE-SPACE}
  1690. a minimum
  1691. %only a small amount
  1692. \endissue{PRINTER-WHITESPACE:JUST-ONE-SPACE}
  1693. of \term{whitespace}\meaning{1}
  1694. is output when printing an expression.
  1695. %% 22.1.6 40
  1696. If it is \term{true},
  1697. the \term{pretty printer} is used, and the \term{Lisp printer} will endeavor
  1698. to insert extra \term{whitespace}\meaning{1} where appropriate to make \term{expressions}
  1699. more readable.
  1700. \varref{*print-pretty*} has an effect even when \thevalueof{*print-escape*}
  1701. is \term{false}.
  1702. \label Examples::
  1703. \issue{FORMAT-PRETTY-PRINT:YES}
  1704. \code
  1705. (setq *print-pretty* 'nil) \EV NIL
  1706. (progn (write '(let ((a 1) (b 2) (c 3)) (+ a b c))) nil)
  1707. \OUT (LET ((A 1) (B 2) (C 3)) (+ A B C))
  1708. \EV NIL
  1709. (let ((*print-pretty* t))
  1710. (progn (write '(let ((a 1) (b 2) (c 3)) (+ a b c))) nil))
  1711. \OUT (LET ((A 1)
  1712. \OUT (B 2)
  1713. \OUT (C 3))
  1714. \OUT (+ A B C))
  1715. \EV NIL
  1716. ;; Note that the first two expressions printed by this next form
  1717. ;; differ from the second two only in whether escape characters are printed.
  1718. ;; In all four cases, extra whitespace is inserted by the pretty printer.
  1719. (flet ((test (x)
  1720. (let ((*print-pretty* t))
  1721. (print x)
  1722. (format t "~%~S " x)
  1723. (terpri) (princ x) (princ " ")
  1724. (format t "~%~A " x))))
  1725. (test '#'(lambda () (list "a" #\b 'c #'d))))
  1726. \OUT #'(LAMBDA ()
  1727. \OUT (LIST "a" #\b 'C #'D))
  1728. \OUT #'(LAMBDA ()
  1729. \OUT (LIST "a" #\b 'C #'D))
  1730. \OUT #'(LAMBDA ()
  1731. \OUT (LIST a b 'C #'D))
  1732. \OUT #'(LAMBDA ()
  1733. \OUT (LIST a b 'C #'D))
  1734. \EV NIL
  1735. \endcode
  1736. \endissue{FORMAT-PRETTY-PRINT:YES}
  1737. \label Affected By:\None.
  1738. \label See Also::
  1739. \funref{write}
  1740. \label Notes:\None.
  1741. \endcom
  1742. %%% ========== *PRINT-READABLY*
  1743. \begincom{*print-readably*}\ftype{Variable}
  1744. \issue{DATA-IO:ADD-SUPPORT}
  1745. \label Value Type::
  1746. a \term{generalized boolean}.
  1747. \label Initial Value::
  1748. %% 22.1.6 38
  1749. \term{false}.
  1750. \label Description::
  1751. %% 22.1.6 36
  1752. If \varref{*print-readably*} is \term{true},
  1753. some special rules for printing \term{objects} go into effect.
  1754. Specifically, printing any \term{object} $O\sub 1$ produces a printed
  1755. representation that, when seen by the \term{Lisp reader}
  1756. %% This additional restriction added in response to Loosemore #14, first public review
  1757. while the \term{standard readtable} is in effect,
  1758. will produce
  1759. an \term{object} $O\sub 2$ that is \term{similar} to $O\sub 1$.
  1760. The printed representation produced might or might not be the same as
  1761. the printed representation produced when \varref{*print-readably*} is \term{false}.
  1762. % If printing a readable printed representation of an \term{object} is not possible,
  1763. If printing an \term{object} \term{readably} is not possible,
  1764. an error \oftype{print-not-readable} is signaled rather than
  1765. using a syntax (\eg the ``\f{\#<}'' syntax) that would not be readable by
  1766. the same \term{implementation}.
  1767. If the \term{value} of some other \term{printer control variable} is such
  1768. that these requirements would be violated, the \term{value} of that other
  1769. \term{variable} is ignored.
  1770. \issue{PRINT-READABLY-BEHAVIOR:CLARIFY}
  1771. %%!!! Glag. I can't believe we voted this in.
  1772. %% I want (and *print-readably* *print-escape*) implies ...!
  1773. %% Grumbling mail sent to X3J13.
  1774. %% -kmp 22-Aug-93
  1775. Specifically, if \varref{*print-readably*} is \term{true},
  1776. printing proceeds as if
  1777. \varref{*print-escape*},
  1778. \varref{*print-array*},
  1779. and \varref{*print-gensym*} were also \term{true},
  1780. and as if
  1781. \varref{*print-length*},
  1782. \varref{*print-level*},
  1783. and \varref{*print-lines*} were \term{false}.
  1784. \endissue{PRINT-READABLY-BEHAVIOR:CLARIFY}
  1785. If \varref{*print-readably*} is \term{false},
  1786. the normal rules for printing and the normal interpretations
  1787. of other \term{printer control variables} are in effect.
  1788. Individual \term{methods} for \funref{print-object}, including user-defined
  1789. \term{methods}, are responsible for implementing these requirements.
  1790. If \varref{*read-eval*} is \term{false} and \varref{*print-readably*} is \term{true},
  1791. any such method that would output a reference to the ``\f{\#.}'' \term{reader macro}
  1792. will either output something else or will signal an error (as described above).
  1793. \label Examples::
  1794. \code
  1795. (let ((x (list "a" '\\a (gensym) '((a (b (c))) d e f g)))
  1796. (*print-escape* nil)
  1797. (*print-gensym* nil)
  1798. (*print-level* 3)
  1799. (*print-length* 3))
  1800. (write x)
  1801. (let ((*print-readably* t))
  1802. (terpri)
  1803. (write x)
  1804. :done))
  1805. \OUT (a a G4581 ((A #) D E ...))
  1806. \OUT ("a" |a| #:G4581 ((A (B (C))) D E F G))
  1807. \EV :DONE
  1808. ;; This is setup code is shared between the examples
  1809. ;; of three hypothetical implementations which follow.
  1810. (setq table (make-hash-table)) \EV #<HASH-TABLE EQL 0/120 32005763>
  1811. (setf (gethash table 1) 'one) \EV ONE
  1812. (setf (gethash table 2) 'two) \EV TWO
  1813. ;; Implementation A
  1814. (let ((*print-readably* t)) (print table))
  1815. Error: Can't print #<HASH-TABLE EQL 0/120 32005763> readably.
  1816. ;; Implementation B
  1817. ;; No standardized #S notation for hash tables is defined,
  1818. ;; but there might be an implementation-defined notation.
  1819. (let ((*print-readably* t)) (print table))
  1820. \OUT #S(HASH-TABLE :TEST EQL :SIZE 120 :CONTENTS (1 ONE 2 TWO))
  1821. \EV #<HASH-TABLE EQL 0/120 32005763>
  1822. ;; Implementation C
  1823. ;; Note that #. notation can only be used if *READ-EVAL* is true.
  1824. ;; If *READ-EVAL* were false, this same implementation might have to
  1825. ;; signal an error unless it had yet another printing strategy to fall
  1826. ;; back on.
  1827. (let ((*print-readably* t)) (print table))
  1828. \OUT #.(LET ((HASH-TABLE (MAKE-HASH-TABLE)))
  1829. \OUT (SETF (GETHASH 1 HASH-TABLE) ONE)
  1830. \OUT (SETF (GETHASH 2 HASH-TABLE) TWO)
  1831. \OUT HASH-TABLE)
  1832. \EV #<HASH-TABLE EQL 0/120 32005763>
  1833. \endcode
  1834. \label Affected By:\None.
  1835. \label See Also::
  1836. \funref{write}, \macref{print-unreadable-object}
  1837. \label Notes::
  1838. The rules for ``\term{similarity}'' imply that
  1839. \f{\#A} or \f{\#(} % )
  1840. syntax cannot be used for \term{arrays} of \term{element type}
  1841. other than \typeref{t}.
  1842. An implementation will have to use another syntax
  1843. or signal an error \oftype{print-not-readable}.
  1844. \issue{PRINT-READABLY-BEHAVIOR:CLARIFY}
  1845. % The printing of interned \term{symbols}, of \term{strings},
  1846. % and of \term{bit vectors} is not affected by \varref{*print-readably*}.
  1847. \endissue{PRINT-READABLY-BEHAVIOR:CLARIFY}
  1848. \endissue{DATA-IO:ADD-SUPPORT}
  1849. \endcom
  1850. %%% ========== *PRINT-RIGHT-MARGIN*
  1851. \begincom{*print-right-margin*}\ftype{Variable}
  1852. \issue{PRETTY-PRINT-INTERFACE}
  1853. \label Value Type::
  1854. a non-negative \term{integer}, or \nil.
  1855. \label Initial Value::
  1856. \nil.
  1857. \label Description::
  1858. If it is \term{non-nil}, it specifies the right margin (as \term{integer}
  1859. number of \term{ems}) to use when the \term{pretty printer} is making
  1860. layout decisions.
  1861. If it is \nil, the right margin is taken to be the maximum line length
  1862. such that output can be displayed without wraparound or truncation.
  1863. If this cannot be determined, an \term{implementation-dependent} value is used.
  1864. \label Examples:\None.
  1865. \label See Also:\None.
  1866. \label Notes::
  1867. This measure is in units of \term{ems} in order to be compatible with
  1868. \term{implementation-defined} variable-width fonts while still not
  1869. requiring the language to provide support for fonts.
  1870. \endissue{PRETTY-PRINT-INTERFACE}
  1871. \endcom
  1872. %-------------------- Printer Errors --------------------
  1873. %%% ========== PRINT-NOT-READABLE
  1874. \begincom{print-not-readable}\ftype{Condition Type}
  1875. \issue{DATA-IO:ADD-SUPPORT}
  1876. \label Class Precedence List::
  1877. \typeref{print-not-readable},
  1878. \typeref{error},
  1879. \typeref{serious-condition},
  1880. \typeref{condition},
  1881. \typeref{t}
  1882. \label Description::
  1883. \Thetype{print-not-readable} consists of error conditions that occur during
  1884. output while \varref{*print-readably*} is \term{true}, as a result of attempting
  1885. to write a printed representation with the \term{Lisp printer}
  1886. that would not be correctly read back with the \term{Lisp reader}.
  1887. The object which could not be printed is initialized by
  1888. \theinitkeyarg{object} to \funref{make-condition}, and is \term{accessed} by
  1889. \thefunction{print-not-readable-object}.
  1890. \endissue{DATA-IO:ADD-SUPPORT}
  1891. \label See Also::
  1892. \funref{print-not-readable-object}
  1893. \endcom%{print-not-readable}\ftype{Condition Type}
  1894. %%% ========== PRINT-NOT-READABLE-OBJECT
  1895. \begincom{print-not-readable-object}\ftype{Function}
  1896. \issue{DATA-IO:ADD-SUPPORT}
  1897. \label Syntax::
  1898. \DefunWithValues print-not-readable-object {condition} {object}
  1899. \label Arguments and Values::
  1900. \param{condition}---a \term{condition} \oftype{print-not-readable}.
  1901. \param{object}---an \term{object}.
  1902. \label Description::
  1903. Returns the \term{object} that could not be printed readably
  1904. in the situation represented by \param{condition}.
  1905. \label Examples:\None.
  1906. \label Affected By:\None.
  1907. \label Exceptional Situations:\None.
  1908. \label See Also::
  1909. \typeref{print-not-readable},
  1910. {\secref\Conditions}
  1911. \label Notes:\None.
  1912. %% Should not be needed.
  1913. %It is an error to use \macref{setf} with \funref{print-not-readable-object}.
  1914. \endissue{DATA-IO:ADD-SUPPORT}
  1915. \endcom
  1916. %%% ========== FORMAT
  1917. \begincom{format}\ftype{Function}
  1918. \label Syntax::
  1919. \DefunWithValues {format} {destination control-string {\rest} args} {result}
  1920. \label Arguments and Values::
  1921. \param{destination}---\nil,
  1922. \t,
  1923. a \term{stream},
  1924. or a \term{string} with a \term{fill pointer}.
  1925. \issue{FORMAT-STRING-ARGUMENTS:SPECIFY}
  1926. \param{control-string}---a \term{format control}.
  1927. \endissue{FORMAT-STRING-ARGUMENTS:SPECIFY}
  1928. \param{args}---\term{format arguments} for \param{control-string}.
  1929. \param{result}---if \param{destination} is \term{non-nil}, then \nil;
  1930. otherwise, a \term{string}.
  1931. \label Description::
  1932. %% 22.3.2 6
  1933. \funref{format} produces formatted output by outputting the characters
  1934. of \param{control-string} and observing that a \term{tilde}
  1935. introduces a directive. The character after the tilde, possibly preceded
  1936. by prefix parameters and modifiers, specifies what kind of formatting
  1937. is desired. Most directives use one or more elements of \param{args} to
  1938. create their output.
  1939. If \param{destination} is a \term{string}, a \term{stream}, or \t,
  1940. then the \param{result} is \nil. Otherwise, the \param{result} is
  1941. a \term{string} containing the `output.'
  1942. %% 22.3.1 21
  1943. \funref{format} is useful for producing nicely formatted text, producing
  1944. good-looking messages, and so on. \funref{format} can generate and return
  1945. a \term{string} or output to \param{destination}.
  1946. For details on how the \param{control-string} is interpreted,
  1947. \seesection\FormattedOutput.
  1948. \label Examples:\None.
  1949. \label Affected By::
  1950. \varref{*standard-output*},
  1951. \varref{*print-escape*},
  1952. \varref{*print-radix*},
  1953. \varref{*print-base*},
  1954. \varref{*print-circle*},
  1955. \varref{*print-pretty*},
  1956. \varref{*print-level*},
  1957. \varref{*print-length*},
  1958. \varref{*print-case*},
  1959. \varref{*print-gensym*},
  1960. \varref{*print-array*}.
  1961. \label Exceptional Situations::
  1962. \issue{STRING-OUTPUT-STREAM-BASHING:UNDEFINED}
  1963. If \param{destination} is a \term{string} with a \term{fill pointer},
  1964. the consequences are undefined if destructive modifications are performed
  1965. directly on the \term{string} during the \term{dynamic extent} of the call.
  1966. \endissue{STRING-OUTPUT-STREAM-BASHING:UNDEFINED}
  1967. \label See Also::
  1968. \funref{write},
  1969. {\secref\ImplementationDefinedScripts}
  1970. \label Notes:\None.
  1971. \endcom