concept-format.tex 72 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922
  1. % -*- Mode: TeX -*-
  2. %% Formatted Output
  3. \issue{PRETTY-PRINT-INTERFACE}
  4. \editornote{KMP: This is transplanted from FORMAT and will need a bit of work before
  5. it looks good standing alone. Bear with me.}
  6. %% 22.3.1 21
  7. \funref{format} is useful for producing nicely formatted text, producing
  8. good-looking messages, and so on. \funref{format} can generate and return
  9. a \term{string} or output to \param{destination}.
  10. The \param{control-string} argument to \funref{format} is actually a \term{format control}.
  11. % It can be any function at all that does the right things with its
  12. % arguments. --sjl 16 Mar 92
  13. %That is, it can be either a \term{format string} or a \term{function} that was returned
  14. That is, it can be either a \term{format string} or a \term{function},
  15. for example a \term{function} returned
  16. by the \macref{formatter} \term{macro}.
  17. If it is a \term{function}, the \term{function} is called with the appropriate
  18. output stream as its first argument and the data arguments to \funref{format}
  19. as its remaining arguments. The function should perform whatever output is
  20. necessary and return the unused tail of the arguments (if any).
  21. The compilation process performed by \macref{formatter} produces a \term{function}
  22. that would do with its \term{arguments} as the \funref{format} interpreter
  23. would do with those \term{arguments}.
  24. The remainder of this section describes what happens if the \param{control-string}
  25. is a \term{format string}.
  26. \endissue{PRETTY-PRINT-INTERFACE}
  27. % Removed redundant text --sjl 16 Mar 92
  28. %%% 22.3.2 6
  29. %\funref{format} produces formatted output by outputting the characters
  30. %of \param{control-string} and observing that a \term{tilde}
  31. %introduces a directive. The character after the tilde, possibly preceded
  32. %by prefix parameters and modifiers, specifies what kind of formatting
  33. %is desired.
  34. \param{Control-string} is composed of simple text (\term{characters})
  35. and embedded directives.
  36. %% 22.3.3 7
  37. \funref{format} writes the simple text as is;
  38. each embedded directive specifies further text output
  39. that is to appear at the corresponding point within the simple text.
  40. Most directives use one or more elements of \param{args} to
  41. create their output.
  42. %% 22.3.3 9
  43. A directive consists of a \term{tilde},
  44. optional prefix parameters
  45. separated by commas, optional \term{colon} and \term{at-sign} modifiers,
  46. and a single character indicating what kind of directive this is.
  47. \issue{FORMAT-ATSIGN-COLON}
  48. There is no required ordering between the \term{at-sign} and \term{colon} modifier.
  49. \endissue{FORMAT-ATSIGN-COLON}
  50. The \term{case} of the directive character is ignored.
  51. Prefix parameters are notated as signed (sign is optional) decimal numbers,
  52. or as a \term{single-quote} followed by a character.
  53. For example, \f{~5,'0d} can be used
  54. to print an \term{integer}
  55. in decimal radix in five columns with leading zeros,
  56. or \f{~5,'*d} to get leading asterisks.
  57. %% 22.3.2 10
  58. In place of a prefix parameter to a directive, \f{V} (or \f{v}) can be used.
  59. In this case, \funref{format} takes an argument from \param{args} as a parameter to
  60. the directive. The argument should be an \term{integer} or \term{character}.
  61. If the \param{arg} used by a \f{V} parameter is \nil,
  62. the effect is as if the parameter had been omitted.
  63. \f{\#} can be used in place of a prefix parameter; it
  64. represents the number of \param{args} remaining to be processed.
  65. When used within a recursive format, in the context of \f{~?} or \f{~\{},
  66. the \f{\#} prefix parameter represents the number of \term{format arguments}
  67. remaining within the recursive call.
  68. Examples of \term{format strings}:
  69. \showtwo{Examples of format control strings}{
  70. \f{"~S"} & ;This is an S directive with no parameters or modifiers. \cr
  71. \f{"~3,-4:@s"} & ;This is an S directive with two parameters, \f{3} and \f{-4}, \cr
  72. & ; and both the \term{colon} and \term{at-sign} flags. \cr
  73. \f{"~,+4S"} & ;Here the first prefix parameter is omitted and takes \cr
  74. & ; on its default value, while the second parameter is \f{4}. \cr
  75. }
  76. \funref{format} sends the output to \param{destination}.
  77. If \param{destination} is \nil,
  78. \funref{format} creates and returns a \term{string}
  79. containing the output from \param{control-string}.
  80. If \param{destination} is \term{non-nil},
  81. it must be a \term{string} with a \term{fill pointer},
  82. a \term{stream}, or the symbol \t.
  83. If \param{destination} is a \term{string} with a \term{fill pointer},
  84. the output is added to the end of the \term{string}.
  85. If \param{destination} is a \term{stream},
  86. the output is sent to that \term{stream}.
  87. If \param{destination} is \t,
  88. the output is sent to \term{standard output}.
  89. %% 22.3.2 8
  90. %%(left out)
  91. %% 22.3.2 15
  92. In the description of the directives that follows,
  93. the term \j{arg} in general
  94. refers to the next item of the set of \param{args} to be processed.
  95. The word or phrase at the beginning of each description is a mnemonic
  96. for the directive.
  97. \issue{FORMAT-PRETTY-PRINT:YES}
  98. \funref{format} directives do not bind any of the printer control
  99. variables (\varref{*print-...*}) except as specified in the following
  100. descriptions.
  101. Implementations may specify the binding of new, implementation-specific
  102. printer control variables for each \funref{format} directive, but they
  103. may neither bind any standard printer control variables not
  104. specified in description of a \funref{format}
  105. directive nor fail to bind
  106. any standard printer control variables as specified in the
  107. description.
  108. \endissue{FORMAT-PRETTY-PRINT:YES}
  109. % This section needs a lot of work on fonts. Maybe all the syntax parts
  110. % of the format directives should use \param instead of \i. Or change the
  111. % \i{foo} to \i{foo\/} to fix kerning problems.
  112. %
  113. % I decided to make a \j{...} which is \i{...\/} instead.
  114. % It's not pretty but it's fast and I'm out of time. -kmp 30-Aug-93.
  115. \beginsubsection{FORMAT Basic Output}
  116. \beginsubsubsection{Tilde C: Character}
  117. \idxtext{C (format directive)}\idxtext{Tilde C (format directive)}
  118. %% 22.3.2 38
  119. The next \j{arg} should be a \term{character};
  120. it is printed
  121. according to the modifier flags.
  122. %% 22.3.2 39
  123. \issue{FORMAT-OP-C}
  124. \f{~C} prints the \term{character}
  125. as if by using \funref{write-char} if it is a \term{simple character}.
  126. \term{Characters} that are not \term{simple}
  127. are not necessarily printed as if by \funref{write-char},
  128. but are displayed in an \term{implementation-defined}, abbreviated format.
  129. For example,
  130. \code
  131. (format nil "~C" #\\A) \EV "A"
  132. (format nil "~C" #\\Space) \EV " "
  133. \endcode
  134. \endissue{FORMAT-OP-C}
  135. %% 22.3.2 40
  136. \f{~:C} is the same as \f{~C} for \term{printing} \term{characters},
  137. but other \term{characters} are ``spelled out.'' The intent is that this
  138. is a ``pretty'' format for printing characters.
  139. For \term{simple} \term{characters} that are not \term{printing},
  140. what is spelled out is the \term{name} of the \term{character} (see \funref{char-name}).
  141. For \term{characters} that are not \term{simple} and not \term{printing},
  142. what is spelled out is \term{implementation-defined}.
  143. For example,
  144. \code
  145. (format nil "~:C" #\\A) \EV "A"
  146. (format nil "~:C" #\\Space) \EV "Space"
  147. ;; This next example assumes an implementation-defined "Control" attribute.
  148. (format nil "~:C" #\\Control-Space)
  149. \EV "Control-Space"
  150. \OV "c-Space"
  151. \endcode
  152. %% 22.3.2 41
  153. \f{~:@C} prints what \f{~:C} would, and then
  154. if the \term{character} requires unusual shift keys on the keyboard to type it,
  155. this fact is mentioned. For example,
  156. \begingroup
  157. \def\Partial{$\partial$}
  158. \code
  159. (format nil "~:@C" #\\Control-Partial) \EV "Control-{\Partial} (Top-F)"
  160. \endcode
  161. \endgroup
  162. This is the format used for telling the user about a key he is expected to type,
  163. in prompts, for instance. The precise output may depend not only
  164. on the implementation, but on the particular I/O devices in use.
  165. %% 22.3.2 42
  166. \f{~@C}
  167. prints the \term{character} in a way that the \term{Lisp reader} can understand,
  168. using \f{\#\\} syntax.
  169. \issue{FORMAT-PRETTY-PRINT:YES}
  170. \f{~@C} binds \varref{*print-escape*} to \t.
  171. \endissue{FORMAT-PRETTY-PRINT:YES}
  172. \endsubsubsection%{Tilde C: Character}
  173. \beginsubsubsection{Tilde Percent: Newline}
  174. \idxtext{Percent (format directive)}\idxtext{Tilde Percent (format directive)}
  175. %% 22.3.2 96
  176. This outputs a \f{\#\\Newline} character, thereby terminating the current
  177. output line and beginning a new one.
  178. \f{~\j{n}\%} outputs \j{n} newlines.
  179. No \j{arg} is used.
  180. \endsubsubsection%{Tilde Percent: Newline}
  181. \beginsubsubsection{Tilde Ampersand: Fresh-Line}
  182. \idxtext{Ampersand (format directive)}\idxtext{Tilde Ampersand (format directive)}
  183. %% 22.3.2 97
  184. Unless it can be determined that the output stream
  185. is already at the beginning of a line,
  186. this outputs a newline.
  187. \f{~\j{n}\&} calls \funref{fresh-line}
  188. and then outputs \j{n}\minussign 1 newlines.
  189. \f{~0\&} does nothing.
  190. \endsubsubsection%{Tilde Ampersand: Fresh-Line}
  191. \beginsubsubsection{Tilde Vertical-Bar: Page}
  192. \idxtext{Vertical-Bar (format directive)}\idxtext{Tilde Vertical-Bar (format directive)}
  193. %% 22.3.2 98
  194. This outputs a page separator character, if possible.
  195. \f{~\j{n}|} does this \j{n} times.
  196. \endsubsubsection%{Tilde Vertical-Bar: Page}
  197. %% 22.3.2 99
  198. \beginsubsubsection{Tilde Tilde: Tilde}
  199. \idxtext{Tilde (format directive)}\idxtext{Tilde Tilde (format directive)}
  200. This outputs a \term{tilde}. \f{~\j{n}~} outputs \j{n} tildes.
  201. \endsubsubsection%{Tilde Tilde: Tilde}
  202. \endsubsection%{FORMAT Basic Output}
  203. \beginsubsection{FORMAT Radix Control}
  204. \beginsubsubsection{Tilde R: Radix}
  205. \idxtext{R (format directive)}\idxtext{Tilde R (format directive)}
  206. %% 22.3.2 29
  207. \f{~\j{n}R} prints \j{arg} in radix \j{n}.
  208. The modifier flags and any remaining parameters are used as for
  209. the \f{~D} directive.
  210. \f{~D} is the same as \f{~10R}.
  211. The full form is
  212. \f{~\j{radix},\j{mincol},\j{padchar},\j{commachar},\j{comma-interval}R}.
  213. %% 22.3.2 30
  214. If no prefix parameters are given to \f{~R}, then a different
  215. interpretation is given. The argument should be an \term{integer}.
  216. For example, if \j{arg} is 4:
  217. %% 22.3.2 31
  218. \beginlist
  219. \itemitem{\bull}
  220. \f{~R} prints \j{arg} as a cardinal English number: \f{four}.
  221. %% 22.3.2 32
  222. \itemitem{\bull}
  223. \f{~:R} prints \j{arg} as an ordinal English number: \f{fourth}.
  224. %% 22.3.2 33
  225. \itemitem{\bull}
  226. \f{~@R} prints \j{arg} as a Roman numeral: \f{IV}.
  227. %% 22.3.2 34
  228. \itemitem{\bull}
  229. \f{~:@R} prints \j{arg} as an old Roman numeral: \f{IIII}.
  230. \endlist
  231. \issue{FORMAT-COMMA-INTERVAL}
  232. For example:
  233. \code
  234. (format nil "~,,' ,4:B" 13) \EV "1101"
  235. (format nil "~,,' ,4:B" 17) \EV "1 0001"
  236. (format nil "~19,0,' ,4:B" 3333) \EV "0000 1101 0000 0101"
  237. (format nil "~3,,,' ,2:R" 17) \EV "1 22"
  238. (format nil "~,,'|,2:D" #xFFFF) \EV "6|55|35"
  239. \endcode
  240. \endissue{FORMAT-COMMA-INTERVAL}
  241. \issue{FORMAT-PRETTY-PRINT:YES}
  242. If and only if the first parameter, \j{n}, is supplied,
  243. \f{~R} binds
  244. \varref{*print-escape*} to \term{false},
  245. \varref{*print-radix*} to \term{false},
  246. \varref{*print-base*} to \j{n},
  247. \issue{PRINC-READABLY:X3J13-DEC-91}
  248. and \varref{*print-readably*} to \term{false}.
  249. \endissue{PRINC-READABLY:X3J13-DEC-91}
  250. If and only if no parameters are supplied,
  251. \f{~R} binds \varref{*print-base*} to \f{10}.
  252. \endissue{FORMAT-PRETTY-PRINT:YES}
  253. \endsubsubsection%{Tilde R: Radix}
  254. \beginsubsubsection{Tilde D: Decimal}
  255. \idxtext{D (format directive)}\idxtext{Tilde D (format directive)}
  256. %% 22.3.2 20
  257. An \j{arg}, which should be an \term{integer},
  258. is printed in decimal radix.
  259. \f{~D} will never put a decimal point after the number.
  260. %% 22.3.2 21
  261. \f{~\j{mincol}D} uses
  262. a column width of \j{mincol}; spaces are inserted on
  263. the left if the number requires fewer than \j{mincol} columns for its digits
  264. and sign. If the number doesn't fit in \j{mincol} columns, additional columns
  265. are used as needed.
  266. %% 22.3.2 22
  267. \f{~\j{mincol},\j{padchar}D} uses \j{padchar} as the pad character
  268. instead of space.
  269. %% 22.3.2 23
  270. If \j{arg} is not an \term{integer}, it is printed in \f{~A} format and decimal base.
  271. %% 22.3.2 24
  272. The \f{@} modifier causes the number's sign to be printed always; the default
  273. is to print it only if the number is negative.
  274. \issue{FORMAT-COMMA-INTERVAL}
  275. The \f{:} modifier causes commas to be printed between groups of digits;
  276. \j{commachar} may be used to change the character used as the comma.
  277. \j{comma-interval}
  278. must be an \term{integer} and defaults to 3. When the \f{:}
  279. modifier is given to any of
  280. these directives, the \j{commachar}
  281. is printed between groups of \j{comma-interval}
  282. digits.
  283. \endissue{FORMAT-COMMA-INTERVAL}
  284. Thus the most general form of \f{~D} is
  285. \f{~\j{mincol},\j{padchar},\j{commachar},\j{comma-interval}D}.
  286. \issue{FORMAT-PRETTY-PRINT:YES}
  287. \f{~D} binds
  288. \varref{*print-escape*} to \term{false},
  289. \varref{*print-radix*} to \term{false},
  290. \varref{*print-base*} to \f{10},
  291. \issue{PRINC-READABLY:X3J13-DEC-91}
  292. and \varref{*print-readably*} to \term{false}.
  293. \endissue{PRINC-READABLY:X3J13-DEC-91}
  294. \endissue{FORMAT-PRETTY-PRINT:YES}
  295. \endsubsubsection%{Tilde D: Decimal}
  296. \beginsubsubsection{Tilde B: Binary}
  297. \idxtext{B (format directive)}\idxtext{Tilde B (format directive)}
  298. %% 22.3.2 25
  299. This is just like \f{~D} but prints in binary radix (radix 2)
  300. instead of decimal. The full form is therefore
  301. \f{~\j{mincol},\j{padchar},\j{commachar},\j{comma-interval}B}.
  302. \issue{FORMAT-PRETTY-PRINT:YES}
  303. \f{~B} binds
  304. \varref{*print-escape*} to \term{false},
  305. \varref{*print-radix*} to \term{false},
  306. \varref{*print-base*} to \f{2},
  307. \issue{PRINC-READABLY:X3J13-DEC-91}
  308. and \varref{*print-readably*} to \term{false}.
  309. \endissue{PRINC-READABLY:X3J13-DEC-91}
  310. \endissue{FORMAT-PRETTY-PRINT:YES}
  311. \endsubsubsection%{Tilde B: Binary}
  312. \beginsubsubsection{Tilde O: Octal}
  313. \idxtext{O (format directive)}\idxtext{Tilde O (format directive)}
  314. %% 22.3.2 26
  315. This is just like \f{~D} but prints in octal radix (radix 8)
  316. instead of decimal. The full form is therefore
  317. \f{~\j{mincol},\j{padchar},\j{commachar},\j{comma-interval}O}.
  318. \issue{FORMAT-PRETTY-PRINT:YES}
  319. \f{~O} binds
  320. \varref{*print-escape*} to \term{false},
  321. \varref{*print-radix*} to \term{false},
  322. \varref{*print-base*} to \f{8},
  323. \issue{PRINC-READABLY:X3J13-DEC-91}
  324. and \varref{*print-readably*} to \term{false}.
  325. \endissue{PRINC-READABLY:X3J13-DEC-91}
  326. \endissue{FORMAT-PRETTY-PRINT:YES}
  327. \endsubsubsection%{Tilde O: Octal}
  328. \beginsubsubsection{Tilde X: Hexadecimal}
  329. \idxtext{X (format directive)}\idxtext{Tilde X (format directive)}
  330. %% 22.3.2 27
  331. This is just like \f{~D} but prints in hexadecimal radix
  332. (radix 16) instead of decimal. The full form is therefore
  333. \f{~\j{mincol},\j{padchar},\j{commachar},\j{comma-interval}X}.
  334. \issue{FORMAT-PRETTY-PRINT:YES}
  335. \f{~X} binds
  336. \varref{*print-escape*} to \term{false},
  337. \varref{*print-radix*} to \term{false},
  338. \varref{*print-base*} to \f{16},
  339. \issue{PRINC-READABLY:X3J13-DEC-91}
  340. and \varref{*print-readably*} to \term{false}.
  341. \endissue{PRINC-READABLY:X3J13-DEC-91}
  342. \endissue{FORMAT-PRETTY-PRINT:YES}
  343. \endsubsubsection%{Tilde X: Hexadecimal}
  344. \endsubsection%{FORMAT Radix Control}
  345. \beginsubsection{FORMAT Floating-Point Printers}
  346. \beginsubsubsection{Tilde F: Fixed-Format Floating-Point}
  347. \idxtext{F (format directive)}\idxtext{Tilde F (format directive)}
  348. %% 22.3.2 43
  349. The next \j{arg} is printed as a \term{float}.
  350. %% 22.3.2 44
  351. The full form is \f{~\j{w},\j{d},\j{k},\j{overflowchar},\j{padchar}F}.
  352. The parameter \j{w}
  353. is the width of the field to be printed; \j{d} is the number
  354. of digits to print after the decimal point; \j{k} is a scale factor
  355. that defaults to zero.
  356. %% 22.3.2 45
  357. Exactly \j{w} characters will
  358. be output. First, leading copies of the character \j{padchar}
  359. (which defaults to a space) are printed, if necessary, to pad the
  360. field on the left.
  361. If the \j{arg} is negative, then a minus sign is printed;
  362. if the \j{arg} is not negative, then a plus sign is printed
  363. if and only if the \f{@}
  364. modifier was supplied. Then a sequence
  365. of digits, containing a single embedded decimal point, is printed;
  366. this represents the magnitude of the value of \j{arg} times $10^\j{k}$,
  367. rounded to \j{d} fractional digits.
  368. When rounding up and rounding down would produce printed values
  369. equidistant from the scaled value of \j{arg}, then the implementation
  370. is free to use either one. For example, printing the argument
  371. \f{6.375} using the format \f{~4,2F} may correctly produce
  372. either \f{6.37} or \f{6.38}.
  373. Leading zeros are not permitted, except that a single
  374. zero digit is output before the decimal point if the printed value
  375. is less than one, and this single zero digit is not output
  376. at all if \j{w}=\j{d}+1.
  377. %% 22.3.2 46
  378. If it is impossible to print the value in the required format in a field
  379. of width \j{w}, then one of two actions is taken. If the
  380. parameter \j{overflowchar} is supplied, then \j{w} copies of that
  381. parameter are printed instead of the scaled value of \j{arg}.
  382. If the \j{overflowchar} parameter is omitted, then the scaled value
  383. is printed using more than \j{w} characters, as many more as may be
  384. needed.
  385. %% 22.3.2 47
  386. If the \j{w} parameter is omitted, then the field is of variable width.
  387. In effect, a value is chosen
  388. for \j{w} in such a way that no leading pad characters need to be printed
  389. and exactly \j{d} characters will follow the decimal point.
  390. For example, the directive \f{~,2F} will print exactly
  391. two digits after the decimal point and as many as necessary before the
  392. decimal point.
  393. %% 22.3.2 48
  394. If the parameter \j{d} is omitted, then there is no constraint
  395. on the number of digits to appear after the decimal point.
  396. A value is chosen for \j{d} in such a way that as many digits
  397. as possible may be printed subject to the width constraint
  398. imposed by the parameter \j{w} and the constraint that no trailing
  399. zero digits may appear in the fraction, except that if the
  400. fraction to be printed is zero, then a single zero digit should
  401. appear after the decimal point if permitted by the width constraint.
  402. %% 22.3.2 49
  403. If both \j{w} and \j{d} are omitted, then the effect is to print
  404. the value using ordinary free-format output; \funref{prin1} uses this format
  405. for any number whose magnitude is either zero or between
  406. $10^{-3}$ (inclusive) and $10^7$ (exclusive).
  407. %% 22.3.2 50
  408. If \j{w} is omitted, then if the magnitude of \j{arg} is so large (or, if
  409. \j{d} is also omitted, so small) that more than 100 digits would have to
  410. be printed, then an implementation is free, at its discretion, to print
  411. the number using exponential notation instead, as if by the directive
  412. \f{~E} (with all parameters to \f{~E} defaulted, not
  413. taking their values from the \f{~F} directive).
  414. %% 22.3.2 51
  415. If \j{arg} is a \term{rational}
  416. number, then it is coerced to be a \term{single float}
  417. and then printed. Alternatively, an implementation is permitted to
  418. process a \term{rational}
  419. number by any other method that has essentially the
  420. same behavior but avoids loss of precision or overflow
  421. because of the coercion. If \j{w} and \j{d} are
  422. not supplied and the number has no exact decimal representation,
  423. for example \f{1/3}, some precision cutoff must be chosen
  424. by the implementation since only a finite number of digits may be printed.
  425. %% 22.3.2 52
  426. If \j{arg} is a \term{complex} number or some non-numeric
  427. \term{object},
  428. then it is printed using the format directive \f{~\j{w}D},
  429. thereby printing it in decimal radix and a minimum field width of \j{w}.
  430. \issue{FORMAT-PRETTY-PRINT:YES}
  431. \f{~F} binds
  432. \varref{*print-escape*} to \term{false}
  433. \issue{PRINC-READABLY:X3J13-DEC-91}
  434. and \varref{*print-readably*} to \term{false}.
  435. \endissue{PRINC-READABLY:X3J13-DEC-91}
  436. \endissue{FORMAT-PRETTY-PRINT:YES}
  437. \endsubsubsection%{Tilde F: Fixed-Format Floating-Point}
  438. \beginsubsubsection{Tilde E: Exponential Floating-Point}
  439. \idxtext{E (format directive)}\idxtext{Tilde E (format directive)}
  440. %% 22.3.2 62
  441. The next \j{arg} is printed as a \term{float} in exponential notation.
  442. %% 22.3.2 63
  443. The full form is
  444. \f{~\j{w},\j{d},\j{e},\j{k},\j{overflowchar},\j{padchar},\j{exponentchar}E}.
  445. The parameter \j{w}
  446. is the width of the field to be printed; \j{d} is the number
  447. of digits to print after the decimal point; \j{e} is the number
  448. of digits to use when printing the exponent;
  449. \j{k} is a scale factor that defaults to one (not zero).
  450. %% 22.3.2 64
  451. Exactly \j{w} characters will
  452. be output. First, leading copies of the character \j{padchar}
  453. (which defaults to a space) are printed, if necessary, to pad the
  454. field on the left.
  455. If the \j{arg} is negative, then a minus sign is printed;
  456. if the \j{arg} is not negative, then a plus sign is printed
  457. if and only if the \f{@}
  458. modifier was supplied. Then a sequence
  459. of digits containing a single embedded decimal point is printed.
  460. The form of this sequence of digits depends on the scale factor \j{k}.
  461. If \j{k} is zero, then \j{d} digits are printed after the decimal
  462. point, and a single zero digit appears before the decimal point if
  463. the total field width will permit it. If \j{k} is positive,
  464. then it must be strictly less than \j{d}+2; \j{k} significant digits
  465. are printed before the decimal point, and \j{d}\minussign \j{k}+1
  466. digits are printed after the decimal point. If \j{k} is negative,
  467. then it must be strictly greater than \minussign \j{d};
  468. a single zero digit appears before the decimal point if
  469. the total field width will permit it, and after the decimal point
  470. are printed first
  471. \minussign \j{k} zeros and then \j{d}+\j{k} significant digits.
  472. The printed fraction must be properly rounded.
  473. When rounding up and rounding down would produce printed values
  474. equidistant from the scaled value of \j{arg}, then the implementation
  475. is free to use either one. For example, printing the argument
  476. \f{637.5} using the format \f{~8,2E} may correctly produce
  477. either \f{6.37E+2} or \f{6.38E+2}.
  478. %% 22.3.2 65
  479. Following the digit sequence, the exponent is printed.
  480. First the character parameter \j{exponentchar} is printed; if this
  481. parameter is omitted, then the \term{exponent marker} that
  482. \funref{prin1} would use is printed, as determined from the
  483. type of the \term{float} and the current value of
  484. \varref{*read-default-float-format*}.
  485. Next, either a plus sign or a minus sign
  486. is printed, followed by \j{e} digits representing the power of
  487. ten by which the printed fraction must be multiplied
  488. to properly represent the rounded value of \j{arg}.
  489. %% 22.3.2 66
  490. If it is impossible to print the value in the required format in a field
  491. of width \j{w}, possibly because \j{k} is too large or too small
  492. or because the exponent cannot be printed in \j{e} character positions,
  493. then one of two actions is taken. If the
  494. parameter \j{overflowchar} is supplied, then \j{w} copies of that
  495. parameter are printed instead of the scaled value of \j{arg}.
  496. If the \j{overflowchar} parameter is omitted, then the scaled value
  497. is printed using more than \j{w} characters, as many more as may be
  498. needed; if the problem is that \j{d} is too small for the supplied \j{k}
  499. or that \j{e} is too small, then a larger value is used for \j{d} or \j{e}
  500. as may be needed.
  501. %% 22.3.2 67
  502. If the \j{w} parameter is omitted, then the field is of variable width.
  503. In effect a value is chosen
  504. for \j{w} in such a way that no leading pad characters need to be printed.
  505. %% 22.3.2 68
  506. If the parameter \j{d} is omitted, then there is no constraint
  507. on the number of digits to appear.
  508. A value is chosen for \j{d} in such a way that as many digits
  509. as possible may be printed subject to the width constraint
  510. imposed by the parameter \j{w}, the constraint of the scale factor \j{k},
  511. and the constraint that no trailing
  512. zero digits may appear in the fraction, except that if the
  513. fraction to be printed is zero then a single zero digit should
  514. appear after the decimal point.
  515. %% 22.3.2 69
  516. If the parameter \j{e} is omitted, then the exponent is printed
  517. using the smallest number of digits necessary to represent its value.
  518. %% 22.3.2 70
  519. If all of \j{w}, \j{d}, and \j{e} are omitted, then the effect is to print
  520. the value using ordinary free-format exponential-notation output;
  521. \funref{prin1} uses
  522. \issue{FORMAT-E-EXPONENT-SIGN:FORCE-SIGN}
  523. a similar
  524. \endissue{FORMAT-E-EXPONENT-SIGN:FORCE-SIGN}
  525. format for any non-zero number whose magnitude
  526. is less than $10^{-3}$ or greater than or equal to $10^7$.
  527. \issue{FORMAT-E-EXPONENT-SIGN:FORCE-SIGN}
  528. The only difference is that the \f{~E}
  529. directive always prints a plus or minus sign in front of the
  530. exponent, while \funref{prin1} omits the plus sign if the exponent is
  531. non-negative.
  532. \endissue{FORMAT-E-EXPONENT-SIGN:FORCE-SIGN}
  533. %% 22.3.2 71
  534. If \j{arg} is a \term{rational}
  535. number, then it is coerced to be a \term{single float}
  536. and then printed. Alternatively, an implementation is permitted to
  537. process a \term{rational}
  538. number by any other method that has essentially the
  539. same behavior but avoids loss of precision or overflow
  540. because of the coercion. If \j{w} and \j{d} are
  541. unsupplied and the number has no exact decimal representation,
  542. for example \f{1/3}, some precision cutoff must be chosen
  543. by the implementation since only a finite number of digits may be printed.
  544. %% 22.3.2 72
  545. If \j{arg} is a \term{complex} number or some non-numeric
  546. \term{object},
  547. then it is printed using the format directive \f{~\j{w}D},
  548. thereby printing it in decimal radix and a minimum field width of \j{w}.
  549. \issue{FORMAT-PRETTY-PRINT:YES}
  550. \f{~E} binds
  551. \varref{*print-escape*} to \term{false}
  552. \issue{PRINC-READABLY:X3J13-DEC-91}
  553. and \varref{*print-readably*} to \term{false}.
  554. \endissue{PRINC-READABLY:X3J13-DEC-91}
  555. \endissue{FORMAT-PRETTY-PRINT:YES}
  556. \endsubsubsection%{Tilde E: Exponential Floating-Point}
  557. \beginsubsubsection{Tilde G: General Floating-Point}
  558. \idxtext{G (format directive)}\idxtext{Tilde G (format directive)}
  559. %% 22.3.2 82
  560. The next \j{arg} is printed as a \term{float}
  561. in either fixed-format or exponential notation as appropriate.
  562. %% 22.3.2 83
  563. The full form is \f{~\j{w},\j{d},\j{e},\j{k},\j{overflowchar},\j{padchar},\j{exponentchar}G}.
  564. The format in which to print \j{arg} depends on the magnitude (absolute
  565. value) of the \j{arg}. Let \j{n} be an integer such that
  566. $10^{\j{n}-1}$ $\le$ |\j{arg}| < $10^\j{n}$.
  567. Let \j{ee} equal \j{e}+2, or 4 if \j{e} is omitted.
  568. Let \j{ww} equal \j{w}\minussign \j{ee},
  569. or \nil\ if \j{w} is omitted. If \j{d} is omitted, first let \j{q}
  570. be the number of digits needed to print \j{arg} with no loss
  571. of information and without leading or trailing zeros;
  572. then let \j{d} equal \f{(max \j{q} (min \j{n} 7))}.
  573. Let \j{dd} equal \j{d}\minussign \j{n}.
  574. %% 22.3.2 84
  575. If 0 $\le$ \j{dd} $\le$ \j{d}, then \j{arg} is printed
  576. as if by the format directives
  577. %!!! ",," ??? -kmp 12-May-91
  578. \f{~\j{ww},\j{dd},,\j{overflowchar},\j{padchar}F~\j{ee}@T}
  579. Note that the scale factor \j{k} is not passed to the \f{~F}
  580. directive. For all other values of \j{dd}, \j{arg} is printed as if
  581. by the format directive
  582. \f{~\j{w},\j{d},\j{e},\j{k},\j{overflowchar},\j{padchar},\j{exponentchar}E}
  583. %% 22.3.2 85
  584. In either case, an \f{@}
  585. modifier is supplied to the \f{~F}
  586. or \f{~E} directive if and only if one was supplied to the
  587. \f{~G} directive.
  588. \issue{FORMAT-PRETTY-PRINT:YES}
  589. \f{~G} binds
  590. \varref{*print-escape*} to \term{false}
  591. \issue{PRINC-READABLY:X3J13-DEC-91}
  592. and \varref{*print-readably*} to \term{false}.
  593. \endissue{PRINC-READABLY:X3J13-DEC-91}
  594. \endissue{FORMAT-PRETTY-PRINT:YES}
  595. \endsubsubsection%{Tilde G: General Floating-Point}
  596. \beginsubsubsection{Tilde Dollarsign: Monetary Floating-Point}
  597. \idxtext{Dollarsign (format directive)}\idxtext{Tilde Dollarsign (format directive)}
  598. %% 22.3.2 90
  599. The next \j{arg} is printed as a \term{float} in fixed-format notation.
  600. %% 22.3.2 91
  601. The full form is \f{~\j{d},\j{n},\j{w},\j{padchar}\$}.
  602. The parameter \j{d} is the number
  603. of digits to print after the decimal point (default value 2);
  604. \j{n} is the minimum number of digits to print before the decimal
  605. point (default value 1);
  606. \j{w} is the minimum total width of the field to be printed (default
  607. value 0).
  608. %% 22.3.2 92
  609. First padding and the sign are output.
  610. If the \j{arg} is negative, then a minus sign is printed;
  611. if the \j{arg} is not negative, then a plus sign is printed
  612. if and only if the \f{@} modifier was supplied.
  613. If the \f{:} modifier is used, the sign appears before any padding,
  614. and otherwise after the padding.
  615. If \j{w} is supplied and the number of other characters to be output
  616. is less than \j{w}, then copies of \j{padchar} (which defaults
  617. to a space) are output to
  618. make the total field width equal \j{w}.
  619. Then \j{n} digits are printed for the integer part of \j{arg},
  620. with leading zeros if necessary; then a decimal point;
  621. then \j{d} digits of fraction, properly rounded.
  622. %% 22.3.2 93
  623. If the magnitude of \j{arg} is so large that more than \j{m} digits would
  624. have to be printed, where \j{m} is the larger of \j{w} and 100, then an
  625. implementation is free, at its discretion, to print the number using
  626. exponential notation instead, as if by the directive
  627. \f{~\j{w},\j{q},,,,\j{padchar}E}, where \j{w} and \j{padchar} are
  628. present or omitted according to whether they were present or omitted in
  629. the \f{~\$} directive, and where \j{q}=\j{d}+\j{n}\minussign 1,
  630. where \j{d} and \j{n} are the (possibly default) values given to the
  631. \f{~\$} directive.
  632. %% 22.3.2 94
  633. If \j{arg} is a \term{rational}
  634. number, then it is coerced to be a \term{single float}
  635. and then printed. Alternatively, an implementation is permitted to
  636. process a \term{rational} number by any
  637. other method that has essentially the
  638. same behavior but avoids loss of precision or overflow
  639. because of the coercion.
  640. %% 22.3.2 95
  641. If \j{arg} is a \term{complex} number or some non-numeric
  642. \term{object},
  643. then it is printed using the format directive \f{~\j{w}D},
  644. thereby printing it in decimal radix and a minimum field width of \j{w}.
  645. \issue{FORMAT-PRETTY-PRINT:YES}
  646. \f{~\$} binds \varref{*print-escape*} to \term{false}
  647. \issue{PRINC-READABLY:X3J13-DEC-91}
  648. and \varref{*print-readably*} to \term{false}.
  649. \endissue{PRINC-READABLY:X3J13-DEC-91}
  650. \endissue{FORMAT-PRETTY-PRINT:YES}
  651. \endsubsubsection%{Tilde Dollarsign: Monetary Floating-Point}
  652. \endsubsection%{FORMAT Floating-Point Printers}
  653. \beginsubsection{FORMAT Printer Operations}
  654. \DefineSection{FORMATPrinterOps}
  655. \beginsubsubsection{Tilde A: Aesthetic}
  656. \idxtext{A (format directive)}\idxtext{Tilde A (format directive)}
  657. %% A originally stood for ASCII. This seems like a bad mnemonic in a portable standard.
  658. %% Replaced it with "Aesthetic". -kmp 30-Aug-93
  659. %% 22.3.2 16
  660. An \j{arg}, any \term{object},
  661. is printed without escape characters
  662. (as by \funref{princ}). If \j{arg} is a \term{string},
  663. its \term{characters}
  664. will be output verbatim.
  665. If \j{arg} is \nil\ it will be printed as \nil;
  666. the \term{colon} modifier (\f{~:A}) will cause an \j{arg} of \nil\ to be printed as \empty,
  667. but if \j{arg} is a composite structure, such as a \term{list} or \term{vector},
  668. any contained occurrences of \nil\ will still be printed as \nil.
  669. %% 22.3.2 17
  670. \f{~\j{mincol}A} inserts spaces on the right, if necessary, to make the
  671. width at least \j{mincol} columns. The \f{@}
  672. modifier causes the spaces
  673. to be inserted on the left rather than the right.
  674. %% 22.3.2 18
  675. \f{~\j{mincol},\j{colinc},\j{minpad},\j{padchar}A}
  676. is the full form of \f{~A},
  677. which allows control of the padding.
  678. The \term{string} is padded on the right (or on the left if the
  679. \f{@} modifier is used) with at least \j{minpad} copies
  680. of \j{padchar}; padding characters are then inserted \j{colinc} characters
  681. at a time until the total width is at least \j{mincol}.
  682. The defaults are \f{0} for \j{mincol} and \j{minpad}, \f{1} for \j{colinc},
  683. and the space character for \j{padchar}.
  684. \issue{FORMAT-PRETTY-PRINT:YES}
  685. \f{~A} binds \varref{*print-escape*} to \term{false},
  686. \issue{PRINC-READABLY:X3J13-DEC-91}
  687. and \varref{*print-readably*} to \term{false}.
  688. \endissue{PRINC-READABLY:X3J13-DEC-91}
  689. \endissue{FORMAT-PRETTY-PRINT:YES}
  690. \endsubsubsection%{Tilde A: Aesthetic}
  691. \beginsubsubsection{Tilde S: Standard}
  692. \idxtext{S (format directive)}\idxtext{Tilde S (format directive)}
  693. %% S originally stood for S-expression, a term which no longer has any meaning.
  694. %% Replaced it with "Standard", since this is the standard lisp representation.
  695. %% -kmp 30-Aug-93
  696. %% 22.3.2 19
  697. This is just like \f{~A}, but \j{arg} is printed with escape
  698. characters (as by \funref{prin1} rather than \f{princ}). The output is
  699. therefore suitable for input to \funref{read}. \f{~S} accepts
  700. all the arguments and modifiers that \f{~A} does.
  701. \issue{FORMAT-PRETTY-PRINT:YES}
  702. \f{~S} binds \varref{*print-escape*} to \t.
  703. \endissue{FORMAT-PRETTY-PRINT:YES}
  704. \endsubsubsection%{Tilde S: Standard}
  705. \issue{PRETTY-PRINT-INTERFACE}
  706. \beginsubsubsection{Tilde W: Write}
  707. \idxtext{W (format directive)}\idxtext{Tilde W (format directive)}
  708. An argument, any \term{object}, is printed obeying every printer control
  709. variable (as by \funref{write}). In addition, \f{~W} interacts correctly with depth
  710. abbreviation, by not resetting the depth counter to zero. \f{~W} does not
  711. accept parameters. If given the \term{colon} modifier, \f{~W} binds \varref{*print-pretty*}
  712. to \term{true}. If given the \term{at-sign} modifier, \f{~W} binds \varref{*print-level*}
  713. and \varref{*print-length*} to \nil.
  714. \f{~W} provides automatic support for the detection of circularity and
  715. sharing. If \thevalueof{*print-circle*} is not \nil\ and \f{~W} is applied
  716. to an argument that is a circular (or shared) reference, an appropriate
  717. \f{\#\param{n}\#} marker is inserted in the output instead of printing the argument.
  718. \endsubsubsection%{Tilde W: Write}
  719. \endissue{PRETTY-PRINT-INTERFACE}
  720. \endsubsection%{FORMAT Printer Operations}
  721. \beginsubsection{FORMAT Pretty Printer Operations}
  722. \issue{PRETTY-PRINT-INTERFACE}
  723. The following constructs provide access to the \term{pretty printer}:
  724. \beginsubsubsection{Tilde Underscore: Conditional Newline}
  725. \DefineSection{TildeUnderscore}
  726. \idxtext{Underscore (format directive)}\idxtext{Tilde Underscore (format directive)}
  727. Without any modifiers, \f{~_} is the same as \f{(pprint-newline :linear)}.
  728. \f{~@_} is the same as \f{(pprint-newline :miser)}.
  729. \f{~:_} is the same as \f{(pprint-newline :fill)}.
  730. \f{~:@_} is the same as \f{(pprint-newline :mandatory)}.
  731. \endsubsubsection%{Tilde Underscore: Conditional Newline}
  732. \beginsubsubsection{Tilde Less-Than-Sign: Logical Block}
  733. \DefineSection{TildeLessThanLogicalBlock}
  734. \idxtext{Less-Than-Sign (format directive)}\idxtext{Tilde Less-Than-Sign (format directive)}
  735. \f{~<...~:>}
  736. If \f{~:>} is used to terminate a \f{~<...~>},
  737. the directive is equivalent to a call to \macref{pprint-logical-block}.
  738. The argument corresponding to the \f{~<...~:>} directive is treated in
  739. the same way as the \term{list} argument to \funref{pprint-logical-block},
  740. thereby providing automatic support for non-\term{list} arguments and
  741. the detection of circularity, sharing, and depth abbreviation.
  742. The portion of the \param{control-string} nested within the \f{~<...~:>}
  743. specifies the \kwd{prefix} (or \kwd{per-line-prefix}), \kwd{suffix},
  744. and body of the \macref{pprint-logical-block}.
  745. The \param{control-string} portion enclosed by \f{~<...~:>} can be divided
  746. into segments \f{~<\param{prefix}~;\param{body}~;\param{suffix}~:>}
  747. by \f{~;} directives. If the first section is terminated by \f{~@;},
  748. it specifies a per-line prefix rather than a simple prefix.
  749. The \param{prefix} and \param{suffix} cannot contain format directives.
  750. An error is signaled if either the prefix or suffix fails to be a
  751. constant string or if the enclosed portion is divided into more than three segments.
  752. If the enclosed portion is divided into only two segments, the \param{suffix}
  753. defaults to the null string. If the enclosed portion consists of only
  754. a single segment, both the \param{prefix} and the \param{suffix} default to
  755. the null string. If the \term{colon} modifier is used (\ie \f{~:<...~:>}),
  756. the \param{prefix} and \param{suffix} default to \f{"("} and \f{")"}
  757. (respectively) instead of the null string.
  758. The body segment can be any arbitrary \term{format string}.
  759. This \term{format string} is applied to the elements of the list
  760. corresponding to the \f{~<...~:>} directive as a whole.
  761. Elements are extracted from this list using \macref{pprint-pop},
  762. thereby providing automatic support for malformed lists, and the detection
  763. of circularity, sharing, and length abbreviation.
  764. Within the body segment, \f{~{\hat}} acts like \macref{pprint-exit-if-list-exhausted}.
  765. \f{~<...~:>} supports a feature not supported by \macref{pprint-logical-block}.
  766. If \f{~:@>} is used to terminate the directive (\ie \f{~<...~:@>}),
  767. then a fill-style conditional newline is automatically inserted after each
  768. group of blanks immediately contained in the body (except for blanks
  769. after a ~\NewlineChar\ directive). This makes it easy to achieve the
  770. equivalent of paragraph filling.
  771. If the \term{at-sign} modifier is used with \f{~<...~:>}, the entire remaining argument
  772. list is passed to the directive as its argument. All of the remaining
  773. arguments are always consumed by \f{~@<...~:>}, even if they are not all used
  774. by the \term{format string} nested in the directive. Other than the difference in
  775. its argument, \f{~@<...~:>} is exactly the same as \f{~<...~:>} except that
  776. circularity detection is not applied if \f{~@<...~:>} is encountered at top
  777. level in a \term{format string}. This ensures that circularity detection is
  778. applied only to data lists, not to \term{format argument} \term{lists}.
  779. \f{" . \#\param{n}\#"} is printed if circularity or sharing has to be indicated
  780. for its argument as a whole.
  781. To a considerable extent, the basic form of the directive \f{~<...~>} is
  782. incompatible with the dynamic control of the arrangement of output by
  783. \f{~W}, \f{~_}, \f{~<...~:>}, \f{~I}, and \f{~:T}. As a result, an error
  784. is signaled if any of these directives is nested within \f{~<...~>}.
  785. Beyond this, an error is also signaled if the \f{~<...~:;...~>} form of
  786. \f{~<...~>} is used in the same \term{format string} with
  787. \f{~W}, \f{~_}, \f{~<...~:>}, \f{~I}, or \f{~:T}.
  788. See also \secref\TildeLessThanJustification.
  789. \endsubsubsection%{Tilde Less-Than-Sign: Logical Block}
  790. \beginsubsubsection{Tilde I: Indent}
  791. \DefineSection{TildeI}
  792. \idxtext{I (format directive)}\idxtext{Tilde I (format directive)}
  793. \f{~\param{n}I} is the same as \f{(pprint-indent :block n)}.
  794. \f{~\param{n}:I} is the same as \f{(pprint-indent :current n)}.
  795. In both cases, \param{n} defaults to zero, if it is omitted.
  796. \endsubsubsection%{Tilde I: Indent}
  797. \beginsubsubsection{Tilde Slash: Call Function}
  798. \idxtext{Slash (format directive)}\idxtext{Tilde Slash (format directive)}
  799. \f{~/\param{name}/}
  800. User defined functions can be called from within a format
  801. string by using the directive \f{~/\param{name}/}.
  802. The \term{colon} modifier, the \term{at-sign} modifier, and arbitrarily many parameters
  803. can be specified with the \f{~/\param{name}/} directive.
  804. \param{name} can be any arbitrary string that does not contain a "/".
  805. All of the characters in \param{name} are treated as if they were upper case.
  806. If \param{name} contains a single \term{colon} (\f{:}) or double \term{colon} (\f{::}),
  807. then everything up to but not including the first \f{":"} or \f{"::"}
  808. is taken to be a \term{string} that names a \term{package}.
  809. Everything after the first \f{":"} or \f{"::"} (if any) is taken to be a
  810. \term{string} that names a \f{symbol}. The function corresponding to a
  811. \f{~/name/} directive is obtained by looking up the \term{symbol}
  812. that has the indicated name in the indicated \term{package}.
  813. If \param{name} does not contain a \f{":"} or \f{"::"},
  814. %then the whole \param{name} string is looked up in \thepackage{user}.
  815. then the whole \param{name} string is looked up in \thepackage{common-lisp-user}.
  816. When a \f{~/name/} directive is encountered,
  817. the indicated function is called with four or more arguments.
  818. The first four arguments are:
  819. the output stream,
  820. the \term{format argument} corresponding to the directive,
  821. a \term{generalized boolean} that is \term{true} if the \term{colon} modifier was used,
  822. and a \term{generalized boolean} that is \term{true} if the \term{at-sign} modifier was used.
  823. The remaining arguments consist of any parameters specified with the directive.
  824. The function should print the argument appropriately.
  825. Any values returned by the function are ignored.
  826. The three \term{functions}
  827. \funref{pprint-linear},
  828. \funref{pprint-fill},
  829. and \funref{pprint-tabular}
  830. are specifically designed so that they can be called by \f{~/.../}
  831. (\ie \f{~/pprint-linear/}, \f{~/pprint-fill/}, and \f{~/pprint-tabular/}).
  832. In particular they take \term{colon} and \term{at-sign} arguments.
  833. \endissue{PRETTY-PRINT-INTERFACE}
  834. \endsubsubsection%{Tilde Slash: Call Function}
  835. \endsubsection%{FORMAT Pretty Printer Operations}
  836. \beginsubsection{FORMAT Layout Control}
  837. \beginsubsubsection{Tilde T: Tabulate}
  838. \idxtext{T (format directive)}\idxtext{Tilde T (format directive)}
  839. %% 22.3.2 102
  840. This spaces over to a given column.
  841. \f{~\j{colnum},\j{colinc}T} will output
  842. sufficient spaces to move the cursor to column \j{colnum}. If the cursor
  843. is already at or beyond column \j{colnum}, it will output spaces to move it to
  844. column \j{colnum}+\j{k}*\j{colinc} for the smallest positive integer
  845. \j{k} possible, unless \j{colinc} is zero, in which case no spaces
  846. are output if the cursor is already at or beyond column \j{colnum}.
  847. \j{colnum} and \j{colinc} default to \f{1}.
  848. %% 22.3.2 103
  849. If for some reason the current absolute column position cannot be determined
  850. by direct inquiry,
  851. \funref{format}
  852. may be able to deduce the current column position by noting
  853. that certain directives (such as \f{~\%}, or \f{~\&},
  854. or \f{~A}
  855. with the argument being a string containing a newline) cause
  856. the column position to be reset to zero, and counting the number of characters
  857. emitted since that point. If that fails, \funref{format}
  858. may attempt a
  859. similar deduction on the riskier assumption that the destination was
  860. at column zero when \funref{format}
  861. was invoked. If even this heuristic fails
  862. or is implementationally inconvenient, at worst
  863. the \f{~T} operation will simply output two spaces.
  864. %% 22.3.2 104
  865. \f{~@T} performs relative tabulation.
  866. \f{~\j{colrel},\j{colinc}@T} outputs \j{colrel} spaces
  867. and then outputs the smallest non-negative
  868. number of additional spaces necessary to move the cursor
  869. to a column that is a multiple
  870. of \j{colinc}. For example, the directive
  871. \f{~3,8@T} outputs
  872. three spaces and then moves the cursor to a ``standard multiple-of-eight
  873. tab stop'' if not at one already.
  874. If the current output column cannot be determined, however,
  875. then \j{colinc} is ignored, and exactly \j{colrel} spaces are output.
  876. If the \term{colon} modifier is used with the \f{~T} directive,
  877. the tabbing computation is done relative to the horizontal position where the
  878. section immediately containing the directive begins, rather than with
  879. respect to a horizontal position of zero. The numerical parameters are
  880. both interpreted as being in units of \term{ems} and both default to \f{1}.
  881. \f{~\param{n},\param{m}:T} is the same as
  882. \f{(pprint-tab :section \param{n} \param{m})}.
  883. \f{~\param{n},\param{m}:@T} is the same as
  884. \f{(pprint-tab :section-relative \param{n} \param{m})}.
  885. \endsubsubsection%{Tilde T: Tab}
  886. \beginsubsubsection{Tilde Less-Than-Sign: Justification}
  887. \DefineSection{TildeLessThanJustification}
  888. \idxtext{Less-Than-Sign (format directive)}\idxtext{Tilde Less-Than-Sign (format directive)}
  889. %% 22.3.2 136
  890. \f{~\j{mincol},\j{colinc},\j{minpad},\j{padchar}<\j{str}~>}
  891. This justifies the text produced by processing \j{str}
  892. within a field at least \j{mincol} columns wide. \j{str}
  893. may be divided up into segments with \f{~;}, in which case the
  894. spacing is evenly divided between the text segments.
  895. %% 22.3.2 137
  896. With no modifiers, the leftmost text segment is left justified in the
  897. field, and the rightmost text segment is right justified. If there is
  898. only one text element, as a special case, it is right justified.
  899. The \f{:} modifier causes
  900. spacing to be introduced before the first text segment; the
  901. \f{@} modifier causes spacing to be added after the last.
  902. The \j{minpad} parameter (default \f{0}) is the minimum number of
  903. padding characters to be output between each segment.
  904. The padding character is supplied by \j{padchar},
  905. which defaults to the space character.
  906. If the total width needed to satisfy these constraints is greater
  907. than \j{mincol}, then the width used is \j{mincol}+\j{k}*\j{colinc}
  908. for the smallest possible non-negative integer value \j{k}.
  909. \j{colinc} defaults to \f{1}, and \j{mincol} defaults to \f{0}.
  910. %% 22.3.2 139
  911. Note that \j{str} may include \funref{format} directives.
  912. All the clauses in \j{str} are processed in order;
  913. it is the resulting pieces of text that are justified.
  914. %% 22.3.2 140
  915. The \f{~\hat } directive may be used to terminate processing of the
  916. clauses prematurely, in which case only the completely processed clauses
  917. are justified.
  918. %% 22.3.2 141
  919. If the first clause of a \f{~<}
  920. is terminated with \f{~:;} instead of
  921. \f{~;}, then it is used in a special way. All of the clauses are
  922. processed (subject to \f{~\hat }, of course), but the
  923. first one is not used
  924. in performing the spacing and padding. When the padded result has been
  925. determined, then if it will fit on the current line of output, it is
  926. output, and the text for the first clause is discarded. If, however, the
  927. padded text will not fit on the current line, then the text segment for
  928. the first clause is output before the padded text. The first clause
  929. ought to contain a newline (such as a \f{~\%} directive). The first
  930. clause is always processed, and so any arguments it refers to will be
  931. used; the decision is whether to use the resulting segment of text, not
  932. whether to process the first clause. If the \f{~:;} has a prefix
  933. parameter \j{n}, then the padded text must fit on the current line with
  934. \j{n} character positions to spare to avoid outputting the first clause's
  935. text. For example, the control string
  936. \code
  937. "~%;; ~\lbr\ ~<~%;; ~1:; ~S~>~\hat\ ,~\rbr\ .~%"
  938. \endcode
  939. can be used to print a list of items separated by commas without
  940. breaking items over line boundaries, beginning each line with
  941. \f{;; }. The prefix parameter
  942. \f{1} in \f{~1:;} accounts for the width of the
  943. comma that will follow the justified item if it is not the last
  944. element in the list, or the period
  945. if it is. If \f{~:;} has a second
  946. prefix parameter, then it is used as the width of the line,
  947. thus overriding the natural line width of the output stream. To make
  948. the preceding example use a line width of 50, one would write
  949. \code
  950. "~%;; ~\lbr\ ~<~%;; ~1,50:; ~S~>~\hat\ ,~\rbr \ .~%"
  951. \endcode
  952. %% 22.3.2 142
  953. If the second argument is not supplied, then \funref{format} uses the
  954. line width of the \param{destination} output stream.
  955. If this cannot be determined (for example, when producing a
  956. \term{string} result), then \funref{format} uses \f{72} as the line length.
  957. See also \secref\TildeLessThanLogicalBlock.
  958. \endsubsubsection%{Tilde Less-Than-Sign: Justification}
  959. \beginsubsubsection{Tilde Greater-Than-Sign: End of Justification}
  960. \idxtext{Greater-Than-Sign (format directive)}\idxtext{Tilde Greater-Than-Sign (format directive)}
  961. %% 22.3.2 143
  962. \f{~>} terminates a \f{~<}.
  963. The consequences of using it elsewhere are undefined.
  964. \endsubsubsection%{Tilde Greater-Than-Sign: End of Justification}
  965. \endsubsection%{FORMAT Layout Control}
  966. \beginsubsection{FORMAT Control-Flow Operations}
  967. \beginsubsubsection{Tilde Asterisk: Go-To}
  968. \idxtext{Asterisk (format directive)}\idxtext{Tilde Asterisk (format directive)}
  969. %% 22.3.2 105
  970. The next \j{arg} is ignored.
  971. \f{~\j{n}*} ignores the next \j{n} arguments.
  972. %% 22.3.2 106
  973. \f{~:*} backs up in the list of
  974. arguments so that the argument last processed will be processed again.
  975. \f{~\j{n}:*} backs up \j{n} arguments.
  976. %% 22.3.2 107
  977. When within a \f{~\{} construct
  978. (see below), the ignoring (in either direction) is relative to the list
  979. of arguments being processed by the iteration.
  980. %% 22.3.2 108
  981. \f{~\j{n}@*}
  982. goes to the \j{n}th \j{arg}, where 0 means the first one;
  983. \j{n} defaults to 0, so \f{~@*} goes back to the first \j{arg}.
  984. Directives after a \f{~\j{n}@*}
  985. will take arguments in sequence beginning with the one gone to.
  986. When within a \f{~\{} construct, the ``goto''
  987. is relative to the list of arguments being processed by the iteration.
  988. \endsubsubsection%{Tilde Asterisk: Go-To}
  989. \beginsubsubsection{Tilde Left-Bracket: Conditional Expression}
  990. \idxtext{Left-Bracket (format directive)}\idxtext{Tilde Left-Bracket (format directive)}
  991. %% 22.3.2 121
  992. \f{~[\j{str0}~;\j{str1}~;\j{...}~;\j{strn}~]}
  993. This is a set of control strings, called \j{clauses}, one of which is
  994. chosen and used. The clauses are separated by \f{~;}
  995. and the construct is terminated by \f{~]}. For example,
  996. \f{"~[Siamese~;Manx~;Persian~] Cat"}
  997. The \j{arg}th
  998. clause is selected, where the first clause is number 0.
  999. If a prefix parameter is given (as \f{~\j{n}[}),
  1000. then the parameter is used instead of an argument.
  1001. If \j{arg} is out of range then no clause is selected
  1002. and no error is signaled.
  1003. After the selected alternative has been processed, the control string
  1004. continues after the \f{~]}.
  1005. %% 22.3.2 122
  1006. \f{~[\j{str0}~;\j{str1}~;\j{...}~;\j{strn}~:;\j{default}~]}
  1007. has a default case.
  1008. If the \j{last} \f{~;} used to separate clauses
  1009. is \f{~:;} instead, then the last clause is an else clause
  1010. that is performed if no other clause is selected.
  1011. For example:
  1012. \f{"~[Siamese~;Manx~;Persian~:;Alley~] Cat"}
  1013. %!!! Deja vu. Is this repeated somewhere??? -kmp 11-Jun-91
  1014. %% 22.3.2 123
  1015. \f{~:[\param{alternative}~;\param{consequent}~]}
  1016. selects the \param{alternative} control string if \j{arg} is \term{false},
  1017. and selects the \param{consequent} control string otherwise.
  1018. %% 22.3.2 124
  1019. \f{~@[\param{consequent}~]}
  1020. tests the argument. If it is \term{true},
  1021. then the argument is not used up by the \f{~[} command
  1022. but remains as the next one to be processed,
  1023. and the one clause \param{consequent} is processed.
  1024. If the \j{arg} is \term{false}, then the argument is used up,
  1025. and the clause is not processed.
  1026. The clause therefore should normally use exactly one argument,
  1027. and may expect it to be \term{non-nil}.
  1028. For example:
  1029. \code
  1030. (setq *print-level* nil *print-length* 5)
  1031. (format nil
  1032. "~@[ print level = ~D~]~@[ print length = ~D~]"
  1033. *print-level* *print-length*)
  1034. \EV " print length = 5"
  1035. \endcode
  1036. Note also that
  1037. \code
  1038. (format \param{stream} "...~@[\param{str}~]..." ...)
  1039. \EQ (format \param{stream} "...~:[~;~:*\param{str}~]..." ...)
  1040. \endcode
  1041. %% 22.3.2 125
  1042. The combination of \f{~[} and \f{\#} is useful, for
  1043. example, for dealing with English conventions for printing lists:
  1044. \code
  1045. (setq foo "Items:~#[ none~; ~S~; ~S and ~S~
  1046. ~:;~@\{~#[~; and~] ~S~\hat\ ,~\}~].")
  1047. (format nil foo) \EV "Items: none."
  1048. (format nil foo 'foo) \EV "Items: FOO."
  1049. (format nil foo 'foo 'bar) \EV "Items: FOO and BAR."
  1050. (format nil foo 'foo 'bar 'baz) \EV "Items: FOO, BAR, and BAZ."
  1051. (format nil foo 'foo 'bar 'baz 'quux) \EV "Items: FOO, BAR, BAZ, and QUUX."
  1052. \endcode
  1053. \endsubsubsection%{Tilde Left-Bracket: Conditional Expression}
  1054. \beginsubsubsection{Tilde Right-Bracket: End of Conditional Expression}
  1055. \idxtext{Right-Bracket (format directive)}\idxtext{Tilde Right-Bracket (format directive)}
  1056. %% 22.3.2 127
  1057. \f{~]} terminates a \f{~[}.
  1058. The consequences of using it elsewhere are undefined.
  1059. \endsubsubsection%{Tilde Right-Bracket: End of Conditional Expression}
  1060. \beginsubsubsection{Tilde Left-Brace: Iteration}
  1061. \idxtext{Left-Brace (format directive)}\idxtext{Tilde Left-Brace (format directive)}
  1062. %% 22.3.2 128
  1063. \f{~\{\j{str}~\}}
  1064. This is an iteration construct. The argument should be a \term{list},
  1065. which is used as a set of arguments
  1066. as if for a recursive call to \funref{format}.
  1067. The \term{string} \j{str} is used repeatedly as the control string.
  1068. Each iteration can absorb as many elements of the \term{list} as it likes
  1069. as arguments;
  1070. if \j{str} uses up two arguments by itself, then two elements of the
  1071. \term{list} will get used up each time around the loop.
  1072. If before any iteration step the \term{list}
  1073. is empty, then the iteration is terminated.
  1074. Also, if a prefix parameter \j{n} is given, then there will be at most \j{n}
  1075. repetitions of processing of \j{str}.
  1076. Finally, the \f{~\hat } directive can be
  1077. used to terminate the iteration prematurely.
  1078. %% 22.3.2 129
  1079. For example:
  1080. \code
  1081. (format nil "The winners are:~\{ ~S~\}."
  1082. '(fred harry jill))
  1083. \EV "The winners are: FRED HARRY JILL."
  1084. (format nil "Pairs:~\{ <~S,~S>~\}."
  1085. '(a 1 b 2 c 3))
  1086. \EV "Pairs: <A,1> <B,2> <C,3>."
  1087. \endcode
  1088. %% 22.3.2 130
  1089. \f{~:\lbr \j{str}~\rbr } is similar,
  1090. but the argument should be a \term{list} of sublists.
  1091. At each repetition step, one sublist
  1092. is used as the set of arguments for
  1093. processing \j{str}; on the next repetition, a new sublist
  1094. is used, whether
  1095. or not all of the last sublist had been processed.
  1096. For example:
  1097. \code
  1098. (format nil "Pairs:~:\lbr <~S,~S>~\rbr\ ."
  1099. '((a 1) (b 2) (c 3)))
  1100. \EV "Pairs: <A,1> <B,2> <C,3>."
  1101. \endcode
  1102. %% 22.3.2 131
  1103. \f{~@\lbr \j{str}~\rbr }
  1104. is similar to \f{~\lbr \j{str}~\rbr }, but instead of
  1105. using one argument that is a list, all the remaining arguments
  1106. are used as the list of arguments for the iteration.
  1107. Example:
  1108. \code
  1109. (format nil "Pairs:~@\lbr <~S,~S>~\rbr\ ." 'a 1 'b 2 'c 3)
  1110. \EV "Pairs: <A,1> <B,2> <C,3>."
  1111. \endcode
  1112. If the iteration is terminated before all the remaining arguments are
  1113. consumed, then any arguments not processed by the iteration remain to be
  1114. processed by any directives following the iteration construct.
  1115. %% 22.3.2 132
  1116. \f{~:@\lbr \j{str}~\rbr }
  1117. combines the features
  1118. of \f{~:\lbr \j{str}~\rbr }
  1119. and \f{~@\lbr \j{str}~\rbr }.
  1120. All the remaining arguments
  1121. are used, and each one must be a \term{list}.
  1122. On each iteration, the next argument is
  1123. used as a \term{list} of arguments to \j{str}.
  1124. Example:
  1125. \code
  1126. (format nil "Pairs:~:@\lbr <~S,~S>~\rbr\ ."
  1127. '(a 1) '(b 2) '(c 3))
  1128. \EV "Pairs: <A,1> <B,2> <C,3>."
  1129. \endcode
  1130. %% 22.3.2 133
  1131. Terminating the repetition construct with \f{~:\rbr }
  1132. instead of \f{~\rbr }
  1133. forces \j{str} to be processed at least once, even if the initial
  1134. list of arguments is null. However, this will not override an explicit
  1135. prefix parameter of zero.
  1136. %% 22.3.2 134
  1137. If \j{str} is empty, then an argument is used as \j{str}.
  1138. It must be a \term{format control}
  1139. and precede any arguments processed by the iteration. As an example,
  1140. the following are equivalent:
  1141. \code
  1142. (apply #'format stream string arguments)
  1143. \EQ (format stream "~1\{~:\}" string arguments)
  1144. \endcode
  1145. This will use \f{string} as a formatting string.
  1146. The \f{~1\lbr } says it will
  1147. be processed at most once, and the \f{~:\rbr }
  1148. says it will be processed at least once.
  1149. Therefore it is processed exactly once, using \f{arguments} as the arguments.
  1150. This case may be handled more clearly by the \f{~?} directive,
  1151. but this general feature of \f{~\lbr }
  1152. is more powerful than \f{~?}.
  1153. \endsubsubsection%{Tilde Left-Brace: Iteration}
  1154. \beginsubsubsection{Tilde Right-Brace: End of Iteration}
  1155. \idxtext{Right-Brace (format directive)}\idxtext{Tilde Right-Brace (format directive)}
  1156. %% 22.3.2 135
  1157. \f{~\}} terminates a \f{~\{}.
  1158. The consequences of using it elsewhere are undefined.
  1159. \endsubsubsection%{Tilde Right-Brace: End of Iteration}
  1160. \beginsubsubsection{Tilde Question-Mark: Recursive Processing}
  1161. \idxtext{Question-Mark (format directive)}\idxtext{Tilde Question-Mark (format directive)}
  1162. %% Was "Indirection", now "Recursive Processing". -kmp 30-Aug-93
  1163. %% 22.3.2 109
  1164. The next \j{arg} must be a \term{format control}, and the one after it a \term{list};
  1165. both are consumed by the \f{~?} directive.
  1166. The two are processed as a \param{control-string}, with the elements of the \term{list}
  1167. as the arguments. Once the recursive processing
  1168. has been finished, the processing of the control
  1169. string containing the \f{~?} directive is resumed.
  1170. Example:
  1171. \code
  1172. (format nil "~? ~D" "<~A ~D>" '("Foo" 5) 7) \EV "<Foo 5> 7"
  1173. (format nil "~? ~D" "<~A ~D>" '("Foo" 5 14) 7) \EV "<Foo 5> 7"
  1174. \endcode
  1175. Note that in the second example three arguments are supplied
  1176. to the \term{format string} \f{"<~A ~D>"}, but only two are processed
  1177. and the third is therefore ignored.
  1178. %% 22.3.2 110
  1179. With the \f{@}
  1180. modifier, only one \j{arg} is directly consumed.
  1181. The \j{arg} must be a \term{string};
  1182. it is processed as part of the control
  1183. string as if it had appeared in place of the \f{~@?} construct,
  1184. and any directives in the recursively processed control string may
  1185. consume arguments of the control string containing the \f{~@?}
  1186. directive.
  1187. Example:
  1188. \code
  1189. (format nil "~@? ~D" "<~A ~D>" "Foo" 5 7) \EV "<Foo 5> 7"
  1190. (format nil "~@? ~D" "<~A ~D>" "Foo" 5 14 7) \EV "<Foo 5> 14"
  1191. \endcode
  1192. \endsubsubsection%{Tilde Question-Mark: Recursive Processing}
  1193. \endsubsection%{FORMAT Control-Flow Operations}
  1194. \beginsubsection{FORMAT Miscellaneous Operations}
  1195. \beginsubsubsection{Tilde Left-Paren: Case Conversion}
  1196. \idxtext{Left-Paren (format directive)}\idxtext{Tilde Left-Paren (format directive)}
  1197. %% 22.3.2 115
  1198. \f{~(\j{str}~)}
  1199. The contained control string \j{str} is processed, and what it produces
  1200. is subject to case conversion.
  1201. %% 22.3.2 116
  1202. With no flags, every \term{uppercase} \term{character}
  1203. is converted to the corresponding \term{lowercase} \term{character}.
  1204. %% 22.3.2 117
  1205. \f{~:(} capitalizes all words, as if by \funref{string-capitalize}.
  1206. %% 22.3.2 118
  1207. \f{~@(}
  1208. capitalizes just the first word and forces the rest to lower
  1209. case.
  1210. %% 22.3.2 119
  1211. \f{~:@(} converts every lowercase character
  1212. to the corresponding uppercase character.
  1213. %% 22.3.2 120
  1214. In this example \f{~@(} is used to cause the first word
  1215. produced by \f{~@R} to be capitalized:
  1216. \code
  1217. (format nil "~@R ~(~@R~)" 14 14)
  1218. \EV "XIV xiv"
  1219. (defun f (n) (format nil "~@(~R~) error~:P detected." n)) \EV F
  1220. (f 0) \EV "Zero errors detected."
  1221. (f 1) \EV "One error detected."
  1222. (f 23) \EV "Twenty-three errors detected."
  1223. \endcode
  1224. %% This next is from Pitman #36 (first public review):
  1225. When case conversions appear nested, the outer conversion dominates,
  1226. as illustrated in the following example:
  1227. \code
  1228. (format nil "~@(how is ~:(BOB SMITH~)?~)")
  1229. \EV "How is bob smith?"
  1230. \NV "How is Bob Smith?"
  1231. \endcode
  1232. \endsubsubsection%{Tilde Left-Paren: Case Conversion}
  1233. \beginsubsubsection{Tilde Right-Paren: End of Case Conversion}
  1234. \idxtext{Right-Paren (format directive)}\idxtext{Tilde Right-Paren (format directive)}
  1235. %% 22.3.2 127
  1236. \f{~)} terminates a \f{~(}.
  1237. The consequences of using it elsewhere are undefined.
  1238. \endsubsubsection%{Tilde Right-Paren: End of Case Conversion}
  1239. \beginsubsubsection{Tilde P: Plural}
  1240. \idxtext{P (format directive)}\idxtext{Tilde P (format directive)}
  1241. %% 22.3.2 35
  1242. If \j{arg} is not \funref{eql}
  1243. to the integer \f{1}, a lowercase \f{s} is
  1244. printed; if \j{arg} is \funref{eql} to \f{1}, nothing is printed.
  1245. If \j{arg} is a floating-point \f{1.0}, the \f{s} is
  1246. printed.
  1247. %% 22.3.2 36
  1248. \f{~:P} does the same thing,
  1249. after doing a \f{~:*} to back up one argument;
  1250. that is, it prints a lowercase \f{s} if the previous argument was not
  1251. \f{1}.
  1252. %% 22.3.2 37
  1253. \f{~@P}
  1254. prints \f{y} if the argument is \f{1}, or \f{ies} if it is
  1255. not. \f{~:@P} does the same thing, but backs up first.
  1256. \code
  1257. (format nil "~D tr~:@P/~D win~:P" 7 1) \EV "7 tries/1 win"
  1258. (format nil "~D tr~:@P/~D win~:P" 1 0) \EV "1 try/0 wins"
  1259. (format nil "~D tr~:@P/~D win~:P" 1 3) \EV "1 try/3 wins"
  1260. \endcode
  1261. \endsubsubsection%{Tilde P: Plural}
  1262. \endsubsection%{FORMAT Miscellaneous Operations}
  1263. \beginsubsection{FORMAT Miscellaneous Pseudo-Operations}
  1264. \beginsubsubsection{Tilde Semicolon: Clause Separator}
  1265. \idxtext{Semicolon (format directive)}\idxtext{Tilde Semicolon (format directive)}
  1266. %% 22.3.2 126
  1267. This separates clauses in \f{~[} and \f{~<} constructs.
  1268. The consequences of using it elsewhere are undefined.
  1269. \endsubsubsection%{Tilde Semicolon: Clause Separator}
  1270. \beginsubsubsection{Tilde Circumflex: Escape Upward}
  1271. \idxtext{Circumflex (format directive)}\idxtext{Tilde Circumflex (format directive)}
  1272. %% 22.3.2 144
  1273. {\f{~\hat }}
  1274. This is an escape construct. If there are no more arguments remaining to
  1275. be processed, then the immediately
  1276. enclosing \f{~\lbr } or \f{~<} construct
  1277. is terminated. If there is no such enclosing construct, then the entire
  1278. formatting operation is terminated.
  1279. In the \f{~<} case, the formatting
  1280. is performed, but no more segments are processed before doing the
  1281. justification.
  1282. \f{~\hat } may appear anywhere in a \f{~\lbr }
  1283. construct.
  1284. \code
  1285. (setq donestr "Done.~{\hat} ~D warning~:P.~{\hat} ~D error~:P.")
  1286. \EV "Done.~{\hat} ~D warning~:P.~{\hat} ~D error~:P."
  1287. (format nil donestr) \EV "Done."
  1288. (format nil donestr 3) \EV "Done. 3 warnings."
  1289. (format nil donestr 1 5) \EV "Done. 1 warning. 5 errors."
  1290. \endcode
  1291. %% 22.3.2 145
  1292. If a prefix parameter is given, then termination occurs if the parameter
  1293. is zero. (Hence \f{~{\hat}} is equivalent to
  1294. \f{~\#{\hat}}.) If two
  1295. parameters are given, termination occurs if they are equal.
  1296. \reviewer{Barmar: Which equality predicate?} If three
  1297. parameters are given, termination occurs if the first is less than or
  1298. equal to the second and the second is less than or equal to the third.
  1299. Of course, this is useless if all the prefix parameters are constants; at
  1300. least one of them should be a \f{\#} or a \f{V} parameter.
  1301. %% 22.3.2 146
  1302. If \f{~{\hat}} is used within a \f{~:\lbr }
  1303. construct, then it terminates
  1304. the current iteration step because in the standard case it tests for
  1305. remaining arguments of the current step only; the next iteration step
  1306. commences immediately. \f{~:{\hat}} is used to terminate
  1307. the iteration process.
  1308. \issue{FORMAT-COLON-UPARROW-SCOPE}
  1309. \f{~:{\hat}}
  1310. may be used only if the command it would terminate is
  1311. \f{~:\lbr } or \f{~:@\lbr }.
  1312. The entire iteration process is terminated if and only if the sublist that is
  1313. supplying the arguments for the current iteration step is the last sublist in
  1314. the case of \f{~:\lbr },
  1315. or the last \funref{format}
  1316. argument in the case of \f{~:@\lbr }.
  1317. \f{~:{\hat}} is not
  1318. equivalent to \f{~\#:{\hat}};
  1319. the latter terminates the entire iteration if and only if no
  1320. arguments remain for the current iteration step.
  1321. For example:
  1322. \code
  1323. (format nil "~:\lbr\ ~@?~:\hat\ ...~\rbr\ " '(("a") ("b"))) \EV "a...b"
  1324. \endcode
  1325. \endissue{FORMAT-COLON-UPARROW-SCOPE}
  1326. %% 22.3.2 147
  1327. If \f{~{\hat}} appears within a control string being processed
  1328. under the control of a \f{~?} directive, but not within
  1329. any \f{~\lbr } or \f{~<} construct within that string,
  1330. then the string being
  1331. processed will be terminated, thereby ending processing
  1332. of the \f{~?} directive. Processing then
  1333. continues within the string
  1334. containing the \f{~?} directive at the point following that directive.
  1335. %% 22.3.2 148
  1336. If \f{~{\hat}}
  1337. appears within a \f{~[} or \f{~(} construct,
  1338. then all the commands up to the \f{~{\hat}} are properly selected
  1339. or case-converted,
  1340. the \f{~[} or \f{~(} processing is terminated,
  1341. and the outward search continues
  1342. for a \f{~\lbr } or \f{~<} construct
  1343. to be terminated. For example:
  1344. \code
  1345. (setq tellstr "~@(~@[~R~]~{\hat} ~A!~)")
  1346. \EV "~@(~@[~R~]~{\hat} ~A!~)"
  1347. (format nil tellstr 23) \EV "Twenty-three!"
  1348. (format nil tellstr nil "losers") \EV " Losers!"
  1349. (format nil tellstr 23 "losers") \EV "Twenty-three losers!"
  1350. \endcode
  1351. %% 22.3.2 149
  1352. Following are examples of the use of \f{~{\hat}}
  1353. within a \f{~<} construct.
  1354. \code
  1355. (format nil "~15<~S~;~{\hat}~S~;~{\hat}~S~>" 'foo)
  1356. \EV " FOO"
  1357. (format nil "~15<~S~;~{\hat}~S~;~{\hat}~S~>" 'foo 'bar)
  1358. \EV "FOO BAR"
  1359. (format nil "~15<~S~;~{\hat}~S~;~{\hat}~S~>" 'foo 'bar 'baz)
  1360. \EV "FOO BAR BAZ"
  1361. \endcode
  1362. \endsubsubsection%{Tilde Circumflex: Escape Upward}
  1363. \beginsubsubsection{Tilde Newline: Ignored Newline}
  1364. \idxtext{Newline (format directive)}\idxtext{Tilde Newline (format directive)}
  1365. %% 22.3.2 100
  1366. \term{Tilde} immediately followed by a \term{newline} ignores the \term{newline}
  1367. and any following non-newline \term{whitespace}\meaning{1} characters.
  1368. With a \f{:},
  1369. the \term{newline} is ignored,
  1370. but any following \term{whitespace}\meaning{1} is left in place.
  1371. With an \f{@},
  1372. the \term{newline} is left in place,
  1373. but any following \term{whitespace}\meaning{1} is ignored.
  1374. For example:
  1375. %% 22.3.2 101
  1376. \code
  1377. (defun type-clash-error (fn nargs argnum right-type wrong-type)
  1378. (format *error-output*
  1379. "~&~S requires its ~:[~:R~;~*~]~
  1380. argument to be of type ~S,~%but it was called ~
  1381. with an argument of type ~S.~%"
  1382. fn (eql nargs 1) argnum right-type wrong-type))
  1383. (type-clash-error 'aref nil 2 'integer 'vector) prints:
  1384. AREF requires its second argument to be of type INTEGER,
  1385. but it was called with an argument of type VECTOR.
  1386. NIL
  1387. (type-clash-error 'car 1 1 'list 'short-float) prints:
  1388. CAR requires its argument to be of type LIST,
  1389. but it was called with an argument of type SHORT-FLOAT.
  1390. NIL
  1391. \endcode
  1392. Note that in this example newlines appear in the output only as specified
  1393. by the \f{~\&} and \f{~\%} directives; the
  1394. actual newline characters
  1395. in the control string are suppressed because each is preceded by a tilde.
  1396. \endsubsubsection%{Tilde Newline: Ignored Newline}
  1397. \endsubsection%{FORMAT Miscellaneous Pseudo-Operations}
  1398. \beginsubsection{Additional Information about FORMAT Operations}
  1399. \beginsubsubsection{Nesting of FORMAT Operations}
  1400. %% 22.3.2 112
  1401. %% this paragraph was left out
  1402. %% 22.3.2 113
  1403. The case-conversion, conditional, iteration, and justification
  1404. constructs can contain other formatting constructs by bracketing them.
  1405. These constructs must nest properly with respect to each other.
  1406. For example, it is not legitimate to put the start of a case-conversion
  1407. construct in each arm of a conditional and the
  1408. end of the case-conversion construct outside the conditional:
  1409. \code
  1410. (format nil "~:[abc~:@(def~;ghi~
  1411. :@(jkl~]mno~)" x) ;Invalid!
  1412. \endcode
  1413. This notation is invalid because the \f{~[...~;...~]}
  1414. and \f{~(...~)} constructs are not properly nested.
  1415. %% 22.3.2 114
  1416. The processing indirection caused by the \f{~?} directive
  1417. is also a kind of nesting for the purposes of this rule of proper nesting.
  1418. It is not permitted to
  1419. start a bracketing construct within a string processed
  1420. under control of a \f{~?}
  1421. directive and end the construct at some point after the \f{~?} construct
  1422. in the string containing that construct, or vice versa.
  1423. For example, this situation is invalid:
  1424. \code
  1425. (format nil "~@?ghi~)" "abc~@(def") ;Invalid!
  1426. \endcode
  1427. This notation
  1428. is invalid because the \f{~?}
  1429. and \f{~(...~)} constructs are not properly nested.
  1430. \endsubsubsection%{Nesting of FORMAT Operations}
  1431. \beginsubsubsection{Missing and Additional FORMAT Arguments}
  1432. %% 22.3.3 3
  1433. The consequences are undefined if no \param{arg} remains for a directive
  1434. requiring an argument. However, it is permissible for one or more \param{args}
  1435. to remain unprocessed by a directive; such \param{args} are ignored.
  1436. \endsubsubsection%{Missing and Additional FORMAT Arguments}
  1437. \beginsubsubsection{Additional FORMAT Parameters}
  1438. %% 22.3.3 11
  1439. The consequences are undefined if a format directive is given more parameters
  1440. than it is described here as accepting.
  1441. \endsubsubsection%{Additional FORMAT Parameters}
  1442. \beginsubsubsection{Undefined FORMAT Modifier Combinations}
  1443. %% 22.3.3 11
  1444. The consequences are undefined if \term{colon} or \term{at-sign} modifiers
  1445. are given to a directive in a combination not specifically described
  1446. here as being meaningful.
  1447. \endsubsubsection%{Undefined FORMAT Modifier Combinations}
  1448. \endsubsection%{Additional Information about FORMAT Operations}
  1449. \beginsubsection{Examples of FORMAT}
  1450. %% 22.3.2 12
  1451. %% 22.3.2 13
  1452. %% 22.3.2 14
  1453. \code
  1454. (format nil "foo") \EV "foo"
  1455. (setq x 5) \EV 5
  1456. (format nil "The answer is ~D." x) \EV "The answer is 5."
  1457. (format nil "The answer is ~3D." x) \EV "The answer is 5."
  1458. (format nil "The answer is ~3,'0D." x) \EV "The answer is 005."
  1459. (format nil "The answer is ~:D." (expt 47 x))
  1460. \EV "The answer is 229,345,007."
  1461. (setq y "elephant") \EV "elephant"
  1462. (format nil "Look at the ~A!" y) \EV "Look at the elephant!"
  1463. (setq n 3) \EV 3
  1464. (format nil "~D item~:P found." n) \EV "3 items found."
  1465. (format nil "~R dog~:[s are~; is~] here." n (= n 1))
  1466. \EV "three dogs are here."
  1467. (format nil "~R dog~:*~[s are~; is~:;s are~] here." n)
  1468. \EV "three dogs are here."
  1469. (format nil "Here ~[are~;is~:;are~] ~:*~R pupp~:@P." n)
  1470. \EV "Here are three puppies."
  1471. \endcode
  1472. %% 22.3.2 53
  1473. \code
  1474. (defun foo (x)
  1475. (format nil "~6,2F|~6,2,1,'*F|~6,2,,'?F|~6F|~,2F|~F"
  1476. x x x x x x)) \EV FOO
  1477. (foo 3.14159) \EV " 3.14| 31.42| 3.14|3.1416|3.14|3.14159"
  1478. (foo -3.14159) \EV " -3.14|-31.42| -3.14|-3.142|-3.14|-3.14159"
  1479. (foo 100.0) \EV "100.00|******|100.00| 100.0|100.00|100.0"
  1480. (foo 1234.0) \EV "1234.00|******|??????|1234.0|1234.00|1234.0"
  1481. (foo 0.006) \EV " 0.01| 0.06| 0.01| 0.006|0.01|0.006"
  1482. \endcode
  1483. %% 22.3.2 73
  1484. \code
  1485. (defun foo (x)
  1486. (format nil
  1487. "~9,2,1,,'*E|~10,3,2,2,'?,,'\$E|~
  1488. ~9,3,2,-2,'%@E|~9,2E"
  1489. x x x x))
  1490. (foo 3.14159) \EV " 3.14E+0| 31.42\$-01|+.003E+03| 3.14E+0"
  1491. (foo -3.14159) \EV " -3.14E+0|-31.42\$-01|-.003E+03| -3.14E+0"
  1492. (foo 1100.0) \EV " 1.10E+3| 11.00\$+02|+.001E+06| 1.10E+3"
  1493. (foo 1100.0L0) \EV " 1.10L+3| 11.00\$+02|+.001L+06| 1.10L+3"
  1494. (foo 1.1E13) \EV "*********| 11.00\$+12|+.001E+16| 1.10E+13"
  1495. (foo 1.1L120) \EV "*********|??????????|%%%%%%%%%|1.10L+120"
  1496. (foo 1.1L1200) \EV "*********|??????????|%%%%%%%%%|1.10L+1200"
  1497. \endcode
  1498. As an example of the effects of varying the scale factor, the code
  1499. \code
  1500. (dotimes (k 13)
  1501. (format t "~%Scale factor ~2D: |~13,6,2,VE|"
  1502. (- k 5) (- k 5) 3.14159))
  1503. \endcode
  1504. produces the following output:
  1505. \code
  1506. Scale factor -5: | 0.000003E+06|
  1507. Scale factor -4: | 0.000031E+05|
  1508. Scale factor -3: | 0.000314E+04|
  1509. Scale factor -2: | 0.003142E+03|
  1510. Scale factor -1: | 0.031416E+02|
  1511. Scale factor 0: | 0.314159E+01|
  1512. Scale factor 1: | 3.141590E+00|
  1513. Scale factor 2: | 31.41590E-01|
  1514. Scale factor 3: | 314.1590E-02|
  1515. Scale factor 4: | 3141.590E-03|
  1516. Scale factor 5: | 31415.90E-04|
  1517. Scale factor 6: | 314159.0E-05|
  1518. Scale factor 7: | 3141590.E-06|
  1519. \endcode
  1520. %% 22.3.2 86
  1521. \code
  1522. (defun foo (x)
  1523. (format nil "~9,2,1,,'*G|~9,3,2,3,'?,,'\$G|~9,3,2,0,'%G|~9,2G"
  1524. x x x x))
  1525. (foo 0.0314159) \EV " 3.14E-2|314.2\$-04|0.314E-01| 3.14E-2"
  1526. (foo 0.314159) \EV " 0.31 |0.314 |0.314 | 0.31 "
  1527. (foo 3.14159) \EV " 3.1 | 3.14 | 3.14 | 3.1 "
  1528. (foo 31.4159) \EV " 31. | 31.4 | 31.4 | 31. "
  1529. (foo 314.159) \EV " 3.14E+2| 314. | 314. | 3.14E+2"
  1530. (foo 3141.59) \EV " 3.14E+3|314.2\$+01|0.314E+04| 3.14E+3"
  1531. (foo 3141.59L0) \EV " 3.14L+3|314.2\$+01|0.314L+04| 3.14L+3"
  1532. (foo 3.14E12) \EV "*********|314.0\$+10|0.314E+13| 3.14E+12"
  1533. (foo 3.14L120) \EV "*********|?????????|%%%%%%%%%|3.14L+120"
  1534. (foo 3.14L1200) \EV "*********|?????????|%%%%%%%%%|3.14L+1200"
  1535. \endcode
  1536. %% 22.3.2 138
  1537. \code
  1538. (format nil "~10<foo~;bar~>") \EV "foo bar"
  1539. (format nil "~10:<foo~;bar~>") \EV " foo bar"
  1540. (format nil "~10<foobar~>") \EV " foobar"
  1541. (format nil "~10:<foobar~>") \EV " foobar"
  1542. (format nil "~10:@<foo~;bar~>") \EV " foo bar "
  1543. (format nil "~10@<foobar~>") \EV "foobar "
  1544. (format nil "~10:@<foobar~>") \EV " foobar "
  1545. \endcode
  1546. \issue{PATHNAME-PRINT-READ:SHARPSIGN-P}
  1547. \code
  1548. (FORMAT NIL "Written to ~A." #P"foo.bin")
  1549. \EV "Written to foo.bin."
  1550. \endcode
  1551. \endissue{PATHNAME-PRINT-READ:SHARPSIGN-P}
  1552. \endsubsection%{Examples of FORMAT}
  1553. \beginsubsection{Notes about FORMAT}
  1554. %% 22.3.2 5
  1555. \issue{FORMAT-STRING-ARGUMENTS:SPECIFY}
  1556. Formatted output is performed not only by \funref{format},
  1557. but by certain other functions that accept a \term{format control}
  1558. the way \funref{format} does. For example, error-signaling functions
  1559. such as \funref{cerror} accept \term{format controls}.
  1560. \endissue{FORMAT-STRING-ARGUMENTS:SPECIFY}
  1561. Note that the meaning of \nil\ and \t\ as destinations to \funref{format}
  1562. are different than those of \nil\ and \t\ as \term{stream designators}.
  1563. The \f{~{\hat}} should appear only at the beginning of a \f{~<} clause,
  1564. because it aborts the entire clause in which it appears (as well as
  1565. all following clauses).
  1566. \endsubsection%{Notes about FORMAT}