forked from ruricolist/dpans2texi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconcept-format.tex
1922 lines (1566 loc) · 72.3 KB
/
concept-format.tex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
% -*- Mode: TeX -*-
%% Formatted Output
\issue{PRETTY-PRINT-INTERFACE}
\editornote{KMP: This is transplanted from FORMAT and will need a bit of work before
it looks good standing alone. Bear with me.}
%% 22.3.1 21
\funref{format} is useful for producing nicely formatted text, producing
good-looking messages, and so on. \funref{format} can generate and return
a \term{string} or output to \param{destination}.
The \param{control-string} argument to \funref{format} is actually a \term{format control}.
% It can be any function at all that does the right things with its
% arguments. --sjl 16 Mar 92
%That is, it can be either a \term{format string} or a \term{function} that was returned
That is, it can be either a \term{format string} or a \term{function},
for example a \term{function} returned
by the \macref{formatter} \term{macro}.
If it is a \term{function}, the \term{function} is called with the appropriate
output stream as its first argument and the data arguments to \funref{format}
as its remaining arguments. The function should perform whatever output is
necessary and return the unused tail of the arguments (if any).
The compilation process performed by \macref{formatter} produces a \term{function}
that would do with its \term{arguments} as the \funref{format} interpreter
would do with those \term{arguments}.
The remainder of this section describes what happens if the \param{control-string}
is a \term{format string}.
\endissue{PRETTY-PRINT-INTERFACE}
% Removed redundant text --sjl 16 Mar 92
%%% 22.3.2 6
%\funref{format} produces formatted output by outputting the characters
%of \param{control-string} and observing that a \term{tilde}
%introduces a directive. The character after the tilde, possibly preceded
%by prefix parameters and modifiers, specifies what kind of formatting
%is desired.
\param{Control-string} is composed of simple text (\term{characters})
and embedded directives.
%% 22.3.3 7
\funref{format} writes the simple text as is;
each embedded directive specifies further text output
that is to appear at the corresponding point within the simple text.
Most directives use one or more elements of \param{args} to
create their output.
%% 22.3.3 9
A directive consists of a \term{tilde},
optional prefix parameters
separated by commas, optional \term{colon} and \term{at-sign} modifiers,
and a single character indicating what kind of directive this is.
\issue{FORMAT-ATSIGN-COLON}
There is no required ordering between the \term{at-sign} and \term{colon} modifier.
\endissue{FORMAT-ATSIGN-COLON}
The \term{case} of the directive character is ignored.
Prefix parameters are notated as signed (sign is optional) decimal numbers,
or as a \term{single-quote} followed by a character.
For example, \f{~5,'0d} can be used
to print an \term{integer}
in decimal radix in five columns with leading zeros,
or \f{~5,'*d} to get leading asterisks.
%% 22.3.2 10
In place of a prefix parameter to a directive, \f{V} (or \f{v}) can be used.
In this case, \funref{format} takes an argument from \param{args} as a parameter to
the directive. The argument should be an \term{integer} or \term{character}.
If the \param{arg} used by a \f{V} parameter is \nil,
the effect is as if the parameter had been omitted.
\f{\#} can be used in place of a prefix parameter; it
represents the number of \param{args} remaining to be processed.
When used within a recursive format, in the context of \f{~?} or \f{~\{},
the \f{\#} prefix parameter represents the number of \term{format arguments}
remaining within the recursive call.
Examples of \term{format strings}:
\showtwo{Examples of format control strings}{
\f{"~S"} & ;This is an S directive with no parameters or modifiers. \cr
\f{"~3,-4:@s"} & ;This is an S directive with two parameters, \f{3} and \f{-4}, \cr
& ; and both the \term{colon} and \term{at-sign} flags. \cr
\f{"~,+4S"} & ;Here the first prefix parameter is omitted and takes \cr
& ; on its default value, while the second parameter is \f{4}. \cr
}
\funref{format} sends the output to \param{destination}.
If \param{destination} is \nil,
\funref{format} creates and returns a \term{string}
containing the output from \param{control-string}.
If \param{destination} is \term{non-nil},
it must be a \term{string} with a \term{fill pointer},
a \term{stream}, or the symbol \t.
If \param{destination} is a \term{string} with a \term{fill pointer},
the output is added to the end of the \term{string}.
If \param{destination} is a \term{stream},
the output is sent to that \term{stream}.
If \param{destination} is \t,
the output is sent to \term{standard output}.
%% 22.3.2 8
%%(left out)
%% 22.3.2 15
In the description of the directives that follows,
the term \j{arg} in general
refers to the next item of the set of \param{args} to be processed.
The word or phrase at the beginning of each description is a mnemonic
for the directive.
\issue{FORMAT-PRETTY-PRINT:YES}
\funref{format} directives do not bind any of the printer control
variables (\varref{*print-...*}) except as specified in the following
descriptions.
Implementations may specify the binding of new, implementation-specific
printer control variables for each \funref{format} directive, but they
may neither bind any standard printer control variables not
specified in description of a \funref{format}
directive nor fail to bind
any standard printer control variables as specified in the
description.
\endissue{FORMAT-PRETTY-PRINT:YES}
% This section needs a lot of work on fonts. Maybe all the syntax parts
% of the format directives should use \param instead of \i. Or change the
% \i{foo} to \i{foo\/} to fix kerning problems.
%
% I decided to make a \j{...} which is \i{...\/} instead.
% It's not pretty but it's fast and I'm out of time. -kmp 30-Aug-93.
\beginsubsection{FORMAT Basic Output}
\beginsubsubsection{Tilde C: Character}
\idxtext{C (format directive)}\idxtext{Tilde C (format directive)}
%% 22.3.2 38
The next \j{arg} should be a \term{character};
it is printed
according to the modifier flags.
%% 22.3.2 39
\issue{FORMAT-OP-C}
\f{~C} prints the \term{character}
as if by using \funref{write-char} if it is a \term{simple character}.
\term{Characters} that are not \term{simple}
are not necessarily printed as if by \funref{write-char},
but are displayed in an \term{implementation-defined}, abbreviated format.
For example,
\code
(format nil "~C" #\\A) \EV "A"
(format nil "~C" #\\Space) \EV " "
\endcode
\endissue{FORMAT-OP-C}
%% 22.3.2 40
\f{~:C} is the same as \f{~C} for \term{printing} \term{characters},
but other \term{characters} are ``spelled out.'' The intent is that this
is a ``pretty'' format for printing characters.
For \term{simple} \term{characters} that are not \term{printing},
what is spelled out is the \term{name} of the \term{character} (see \funref{char-name}).
For \term{characters} that are not \term{simple} and not \term{printing},
what is spelled out is \term{implementation-defined}.
For example,
\code
(format nil "~:C" #\\A) \EV "A"
(format nil "~:C" #\\Space) \EV "Space"
;; This next example assumes an implementation-defined "Control" attribute.
(format nil "~:C" #\\Control-Space)
\EV "Control-Space"
\OV "c-Space"
\endcode
%% 22.3.2 41
\f{~:@C} prints what \f{~:C} would, and then
if the \term{character} requires unusual shift keys on the keyboard to type it,
this fact is mentioned. For example,
\begingroup
\def\Partial{$\partial$}
\code
(format nil "~:@C" #\\Control-Partial) \EV "Control-{\Partial} (Top-F)"
\endcode
\endgroup
This is the format used for telling the user about a key he is expected to type,
in prompts, for instance. The precise output may depend not only
on the implementation, but on the particular I/O devices in use.
%% 22.3.2 42
\f{~@C}
prints the \term{character} in a way that the \term{Lisp reader} can understand,
using \f{\#\\} syntax.
\issue{FORMAT-PRETTY-PRINT:YES}
\f{~@C} binds \varref{*print-escape*} to \t.
\endissue{FORMAT-PRETTY-PRINT:YES}
\endsubsubsection%{Tilde C: Character}
\beginsubsubsection{Tilde Percent: Newline}
\idxtext{Percent (format directive)}\idxtext{Tilde Percent (format directive)}
%% 22.3.2 96
This outputs a \f{\#\\Newline} character, thereby terminating the current
output line and beginning a new one.
\f{~\j{n}\%} outputs \j{n} newlines.
No \j{arg} is used.
\endsubsubsection%{Tilde Percent: Newline}
\beginsubsubsection{Tilde Ampersand: Fresh-Line}
\idxtext{Ampersand (format directive)}\idxtext{Tilde Ampersand (format directive)}
%% 22.3.2 97
Unless it can be determined that the output stream
is already at the beginning of a line,
this outputs a newline.
\f{~\j{n}\&} calls \funref{fresh-line}
and then outputs \j{n}\minussign 1 newlines.
\f{~0\&} does nothing.
\endsubsubsection%{Tilde Ampersand: Fresh-Line}
\beginsubsubsection{Tilde Vertical-Bar: Page}
\idxtext{Vertical-Bar (format directive)}\idxtext{Tilde Vertical-Bar (format directive)}
%% 22.3.2 98
This outputs a page separator character, if possible.
\f{~\j{n}|} does this \j{n} times.
\endsubsubsection%{Tilde Vertical-Bar: Page}
%% 22.3.2 99
\beginsubsubsection{Tilde Tilde: Tilde}
\idxtext{Tilde (format directive)}\idxtext{Tilde Tilde (format directive)}
This outputs a \term{tilde}. \f{~\j{n}~} outputs \j{n} tildes.
\endsubsubsection%{Tilde Tilde: Tilde}
\endsubsection%{FORMAT Basic Output}
\beginsubsection{FORMAT Radix Control}
\beginsubsubsection{Tilde R: Radix}
\idxtext{R (format directive)}\idxtext{Tilde R (format directive)}
%% 22.3.2 29
\f{~\j{n}R} prints \j{arg} in radix \j{n}.
The modifier flags and any remaining parameters are used as for
the \f{~D} directive.
\f{~D} is the same as \f{~10R}.
The full form is
\f{~\j{radix},\j{mincol},\j{padchar},\j{commachar},\j{comma-interval}R}.
%% 22.3.2 30
If no prefix parameters are given to \f{~R}, then a different
interpretation is given. The argument should be an \term{integer}.
For example, if \j{arg} is 4:
%% 22.3.2 31
\beginlist
\itemitem{\bull}
\f{~R} prints \j{arg} as a cardinal English number: \f{four}.
%% 22.3.2 32
\itemitem{\bull}
\f{~:R} prints \j{arg} as an ordinal English number: \f{fourth}.
%% 22.3.2 33
\itemitem{\bull}
\f{~@R} prints \j{arg} as a Roman numeral: \f{IV}.
%% 22.3.2 34
\itemitem{\bull}
\f{~:@R} prints \j{arg} as an old Roman numeral: \f{IIII}.
\endlist
\issue{FORMAT-COMMA-INTERVAL}
For example:
\code
(format nil "~,,' ,4:B" 13) \EV "1101"
(format nil "~,,' ,4:B" 17) \EV "1 0001"
(format nil "~19,0,' ,4:B" 3333) \EV "0000 1101 0000 0101"
(format nil "~3,,,' ,2:R" 17) \EV "1 22"
(format nil "~,,'|,2:D" #xFFFF) \EV "6|55|35"
\endcode
\endissue{FORMAT-COMMA-INTERVAL}
\issue{FORMAT-PRETTY-PRINT:YES}
If and only if the first parameter, \j{n}, is supplied,
\f{~R} binds
\varref{*print-escape*} to \term{false},
\varref{*print-radix*} to \term{false},
\varref{*print-base*} to \j{n},
\issue{PRINC-READABLY:X3J13-DEC-91}
and \varref{*print-readably*} to \term{false}.
\endissue{PRINC-READABLY:X3J13-DEC-91}
If and only if no parameters are supplied,
\f{~R} binds \varref{*print-base*} to \f{10}.
\endissue{FORMAT-PRETTY-PRINT:YES}
\endsubsubsection%{Tilde R: Radix}
\beginsubsubsection{Tilde D: Decimal}
\idxtext{D (format directive)}\idxtext{Tilde D (format directive)}
%% 22.3.2 20
An \j{arg}, which should be an \term{integer},
is printed in decimal radix.
\f{~D} will never put a decimal point after the number.
%% 22.3.2 21
\f{~\j{mincol}D} uses
a column width of \j{mincol}; spaces are inserted on
the left if the number requires fewer than \j{mincol} columns for its digits
and sign. If the number doesn't fit in \j{mincol} columns, additional columns
are used as needed.
%% 22.3.2 22
\f{~\j{mincol},\j{padchar}D} uses \j{padchar} as the pad character
instead of space.
%% 22.3.2 23
If \j{arg} is not an \term{integer}, it is printed in \f{~A} format and decimal base.
%% 22.3.2 24
The \f{@} modifier causes the number's sign to be printed always; the default
is to print it only if the number is negative.
\issue{FORMAT-COMMA-INTERVAL}
The \f{:} modifier causes commas to be printed between groups of digits;
\j{commachar} may be used to change the character used as the comma.
\j{comma-interval}
must be an \term{integer} and defaults to 3. When the \f{:}
modifier is given to any of
these directives, the \j{commachar}
is printed between groups of \j{comma-interval}
digits.
\endissue{FORMAT-COMMA-INTERVAL}
Thus the most general form of \f{~D} is
\f{~\j{mincol},\j{padchar},\j{commachar},\j{comma-interval}D}.
\issue{FORMAT-PRETTY-PRINT:YES}
\f{~D} binds
\varref{*print-escape*} to \term{false},
\varref{*print-radix*} to \term{false},
\varref{*print-base*} to \f{10},
\issue{PRINC-READABLY:X3J13-DEC-91}
and \varref{*print-readably*} to \term{false}.
\endissue{PRINC-READABLY:X3J13-DEC-91}
\endissue{FORMAT-PRETTY-PRINT:YES}
\endsubsubsection%{Tilde D: Decimal}
\beginsubsubsection{Tilde B: Binary}
\idxtext{B (format directive)}\idxtext{Tilde B (format directive)}
%% 22.3.2 25
This is just like \f{~D} but prints in binary radix (radix 2)
instead of decimal. The full form is therefore
\f{~\j{mincol},\j{padchar},\j{commachar},\j{comma-interval}B}.
\issue{FORMAT-PRETTY-PRINT:YES}
\f{~B} binds
\varref{*print-escape*} to \term{false},
\varref{*print-radix*} to \term{false},
\varref{*print-base*} to \f{2},
\issue{PRINC-READABLY:X3J13-DEC-91}
and \varref{*print-readably*} to \term{false}.
\endissue{PRINC-READABLY:X3J13-DEC-91}
\endissue{FORMAT-PRETTY-PRINT:YES}
\endsubsubsection%{Tilde B: Binary}
\beginsubsubsection{Tilde O: Octal}
\idxtext{O (format directive)}\idxtext{Tilde O (format directive)}
%% 22.3.2 26
This is just like \f{~D} but prints in octal radix (radix 8)
instead of decimal. The full form is therefore
\f{~\j{mincol},\j{padchar},\j{commachar},\j{comma-interval}O}.
\issue{FORMAT-PRETTY-PRINT:YES}
\f{~O} binds
\varref{*print-escape*} to \term{false},
\varref{*print-radix*} to \term{false},
\varref{*print-base*} to \f{8},
\issue{PRINC-READABLY:X3J13-DEC-91}
and \varref{*print-readably*} to \term{false}.
\endissue{PRINC-READABLY:X3J13-DEC-91}
\endissue{FORMAT-PRETTY-PRINT:YES}
\endsubsubsection%{Tilde O: Octal}
\beginsubsubsection{Tilde X: Hexadecimal}
\idxtext{X (format directive)}\idxtext{Tilde X (format directive)}
%% 22.3.2 27
This is just like \f{~D} but prints in hexadecimal radix
(radix 16) instead of decimal. The full form is therefore
\f{~\j{mincol},\j{padchar},\j{commachar},\j{comma-interval}X}.
\issue{FORMAT-PRETTY-PRINT:YES}
\f{~X} binds
\varref{*print-escape*} to \term{false},
\varref{*print-radix*} to \term{false},
\varref{*print-base*} to \f{16},
\issue{PRINC-READABLY:X3J13-DEC-91}
and \varref{*print-readably*} to \term{false}.
\endissue{PRINC-READABLY:X3J13-DEC-91}
\endissue{FORMAT-PRETTY-PRINT:YES}
\endsubsubsection%{Tilde X: Hexadecimal}
\endsubsection%{FORMAT Radix Control}
\beginsubsection{FORMAT Floating-Point Printers}
\beginsubsubsection{Tilde F: Fixed-Format Floating-Point}
\idxtext{F (format directive)}\idxtext{Tilde F (format directive)}
%% 22.3.2 43
The next \j{arg} is printed as a \term{float}.
%% 22.3.2 44
The full form is \f{~\j{w},\j{d},\j{k},\j{overflowchar},\j{padchar}F}.
The parameter \j{w}
is the width of the field to be printed; \j{d} is the number
of digits to print after the decimal point; \j{k} is a scale factor
that defaults to zero.
%% 22.3.2 45
Exactly \j{w} characters will
be output. First, leading copies of the character \j{padchar}
(which defaults to a space) are printed, if necessary, to pad the
field on the left.
If the \j{arg} is negative, then a minus sign is printed;
if the \j{arg} is not negative, then a plus sign is printed
if and only if the \f{@}
modifier was supplied. Then a sequence
of digits, containing a single embedded decimal point, is printed;
this represents the magnitude of the value of \j{arg} times $10^\j{k}$,
rounded to \j{d} fractional digits.
When rounding up and rounding down would produce printed values
equidistant from the scaled value of \j{arg}, then the implementation
is free to use either one. For example, printing the argument
\f{6.375} using the format \f{~4,2F} may correctly produce
either \f{6.37} or \f{6.38}.
Leading zeros are not permitted, except that a single
zero digit is output before the decimal point if the printed value
is less than one, and this single zero digit is not output
at all if \j{w}=\j{d}+1.
%% 22.3.2 46
If it is impossible to print the value in the required format in a field
of width \j{w}, then one of two actions is taken. If the
parameter \j{overflowchar} is supplied, then \j{w} copies of that
parameter are printed instead of the scaled value of \j{arg}.
If the \j{overflowchar} parameter is omitted, then the scaled value
is printed using more than \j{w} characters, as many more as may be
needed.
%% 22.3.2 47
If the \j{w} parameter is omitted, then the field is of variable width.
In effect, a value is chosen
for \j{w} in such a way that no leading pad characters need to be printed
and exactly \j{d} characters will follow the decimal point.
For example, the directive \f{~,2F} will print exactly
two digits after the decimal point and as many as necessary before the
decimal point.
%% 22.3.2 48
If the parameter \j{d} is omitted, then there is no constraint
on the number of digits to appear after the decimal point.
A value is chosen for \j{d} in such a way that as many digits
as possible may be printed subject to the width constraint
imposed by the parameter \j{w} and the constraint that no trailing
zero digits may appear in the fraction, except that if the
fraction to be printed is zero, then a single zero digit should
appear after the decimal point if permitted by the width constraint.
%% 22.3.2 49
If both \j{w} and \j{d} are omitted, then the effect is to print
the value using ordinary free-format output; \funref{prin1} uses this format
for any number whose magnitude is either zero or between
$10^{-3}$ (inclusive) and $10^7$ (exclusive).
%% 22.3.2 50
If \j{w} is omitted, then if the magnitude of \j{arg} is so large (or, if
\j{d} is also omitted, so small) that more than 100 digits would have to
be printed, then an implementation is free, at its discretion, to print
the number using exponential notation instead, as if by the directive
\f{~E} (with all parameters to \f{~E} defaulted, not
taking their values from the \f{~F} directive).
%% 22.3.2 51
If \j{arg} is a \term{rational}
number, then it is coerced to be a \term{single float}
and then printed. Alternatively, an implementation is permitted to
process a \term{rational}
number by any other method that has essentially the
same behavior but avoids loss of precision or overflow
because of the coercion. If \j{w} and \j{d} are
not supplied and the number has no exact decimal representation,
for example \f{1/3}, some precision cutoff must be chosen
by the implementation since only a finite number of digits may be printed.
%% 22.3.2 52
If \j{arg} is a \term{complex} number or some non-numeric
\term{object},
then it is printed using the format directive \f{~\j{w}D},
thereby printing it in decimal radix and a minimum field width of \j{w}.
\issue{FORMAT-PRETTY-PRINT:YES}
\f{~F} binds
\varref{*print-escape*} to \term{false}
\issue{PRINC-READABLY:X3J13-DEC-91}
and \varref{*print-readably*} to \term{false}.
\endissue{PRINC-READABLY:X3J13-DEC-91}
\endissue{FORMAT-PRETTY-PRINT:YES}
\endsubsubsection%{Tilde F: Fixed-Format Floating-Point}
\beginsubsubsection{Tilde E: Exponential Floating-Point}
\idxtext{E (format directive)}\idxtext{Tilde E (format directive)}
%% 22.3.2 62
The next \j{arg} is printed as a \term{float} in exponential notation.
%% 22.3.2 63
The full form is
\f{~\j{w},\j{d},\j{e},\j{k},\j{overflowchar},\j{padchar},\j{exponentchar}E}.
The parameter \j{w}
is the width of the field to be printed; \j{d} is the number
of digits to print after the decimal point; \j{e} is the number
of digits to use when printing the exponent;
\j{k} is a scale factor that defaults to one (not zero).
%% 22.3.2 64
Exactly \j{w} characters will
be output. First, leading copies of the character \j{padchar}
(which defaults to a space) are printed, if necessary, to pad the
field on the left.
If the \j{arg} is negative, then a minus sign is printed;
if the \j{arg} is not negative, then a plus sign is printed
if and only if the \f{@}
modifier was supplied. Then a sequence
of digits containing a single embedded decimal point is printed.
The form of this sequence of digits depends on the scale factor \j{k}.
If \j{k} is zero, then \j{d} digits are printed after the decimal
point, and a single zero digit appears before the decimal point if
the total field width will permit it. If \j{k} is positive,
then it must be strictly less than \j{d}+2; \j{k} significant digits
are printed before the decimal point, and \j{d}\minussign \j{k}+1
digits are printed after the decimal point. If \j{k} is negative,
then it must be strictly greater than \minussign \j{d};
a single zero digit appears before the decimal point if
the total field width will permit it, and after the decimal point
are printed first
\minussign \j{k} zeros and then \j{d}+\j{k} significant digits.
The printed fraction must be properly rounded.
When rounding up and rounding down would produce printed values
equidistant from the scaled value of \j{arg}, then the implementation
is free to use either one. For example, printing the argument
\f{637.5} using the format \f{~8,2E} may correctly produce
either \f{6.37E+2} or \f{6.38E+2}.
%% 22.3.2 65
Following the digit sequence, the exponent is printed.
First the character parameter \j{exponentchar} is printed; if this
parameter is omitted, then the \term{exponent marker} that
\funref{prin1} would use is printed, as determined from the
type of the \term{float} and the current value of
\varref{*read-default-float-format*}.
Next, either a plus sign or a minus sign
is printed, followed by \j{e} digits representing the power of
ten by which the printed fraction must be multiplied
to properly represent the rounded value of \j{arg}.
%% 22.3.2 66
If it is impossible to print the value in the required format in a field
of width \j{w}, possibly because \j{k} is too large or too small
or because the exponent cannot be printed in \j{e} character positions,
then one of two actions is taken. If the
parameter \j{overflowchar} is supplied, then \j{w} copies of that
parameter are printed instead of the scaled value of \j{arg}.
If the \j{overflowchar} parameter is omitted, then the scaled value
is printed using more than \j{w} characters, as many more as may be
needed; if the problem is that \j{d} is too small for the supplied \j{k}
or that \j{e} is too small, then a larger value is used for \j{d} or \j{e}
as may be needed.
%% 22.3.2 67
If the \j{w} parameter is omitted, then the field is of variable width.
In effect a value is chosen
for \j{w} in such a way that no leading pad characters need to be printed.
%% 22.3.2 68
If the parameter \j{d} is omitted, then there is no constraint
on the number of digits to appear.
A value is chosen for \j{d} in such a way that as many digits
as possible may be printed subject to the width constraint
imposed by the parameter \j{w}, the constraint of the scale factor \j{k},
and the constraint that no trailing
zero digits may appear in the fraction, except that if the
fraction to be printed is zero then a single zero digit should
appear after the decimal point.
%% 22.3.2 69
If the parameter \j{e} is omitted, then the exponent is printed
using the smallest number of digits necessary to represent its value.
%% 22.3.2 70
If all of \j{w}, \j{d}, and \j{e} are omitted, then the effect is to print
the value using ordinary free-format exponential-notation output;
\funref{prin1} uses
\issue{FORMAT-E-EXPONENT-SIGN:FORCE-SIGN}
a similar
\endissue{FORMAT-E-EXPONENT-SIGN:FORCE-SIGN}
format for any non-zero number whose magnitude
is less than $10^{-3}$ or greater than or equal to $10^7$.
\issue{FORMAT-E-EXPONENT-SIGN:FORCE-SIGN}
The only difference is that the \f{~E}
directive always prints a plus or minus # front of the
exponent, while \funref{prin1} omits the plus sign if the exponent is
non-negative.
\endissue{FORMAT-E-EXPONENT-SIGN:FORCE-SIGN}
%% 22.3.2 71
If \j{arg} is a \term{rational}
number, then it is coerced to be a \term{single float}
and then printed. Alternatively, an implementation is permitted to
process a \term{rational}
number by any other method that has essentially the
same behavior but avoids loss of precision or overflow
because of the coercion. If \j{w} and \j{d} are
unsupplied and the number has no exact decimal representation,
for example \f{1/3}, some precision cutoff must be chosen
by the implementation since only a finite number of digits may be printed.
%% 22.3.2 72
If \j{arg} is a \term{complex} number or some non-numeric
\term{object},
then it is printed using the format directive \f{~\j{w}D},
thereby printing it in decimal radix and a minimum field width of \j{w}.
\issue{FORMAT-PRETTY-PRINT:YES}
\f{~E} binds
\varref{*print-escape*} to \term{false}
\issue{PRINC-READABLY:X3J13-DEC-91}
and \varref{*print-readably*} to \term{false}.
\endissue{PRINC-READABLY:X3J13-DEC-91}
\endissue{FORMAT-PRETTY-PRINT:YES}
\endsubsubsection%{Tilde E: Exponential Floating-Point}
\beginsubsubsection{Tilde G: General Floating-Point}
\idxtext{G (format directive)}\idxtext{Tilde G (format directive)}
%% 22.3.2 82
The next \j{arg} is printed as a \term{float}
in either fixed-format or exponential notation as appropriate.
%% 22.3.2 83
The full form is \f{~\j{w},\j{d},\j{e},\j{k},\j{overflowchar},\j{padchar},\j{exponentchar}G}.
The format in which to print \j{arg} depends on the magnitude (absolute
value) of the \j{arg}. Let \j{n} be an integer such that
$10^{\j{n}-1}$ $\le$ |\j{arg}| < $10^\j{n}$.
Let \j{ee} equal \j{e}+2, or 4 if \j{e} is omitted.
Let \j{ww} equal \j{w}\minussign \j{ee},
or \nil\ if \j{w} is omitted. If \j{d} is omitted, first let \j{q}
be the number of digits needed to print \j{arg} with no loss
of information and without leading or trailing zeros;
then let \j{d} equal \f{(max \j{q} (min \j{n} 7))}.
Let \j{dd} equal \j{d}\minussign \j{n}.
%% 22.3.2 84
If 0 $\le$ \j{dd} $\le$ \j{d}, then \j{arg} is printed
as if by the format directives
%!!! ",," ??? -kmp 12-May-91
\f{~\j{ww},\j{dd},,\j{overflowchar},\j{padchar}F~\j{ee}@T}
Note that the scale factor \j{k} is not passed to the \f{~F}
directive. For all other values of \j{dd}, \j{arg} is printed as if
by the format directive
\f{~\j{w},\j{d},\j{e},\j{k},\j{overflowchar},\j{padchar},\j{exponentchar}E}
%% 22.3.2 85
In either case, an \f{@}
modifier is supplied to the \f{~F}
or \f{~E} directive if and only if one was supplied to the
\f{~G} directive.
\issue{FORMAT-PRETTY-PRINT:YES}
\f{~G} binds
\varref{*print-escape*} to \term{false}
\issue{PRINC-READABLY:X3J13-DEC-91}
and \varref{*print-readably*} to \term{false}.
\endissue{PRINC-READABLY:X3J13-DEC-91}
\endissue{FORMAT-PRETTY-PRINT:YES}
\endsubsubsection%{Tilde G: General Floating-Point}
\beginsubsubsection{Tilde Dollarsign: Monetary Floating-Point}
\idxtext{Dollarsign (format directive)}\idxtext{Tilde Dollarsign (format directive)}
%% 22.3.2 90
The next \j{arg} is printed as a \term{float} in fixed-format notation.
%% 22.3.2 91
The full form is \f{~\j{d},\j{n},\j{w},\j{padchar}\$}.
The parameter \j{d} is the number
of digits to print after the decimal point (default value 2);
\j{n} is the minimum number of digits to print before the decimal
point (default value 1);
\j{w} is the minimum total width of the field to be printed (default
value 0).
%% 22.3.2 92
First padding and the sign are output.
If the \j{arg} is negative, then a minus sign is printed;
if the \j{arg} is not negative, then a plus sign is printed
if and only if the \f{@} modifier was supplied.
If the \f{:} modifier is used, the sign appears before any padding,
and otherwise after the padding.
If \j{w} is supplied and the number of other characters to be output
is less than \j{w}, then copies of \j{padchar} (which defaults
to a space) are output to
make the total field width equal \j{w}.
Then \j{n} digits are printed for the integer part of \j{arg},
with leading zeros if necessary; then a decimal point;
then \j{d} digits of fraction, properly rounded.
%% 22.3.2 93
If the magnitude of \j{arg} is so large that more than \j{m} digits would
have to be printed, where \j{m} is the larger of \j{w} and 100, then an
implementation is free, at its discretion, to print the number using
exponential notation instead, as if by the directive
\f{~\j{w},\j{q},,,,\j{padchar}E}, where \j{w} and \j{padchar} are
present or omitted according to whether they were present or omitted in
the \f{~\$} directive, and where \j{q}=\j{d}+\j{n}\minussign 1,
where \j{d} and \j{n} are the (possibly default) values given to the
\f{~\$} directive.
%% 22.3.2 94
If \j{arg} is a \term{rational}
number, then it is coerced to be a \term{single float}
and then printed. Alternatively, an implementation is permitted to
process a \term{rational} number by any
other method that has essentially the
same behavior but avoids loss of precision or overflow
because of the coercion.
%% 22.3.2 95
If \j{arg} is a \term{complex} number or some non-numeric
\term{object},
then it is printed using the format directive \f{~\j{w}D},
thereby printing it in decimal radix and a minimum field width of \j{w}.
\issue{FORMAT-PRETTY-PRINT:YES}
\f{~\$} binds \varref{*print-escape*} to \term{false}
\issue{PRINC-READABLY:X3J13-DEC-91}
and \varref{*print-readably*} to \term{false}.
\endissue{PRINC-READABLY:X3J13-DEC-91}
\endissue{FORMAT-PRETTY-PRINT:YES}
\endsubsubsection%{Tilde Dollarsign: Monetary Floating-Point}
\endsubsection%{FORMAT Floating-Point Printers}
\beginsubsection{FORMAT Printer Operations}
\DefineSection{FORMATPrinterOps}
\beginsubsubsection{Tilde A: Aesthetic}
\idxtext{A (format directive)}\idxtext{Tilde A (format directive)}
%% A originally stood for ASCII. This seems like a bad mnemonic in a portable standard.
%% Replaced it with "Aesthetic". -kmp 30-Aug-93
%% 22.3.2 16
An \j{arg}, any \term{object},
is printed without escape characters
(as by \funref{princ}). If \j{arg} is a \term{string},
its \term{characters}
will be output verbatim.
If \j{arg} is \nil\ it will be printed as \nil;
the \term{colon} modifier (\f{~:A}) will cause an \j{arg} of \nil\ to be printed as \empty,
but if \j{arg} is a composite structure, such as a \term{list} or \term{vector},
any contained occurrences of \nil\ will still be printed as \nil.
%% 22.3.2 17
\f{~\j{mincol}A} inserts spaces on the right, if necessary, to make the
width at least \j{mincol} columns. The \f{@}
modifier causes the spaces
to be inserted on the left rather than the right.
%% 22.3.2 18
\f{~\j{mincol},\j{colinc},\j{minpad},\j{padchar}A}
is the full form of \f{~A},
which allows control of the padding.
The \term{string} is padded on the right (or on the left if the
\f{@} modifier is used) with at least \j{minpad} copies
of \j{padchar}; padding characters are then inserted \j{colinc} characters
at a time until the total width is at least \j{mincol}.
The defaults are \f{0} for \j{mincol} and \j{minpad}, \f{1} for \j{colinc},
and the space character for \j{padchar}.
\issue{FORMAT-PRETTY-PRINT:YES}
\f{~A} binds \varref{*print-escape*} to \term{false},
\issue{PRINC-READABLY:X3J13-DEC-91}
and \varref{*print-readably*} to \term{false}.
\endissue{PRINC-READABLY:X3J13-DEC-91}
\endissue{FORMAT-PRETTY-PRINT:YES}
\endsubsubsection%{Tilde A: Aesthetic}
\beginsubsubsection{Tilde S: Standard}
\idxtext{S (format directive)}\idxtext{Tilde S (format directive)}
%% S originally stood for S-expression, a term which no longer has any meaning.
%% Replaced it with "Standard", since this is the standard lisp representation.
%% -kmp 30-Aug-93
%% 22.3.2 19
This is just like \f{~A}, but \j{arg} is printed with escape
characters (as by \funref{prin1} rather than \f{princ}). The output is
therefore suitable for input to \funref{read}. \f{~S} accepts
all the arguments and modifiers that \f{~A} does.
\issue{FORMAT-PRETTY-PRINT:YES}
\f{~S} binds \varref{*print-escape*} to \t.
\endissue{FORMAT-PRETTY-PRINT:YES}
\endsubsubsection%{Tilde S: Standard}
\issue{PRETTY-PRINT-INTERFACE}
\beginsubsubsection{Tilde W: Write}
\idxtext{W (format directive)}\idxtext{Tilde W (format directive)}
An argument, any \term{object}, is printed obeying every printer control
variable (as by \funref{write}). In addition, \f{~W} interacts correctly with depth
abbreviation, by not resetting the depth counter to zero. \f{~W} does not
accept parameters. If given the \term{colon} modifier, \f{~W} binds \varref{*print-pretty*}
to \term{true}. If given the \term{at-sign} modifier, \f{~W} binds \varref{*print-level*}
and \varref{*print-length*} to \nil.
\f{~W} provides automatic support for the detection of circularity and
sharing. If \thevalueof{*print-circle*} is not \nil\ and \f{~W} is applied
to an argument that is a circular (or shared) reference, an appropriate
\f{\#\param{n}\#} marker is inserted in the output instead of printing the argument.
\endsubsubsection%{Tilde W: Write}
\endissue{PRETTY-PRINT-INTERFACE}
\endsubsection%{FORMAT Printer Operations}
\beginsubsection{FORMAT Pretty Printer Operations}
\issue{PRETTY-PRINT-INTERFACE}
The following constructs provide access to the \term{pretty printer}:
\beginsubsubsection{Tilde Underscore: Conditional Newline}
\DefineSection{TildeUnderscore}
\idxtext{Underscore (format directive)}\idxtext{Tilde Underscore (format directive)}
Without any modifiers, \f{~_} is the same as \f{(pprint-newline :linear)}.
\f{~@_} is the same as \f{(pprint-newline :miser)}.
\f{~:_} is the same as \f{(pprint-newline :fill)}.
\f{~:@_} is the same as \f{(pprint-newline :mandatory)}.
\endsubsubsection%{Tilde Underscore: Conditional Newline}
\beginsubsubsection{Tilde Less-Than-Sign: Logical Block}
\DefineSection{TildeLessThanLogicalBlock}
\idxtext{Less-Than-Sign (format directive)}\idxtext{Tilde Less-Than-Sign (format directive)}
\f{~<...~:>}
If \f{~:>} is used to terminate a \f{~<...~>},
the directive is equivalent to a call to \macref{pprint-logical-block}.
The argument corresponding to the \f{~<...~:>} directive is treated in
the same way as the \term{list} argument to \funref{pprint-logical-block},
thereby providing automatic support for non-\term{list} arguments and
the detection of circularity, sharing, and depth abbreviation.
The portion of the \param{control-string} nested within the \f{~<...~:>}
specifies the \kwd{prefix} (or \kwd{per-line-prefix}), \kwd{suffix},
and body of the \macref{pprint-logical-block}.
The \param{control-string} portion enclosed by \f{~<...~:>} can be divided
into segments \f{~<\param{prefix}~;\param{body}~;\param{suffix}~:>}
by \f{~;} directives. If the first section is terminated by \f{~@;},
it specifies a per-line prefix rather than a simple prefix.
The \param{prefix} and \param{suffix} cannot contain format directives.
An error is signaled if either the prefix or suffix fails to be a
constant string or if the enclosed portion is divided into more than three segments.
If the enclosed portion is divided into only two segments, the \param{suffix}
defaults to the null string. If the enclosed portion consists of only
a single segment, both the \param{prefix} and the \param{suffix} default to
the null string. If the \term{colon} modifier is used (\ie \f{~:<...~:>}),
the \param{prefix} and \param{suffix} default to \f{"("} and \f{")"}
(respectively) instead of the null string.
The body segment can be any arbitrary \term{format string}.
This \term{format string} is applied to the elements of the list
corresponding to the \f{~<...~:>} directive as a whole.
Elements are extracted from this list using \macref{pprint-pop},
thereby providing automatic support for malformed lists, and the detection
of circularity, sharing, and length abbreviation.
Within the body segment, \f{~{\hat}} acts like \macref{pprint-exit-if-list-exhausted}.
\f{~<...~:>} supports a feature not supported by \macref{pprint-logical-block}.
If \f{~:@>} is used to terminate the directive (\ie \f{~<...~:@>}),
then a fill-style conditional newline is automatically inserted after each
group of blanks immediately contained in the body (except for blanks
after a ~\NewlineChar\ directive). This makes it easy to achieve the
equivalent of paragraph filling.
If the \term{at-sign} modifier is used with \f{~<...~:>}, the entire remaining argument
list is passed to the directive as its argument. All of the remaining
arguments are always consumed by \f{~@<...~:>}, even if they are not all used
by the \term{format string} nested in the directive. Other than the difference in
its argument, \f{~@<...~:>} is exactly the same as \f{~<...~:>} except that
circularity detection is not applied if \f{~@<...~:>} is encountered at top
level in a \term{format string}. This ensures that circularity detection is
applied only to data lists, not to \term{format argument} \term{lists}.
\f{" . \#\param{n}\#"} is printed if circularity or sharing has to be indicated
for its argument as a whole.
To a considerable extent, the basic form of the directive \f{~<...~>} is
incompatible with the dynamic control of the arrangement of output by
\f{~W}, \f{~_}, \f{~<...~:>}, \f{~I}, and \f{~:T}. As a result, an error
is signaled if any of these directives is nested within \f{~<...~>}.
Beyond this, an error is also signaled if the \f{~<...~:;...~>} form of
\f{~<...~>} is used in the same \term{format string} with
\f{~W}, \f{~_}, \f{~<...~:>}, \f{~I}, or \f{~:T}.
See also \secref\TildeLessThanJustification.
\endsubsubsection%{Tilde Less-Than-Sign: Logical Block}
\beginsubsubsection{Tilde I: Indent}
\DefineSection{TildeI}
\idxtext{I (format directive)}\idxtext{Tilde I (format directive)}
\f{~\param{n}I} is the same as \f{(pprint-indent :block n)}.
\f{~\param{n}:I} is the same as \f{(pprint-indent :current n)}.
In both cases, \param{n} defaults to zero, if it is omitted.
\endsubsubsection%{Tilde I: Indent}
\beginsubsubsection{Tilde Slash: Call Function}
\idxtext{Slash (format directive)}\idxtext{Tilde Slash (format directive)}
\f{~/\param{name}/}
User defined functions can be called from within a format
string by using the directive \f{~/\param{name}/}.
The \term{colon} modifier, the \term{at-sign} modifier, and arbitrarily many parameters
can be specified with the \f{~/\param{name}/} directive.
\param{name} can be any arbitrary string that does not contain a "/".
All of the characters in \param{name} are treated as if they were upper case.
If \param{name} contains a single \term{colon} (\f{:}) or double \term{colon} (\f{::}),
then everything up to but not including the first \f{":"} or \f{"::"}
is taken to be a \term{string} that names a \term{package}.
Everything after the first \f{":"} or \f{"::"} (if any) is taken to be a
\term{string} that names a \f{symbol}. The function corresponding to a