FORMAT-PRETTY-PRINTFORMAT operators, ~A and ~S are defined to print their argument as PRINC and PRIN1 respectively. The text does not say whether or not these FORMAT operators must obey the *PRINT-PRETTY* flag.FORMAT does not rebind any of the printer control variables (*PRINT-...) except as follows:
~A Binds *PRINT-ESCAPE* to NIL.
~S Binds *PRINT-ESCAPE* to T.
~D Binds *PRINT-ESCAPE* to NIL, *PRINT-RADIX* to NIL, and *PRINT-BASE* to 10.
~B Binds *PRINT-ESCAPE* to NIL, *PRINT-RADIX* to NIL, and *PRINT-BASE* to 2.
~O Binds *PRINT-ESCAPE* to NIL, *PRINT-RADIX* to NIL, and *PRINT-BASE* to 8.
~X Binds *PRINT-ESCAPE* to NIL, *PRINT-RADIX* to NIL, and *PRINT-BASE* to 16.
~R Iff a first argument is specified, binds *PRINT-ESCAPE* to NIL, *PRINT-RADIX* to NIL, and *PRINT-BASE* to the value of the first argument.
Iff no aruments are specified, binds *PRINT-BASE* to 10.
~@C Binds *PRINT-ESCAPE* to T.
~F,~G,~E,~$ Binds *PRINT-ESCAPE* to NIL.
LET ((TEST '#'(LAMBDA (X) (LET ((*PRINT-PRETTY* T)) (PRINT X) (FORMAT T "~%~S " X) (TERPRI) (PRINC X) (PRINC " ") (FORMAT T "~%~A " X))))) (FUNCALL (EVAL TEST) TEST))
This should print four copies of the above lambda expression. The first pair should appear identical and the second pair should appear identical. The only difference between the two pairs should be the absence of string quotes in the second pair.
FORMAT should interact with the printer control variables in a predictable way. This proposal is one of the two simplest possible definitions and provides the most flexibility to the user.
A major advantage of this proposal is that the following two expressions are guaranteed to have exactly the same effect:
(FORMAT stream "~S" object)
(PRIN1 object stream)
Thus use or non-use of FORMAT becomes a purely stylistic matter.
TI Explorer obey the binding of *PRINT-PRETTY*. Lucid Common Lisp always applies ~A and ~S with *PRINT-PRETTY* bound to NIL.FORMAT to not bind *PRINT-foo* variables is trivial, there are some painful implications. How does a pretty-printing ~A interact with MINCOL, etc? How much of the user interface depends on FORMAT in ways that might be uglified by pretty printing?FORMAT and the printer control variables (especially *PRINT-PRETTY*) will remain undefined. This will continue to make portable Common Lisp programming harder than it need be.FORMAT and the *PRINT- variables. There may be other similar interactions in Common Lisp that need clarification.
Otherwise, code that depends on FORMATs action in one implementation will not port to others that do not have the same behavior.
CLtL might change as follows:
Add a header "Printer Control Variables" before the description of *PRINT-ESCAPE* on page 370.
Add the following paragraph to page 386 just before the paragraph starting with "It is an error":
"The FORMAT function by itself never binds any of the printer control variables. Specific FORMAT directives bind exactly the printer control variables specified in their description. While implementations may specify the binding of new, implementation specific printer control variables for each FORMAT directive, they may neither bind any standard printer control variables not specified in description of a FORMAT directive nor fail to bind any standard printer control variables as specified in the description."
There was some discussion on whether *PRINT-BASE* should be bound for ~F, ~G, ~E, and ~$. This is not necessary because page 341 of CLtL states that floating point numbers are always printed in base 10.