220 lines
15 KiB
HTML
220 lines
15 KiB
HTML
<!-- Common Lisp HyperSpec (TM), version 7.0 generated by Kent M. Pitman on Mon, 11-Apr-2005 2:31am EDT -->
|
|
<HTML>
|
|
<HEAD>
|
|
<TITLE>CLHS: Issue FORMAT-PRETTY-PRINT Writeup</TITLE>
|
|
<LINK HREF="../Data/clhs.css" REL="stylesheet" TYPE="text/css" />
|
|
<META HTTP-EQUIV="Author" CONTENT="Kent M. Pitman">
|
|
<META HTTP-EQUIV="Organization" CONTENT="LispWorks Ltd.">
|
|
<LINK REL=TOP HREF="../Front/index.htm">
|
|
<LINK REL=COPYRIGHT HREF="../Front/Help.htm#Legal">
|
|
<LINK REL=DISCLAIMER HREF="../Front/Help.htm#Disclaimer">
|
|
<LINK REL=PREV HREF="../Issues/iss168_w.htm">
|
|
<LINK REL=UP HREF="../Issues/iss169.htm">
|
|
<LINK REL=NEXT HREF="../Issues/iss170_w.htm">
|
|
</HEAD>
|
|
<BODY>
|
|
<H1><A REV=MADE HREF="http://www.lispworks.com/"><IMG WIDTH=80 HEIGHT=65 ALT="[LISPWORKS]" SRC="../Graphics/LWSmall.gif" ALIGN=Bottom></A><A REL=TOP HREF="../Front/index.htm"><IMG WIDTH=237 HEIGHT=65 ALT="[Common Lisp HyperSpec (TM)]" SRC="../Graphics/CLHS_Sm.gif" ALIGN=Bottom></A> <A REL=PREV HREF="../Issues/iss168_w.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Previous]" SRC="../Graphics/Prev.gif" ALIGN=Bottom></A><A REL=UP HREF="../Issues/iss169.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Up]" SRC="../Graphics/Up.gif" ALIGN=Bottom></A><A REL=NEXT HREF="../Issues/iss170_w.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Next]" SRC="../Graphics/Next.gif" ALIGN=Bottom></A></H1>
|
|
|
|
<HR>
|
|
|
|
|
|
|
|
<H2>Issue FORMAT-PRETTY-PRINT Writeup</H2>
|
|
|
|
<PRE>See "Additional Discussion" at end.<P>
|
|
-----<P>
|
|
<B>Issue:</B> <A HREF="iss169.htm">FORMAT-PRETTY-PRINT</A><P>
|
|
<B>References:</B> <A REL=DEFINITION HREF="../Body/f_format.htm#format"><B>FORMAT</B></A> (pp. 385-388), <A REL=DEFINITION HREF="../Body/f_wr_pr.htm#prin1"><B>PRIN1</B></A> (p. 83), <A REL=DEFINITION HREF="../Body/f_wr_pr.htm#princ"><B>PRINC</B></A> (p. 83),<P>
|
|
<A REL=DEFINITION HREF="../Body/f_wr_pr.htm#write"><B>WRITE</B></A> (p. 382), <A REL=DEFINITION HREF="../Body/v_pr_pre.htm#STprint-prettyST"><B>*PRINT-PRETTY*</B></A> (p. 371)<P>
|
|
<B>Category:</B> CLARIFICATION<P>
|
|
<B>Edit history:</B> Version 1 by Pierson 3/4/88<P>
|
|
Version 2 by Pierson 5/24/88 (fix name typo)<P>
|
|
Version 3 by Pierson 6/10/88 incorporate comments<P>
|
|
Version 4 by Pierson 6/10/88 comments from Van Roggen<P>
|
|
Version 5 by Masinter 2-Oct-88<P>
|
|
Version 6 by Pierson 11/10/88 final nits<P>
|
|
Version 7 by Pierson 11/15/88 "does" => "does not"<P>
|
|
<P>
|
|
<B>Problem description:<P>
|
|
</B><P>
|
|
The <A REL=DEFINITION HREF="../Body/f_format.htm#format"><B>FORMAT</B></A> operators, ~A and ~S are defined to print their argument as<P>
|
|
<A REL=DEFINITION HREF="../Body/f_wr_pr.htm#princ"><B>PRINC</B></A> and <A REL=DEFINITION HREF="../Body/f_wr_pr.htm#prin1"><B>PRIN1</B></A> respectively. The text does not say whether or not<P>
|
|
these <A REL=DEFINITION HREF="../Body/f_format.htm#format"><B>FORMAT</B></A> operators must obey the <A REL=DEFINITION HREF="../Body/v_pr_pre.htm#STprint-prettyST"><B>*PRINT-PRETTY*</B></A> flag.<P>
|
|
<P>
|
|
<B>Proposal (FORMAT-PRETTY-PRINT:YES):<P>
|
|
</B><P>
|
|
Specify that <A REL=DEFINITION HREF="../Body/f_format.htm#format"><B>FORMAT</B></A> does not rebind any of the printer control<P>
|
|
variables (*PRINT-...) except as follows:<P>
|
|
<P>
|
|
~A<P>
|
|
Binds <A REL=DEFINITION HREF="../Body/v_pr_esc.htm#STprint-escapeST"><B>*PRINT-ESCAPE*</B></A> to <A REL=DEFINITION HREF="../Body/a_nil.htm#nil"><B>NIL</B></A>.<P>
|
|
<P>
|
|
~S<P>
|
|
Binds <A REL=DEFINITION HREF="../Body/v_pr_esc.htm#STprint-escapeST"><B>*PRINT-ESCAPE*</B></A> to T.<P>
|
|
<P>
|
|
~D<P>
|
|
Binds <A REL=DEFINITION HREF="../Body/v_pr_esc.htm#STprint-escapeST"><B>*PRINT-ESCAPE*</B></A> to <A REL=DEFINITION HREF="../Body/a_nil.htm#nil"><B>NIL</B></A>, <A REL=DEFINITION HREF="../Body/v_pr_bas.htm#STprint-radixST"><B>*PRINT-RADIX*</B></A> to <A REL=DEFINITION HREF="../Body/a_nil.htm#nil"><B>NIL</B></A>, and<P>
|
|
<A REL=DEFINITION HREF="../Body/v_pr_bas.htm#STprint-baseST"><B>*PRINT-BASE*</B></A> to 10.<P>
|
|
<P>
|
|
~B<P>
|
|
Binds <A REL=DEFINITION HREF="../Body/v_pr_esc.htm#STprint-escapeST"><B>*PRINT-ESCAPE*</B></A> to <A REL=DEFINITION HREF="../Body/a_nil.htm#nil"><B>NIL</B></A>, <A REL=DEFINITION HREF="../Body/v_pr_bas.htm#STprint-radixST"><B>*PRINT-RADIX*</B></A> to <A REL=DEFINITION HREF="../Body/a_nil.htm#nil"><B>NIL</B></A>, and<P>
|
|
<A REL=DEFINITION HREF="../Body/v_pr_bas.htm#STprint-baseST"><B>*PRINT-BASE*</B></A> to 2.<P>
|
|
<P>
|
|
~O<P>
|
|
Binds <A REL=DEFINITION HREF="../Body/v_pr_esc.htm#STprint-escapeST"><B>*PRINT-ESCAPE*</B></A> to <A REL=DEFINITION HREF="../Body/a_nil.htm#nil"><B>NIL</B></A>, <A REL=DEFINITION HREF="../Body/v_pr_bas.htm#STprint-radixST"><B>*PRINT-RADIX*</B></A> to <A REL=DEFINITION HREF="../Body/a_nil.htm#nil"><B>NIL</B></A>, and<P>
|
|
<A REL=DEFINITION HREF="../Body/v_pr_bas.htm#STprint-baseST"><B>*PRINT-BASE*</B></A> to 8.<P>
|
|
<P>
|
|
~X<P>
|
|
Binds <A REL=DEFINITION HREF="../Body/v_pr_esc.htm#STprint-escapeST"><B>*PRINT-ESCAPE*</B></A> to <A REL=DEFINITION HREF="../Body/a_nil.htm#nil"><B>NIL</B></A>, <A REL=DEFINITION HREF="../Body/v_pr_bas.htm#STprint-radixST"><B>*PRINT-RADIX*</B></A> to <A REL=DEFINITION HREF="../Body/a_nil.htm#nil"><B>NIL</B></A>, and<P>
|
|
<A REL=DEFINITION HREF="../Body/v_pr_bas.htm#STprint-baseST"><B>*PRINT-BASE*</B></A> to 16.<P>
|
|
<P>
|
|
~R<P>
|
|
Iff a first argument is specified, binds <A REL=DEFINITION HREF="../Body/v_pr_esc.htm#STprint-escapeST"><B>*PRINT-ESCAPE*</B></A> to <A REL=DEFINITION HREF="../Body/a_nil.htm#nil"><B>NIL</B></A>,<P>
|
|
<A REL=DEFINITION HREF="../Body/v_pr_bas.htm#STprint-radixST"><B>*PRINT-RADIX*</B></A> to <A REL=DEFINITION HREF="../Body/a_nil.htm#nil"><B>NIL</B></A>, and <A REL=DEFINITION HREF="../Body/v_pr_bas.htm#STprint-baseST"><B>*PRINT-BASE*</B></A> to the value of the first<P>
|
|
argument.<P>
|
|
<P>
|
|
Iff no aruments are specified, binds <A REL=DEFINITION HREF="../Body/v_pr_bas.htm#STprint-baseST"><B>*PRINT-BASE*</B></A> to 10.<P>
|
|
<P>
|
|
~@C<P>
|
|
Binds <A REL=DEFINITION HREF="../Body/v_pr_esc.htm#STprint-escapeST"><B>*PRINT-ESCAPE*</B></A> to T.<P>
|
|
<P>
|
|
~F,~G,~E,~$<P>
|
|
Binds <A REL=DEFINITION HREF="../Body/v_pr_esc.htm#STprint-escapeST"><B>*PRINT-ESCAPE*</B></A> to <A REL=DEFINITION HREF="../Body/a_nil.htm#nil"><B>NIL</B></A>.<P>
|
|
<P>
|
|
<B>Test Cases/Examples:<P>
|
|
</B><P>
|
|
(<A REL=DEFINITION HREF="../Body/s_let_l.htm#let"><B>LET</B></A> ((TEST '#'(<A REL=DEFINITION HREF="../Body/a_lambda.htm#lambda"><B>LAMBDA</B></A> (X)<P>
|
|
(<A REL=DEFINITION HREF="../Body/s_let_l.htm#let"><B>LET</B></A> ((<A REL=DEFINITION HREF="../Body/v_pr_pre.htm#STprint-prettyST"><B>*PRINT-PRETTY*</B></A> T))<P>
|
|
(<A REL=DEFINITION HREF="../Body/f_wr_pr.htm#print"><B>PRINT</B></A> X)<P>
|
|
(<A REL=DEFINITION HREF="../Body/f_format.htm#format"><B>FORMAT</B></A> T "~%~S " X)<P>
|
|
(<A REL=DEFINITION HREF="../Body/f_terpri.htm#terpri"><B>TERPRI</B></A>) (<A REL=DEFINITION HREF="../Body/f_wr_pr.htm#princ"><B>PRINC</B></A> X) (<A REL=DEFINITION HREF="../Body/f_wr_pr.htm#princ"><B>PRINC</B></A> " ")<P>
|
|
(<A REL=DEFINITION HREF="../Body/f_format.htm#format"><B>FORMAT</B></A> T "~%~A " X)))))<P>
|
|
(<A REL=DEFINITION HREF="../Body/f_funcal.htm#funcall"><B>FUNCALL</B></A> (<A REL=DEFINITION HREF="../Body/f_eval.htm#eval"><B>EVAL</B></A> TEST) TEST))<P>
|
|
<P>
|
|
This should print four copies of the above <A REL=DEFINITION HREF="../Body/a_lambda.htm#lambda"><B>lambda</B></A> expression. The<P>
|
|
first pair should appear identical and the second pair should appear<P>
|
|
identical. The only difference between the two pairs should be the<P>
|
|
absence of string quotes in the second pair.<P>
|
|
<P>
|
|
<B>Rationale:<P>
|
|
</B><P>
|
|
<A REL=DEFINITION HREF="../Body/f_format.htm#format"><B>FORMAT</B></A> should interact with the printer control variables in a<P>
|
|
predictable way. This proposal is one of the two simplest possible<P>
|
|
definitions and provides the most flexibility to the user.<P>
|
|
<P>
|
|
A major advantage of this proposal is that the following two<P>
|
|
expressions are guaranteed to have exactly the same effect:<P>
|
|
<P>
|
|
(<A REL=DEFINITION HREF="../Body/f_format.htm#format"><B>FORMAT</B></A> <A REL=DEFINITION HREF="../Body/t_stream.htm#stream"><B>stream</B></A> "~S" object)<P>
|
|
(<A REL=DEFINITION HREF="../Body/f_wr_pr.htm#prin1"><B>PRIN1</B></A> object <A REL=DEFINITION HREF="../Body/t_stream.htm#stream"><B>stream</B></A>)<P>
|
|
<P>
|
|
Thus use or non-use of <A REL=DEFINITION HREF="../Body/f_format.htm#format"><B>FORMAT</B></A> becomes a purely stylistic matter.<P>
|
|
<P>
|
|
<B>Current practice:<P>
|
|
</B><P>
|
|
Ibuki Lisp and the TI Explorer obey the binding of <A REL=DEFINITION HREF="../Body/v_pr_pre.htm#STprint-prettyST"><B>*PRINT-PRETTY*</B></A>.<P>
|
|
Lucid Common Lisp always applies ~A and ~S with <A REL=DEFINITION HREF="../Body/v_pr_pre.htm#STprint-prettyST"><B>*PRINT-PRETTY*</B></A> bound<P>
|
|
to <A REL=DEFINITION HREF="../Body/a_nil.htm#nil"><B>NIL</B></A>.<P>
|
|
<P>
|
|
<B>Cost to Implementors:<P>
|
|
</B><P>
|
|
While changing <A REL=DEFINITION HREF="../Body/f_format.htm#format"><B>FORMAT</B></A> to not bind *PRINT-foo* variables is trivial,<P>
|
|
there are some painful implications. How does a pretty-printing ~A<P>
|
|
interact with MINCOL, etc? How much of the user interface depends on<P>
|
|
<A REL=DEFINITION HREF="../Body/f_format.htm#format"><B>FORMAT</B></A> in ways that might be uglified by pretty printing?<P>
|
|
<P>
|
|
<B>Cost to Users:<P>
|
|
</B><P>
|
|
Truely portable code shouldn't be affected because existing<P>
|
|
implementations are inconsistent. Despite this, there are probably a<P>
|
|
number of user programs in non-complying implementations which will<P>
|
|
have to change whichever way this is decided.<P>
|
|
<P>
|
|
<B>Cost of non-Adoption:<P>
|
|
</B><P>
|
|
The interaction of <A REL=DEFINITION HREF="../Body/f_format.htm#format"><B>FORMAT</B></A> and the printer control variables (especially<P>
|
|
<A REL=DEFINITION HREF="../Body/v_pr_pre.htm#STprint-prettyST"><B>*PRINT-PRETTY*</B></A>) will remain undefined. This will continue to make<P>
|
|
portable Common Lisp programming harder than it need be.<P>
|
|
<P>
|
|
<B>Benefits:<P>
|
|
</B><P>
|
|
Life will be easier for users in two ways: (1) one more portability<P>
|
|
problem will be removed, and (2) users will be more likely to be able<P>
|
|
to persuade environmental features like debuggers to print in their<P>
|
|
preferred way.<P>
|
|
<P>
|
|
<B>Aesthetics:<P>
|
|
</B><P>
|
|
The interaction between two related parts of output will be clarified<P>
|
|
in a simple way.<P>
|
|
<P>
|
|
<B>Discussion:<P>
|
|
</B><P>
|
|
It is important to specify exactly what of Common Lisp's special<P>
|
|
variables get rebound by other functions and macros in Common Lisp.<P>
|
|
This cleanup issue addresses the interaction of <A REL=DEFINITION HREF="../Body/f_format.htm#format"><B>FORMAT</B></A> and the<P>
|
|
*PRINT- variables. There may be other similar interactions in <P>
|
|
Common Lisp that need clarification.<P>
|
|
<P>
|
|
Otherwise, code that depends on FORMATs action in one implementation<P>
|
|
will not port to others that do not have the same behavior.<P>
|
|
<P>
|
|
CLtL might change as follows:<P>
|
|
<P>
|
|
Add a header "Printer Control Variables" before the description of<P>
|
|
<A REL=DEFINITION HREF="../Body/v_pr_esc.htm#STprint-escapeST"><B>*PRINT-ESCAPE*</B></A> on page 370.<P>
|
|
<P>
|
|
Add the following paragraph to page 386 just before the paragraph<P>
|
|
starting with "It is an error":<P>
|
|
<P>
|
|
"The <A REL=DEFINITION HREF="../Body/f_format.htm#format"><B>FORMAT</B></A> function by itself never binds any of the printer<P>
|
|
control variables. Specific <A REL=DEFINITION HREF="../Body/f_format.htm#format"><B>FORMAT</B></A> directives bind exactly the<P>
|
|
printer control variables specified in their description. While<P>
|
|
implementations may specify the binding of new, implementation<P>
|
|
specific printer control variables for each <A REL=DEFINITION HREF="../Body/f_format.htm#format"><B>FORMAT</B></A> directive, they<P>
|
|
may neither bind any <A REL=DEFINITION HREF="../Body/07_ffb.htm#standard"><B>standard</B></A> printer control variables not<P>
|
|
specified in description of a <A REL=DEFINITION HREF="../Body/f_format.htm#format"><B>FORMAT</B></A> directive nor fail to bind<P>
|
|
any <A REL=DEFINITION HREF="../Body/07_ffb.htm#standard"><B>standard</B></A> printer control variables as specified in the<P>
|
|
description."<P>
|
|
<P>
|
|
There was some discussion on whether <A REL=DEFINITION HREF="../Body/v_pr_bas.htm#STprint-baseST"><B>*PRINT-BASE*</B></A> should be bound for<P>
|
|
~F, ~G, ~E, and ~$. This is not necessary because page 341 of CLtL<P>
|
|
states that floating point numbers are always printed in base 10.<P>
|
|
<P>
|
|
-----<P>
|
|
Additional Discussion:<P>
|
|
<P>
|
|
Date: Tue, 23 Jul 91 11:24:56 EDT<P>
|
|
From: Guy Steele <gls@Think.COM><P>
|
|
To: KMP@STONY-BROOK.SCRC.Symbolics.COM<P>
|
|
Cc: Quinquevirate@MCC.COM, KMP@STONY-BROOK.SCRC.Symbolics.COM<P>
|
|
In-Reply-To: <19910712224013.6.KMP@BOBOLINK.SCRC.Symbolics.COM><P>
|
|
Subject: Hopefully just a typo in <A HREF="iss169.htm">FORMAT-PRETTY-PRINT</A><P>
|
|
<P>
|
|
Date: Fri, 12 Jul 1991 18:40-0400<P>
|
|
From: Kent M Pitman <KMP@STONY-BROOK.SCRC.Symbolics.COM><P>
|
|
<P>
|
|
>From the proposal part of issue <A HREF="iss169.htm">FORMAT-PRETTY-PRINT:YES</A> ...<P>
|
|
<P>
|
|
==========<P>
|
|
~R<P>
|
|
Iff a first argument is specified, binds <A REL=DEFINITION HREF="../Body/v_pr_esc.htm#STprint-escapeST"><B>*PRINT-ESCAPE*</B></A> to <A REL=DEFINITION HREF="../Body/a_nil.htm#nil"><B>NIL</B></A>,<P>
|
|
<A REL=DEFINITION HREF="../Body/v_pr_bas.htm#STprint-radixST"><B>*PRINT-RADIX*</B></A> to <A REL=DEFINITION HREF="../Body/a_nil.htm#nil"><B>NIL</B></A>, and <A REL=DEFINITION HREF="../Body/v_pr_bas.htm#STprint-baseST"><B>*PRINT-BASE*</B></A> to the value of the first<P>
|
|
argument.<P>
|
|
<P>
|
|
Iff no arguments are specified, binds <A REL=DEFINITION HREF="../Body/v_pr_bas.htm#STprint-baseST"><B>*PRINT-BASE*</B></A> to 10.<P>
|
|
==========<P>
|
|
<P>
|
|
I'm just going to assume that "parameter" was intended instead of<P>
|
|
"argument" in all three cases. If someone disagrees, they should say so.<P>
|
|
<P>
|
|
I believe your assumption is correct.<P>
|
|
--Guy<P>
|
|
</PRE>
|
|
<HR>
|
|
|
|
<A REL=NAVIGATOR HREF="../Front/StartPts.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Starting Points]" SRC="../Graphics/StartPts.gif" ALIGN=Bottom></A><A REL=TOC HREF="../Front/Contents.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Contents]" SRC="../Graphics/Contents.gif" ALIGN=Bottom></A><A REL=INDEX HREF="../Front/X_Master.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Index]" SRC="../Graphics/Index.gif" ALIGN=Bottom></A><A REL=INDEX HREF="../Front/X_Symbol.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Symbols]" SRC="../Graphics/Symbols.gif" ALIGN=Bottom></A><A REL=GLOSSARY HREF="../Body/26_a.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Glossary]" SRC="../Graphics/Glossary.gif" ALIGN=Bottom></A><A HREF="../Front/X3J13Iss.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Issues]" SRC="../Graphics/Issues.gif" ALIGN=Bottom></A><BR>
|
|
|
|
<A REL=COPYRIGHT HREF="../Front/Help.htm#Legal"><I>Copyright 1996-2005, LispWorks Ltd. All rights reserved.</I></A><P>
|
|
</BODY>
|
|
</HTML>
|