154 lines
9.7 KiB
HTML
154 lines
9.7 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 PRINC-READABLY 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/iss270_w.htm">
|
|
<LINK REL=UP HREF="../Issues/iss271.htm">
|
|
<LINK REL=NEXT HREF="../Issues/iss272_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/iss270_w.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Previous]" SRC="../Graphics/Prev.gif" ALIGN=Bottom></A><A REL=UP HREF="../Issues/iss271.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Up]" SRC="../Graphics/Up.gif" ALIGN=Bottom></A><A REL=NEXT HREF="../Issues/iss272_w.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Next]" SRC="../Graphics/Next.gif" ALIGN=Bottom></A></H1>
|
|
|
|
<HR>
|
|
|
|
|
|
|
|
<H2>Issue PRINC-READABLY Writeup</H2>
|
|
|
|
<PRE><B>Issue:</B> <A HREF="iss271.htm">PRINC-READABLY</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>
|
|
Related Issues: <A HREF="iss089.htm">DATA-IO</A>, <A HREF="iss169.htm">FORMAT-PRETTY-PRINT</A>, <A HREF="iss274.htm">PRINT-CIRCLE-SHARED</A><P>
|
|
<B>Category:</B> CHANGE<P>
|
|
<B>Edit history:</B> Version 1 by Moon 9/25/91<P>
|
|
<P>
|
|
<B>Problem description:<P>
|
|
</B><P>
|
|
What do you think this form outputs?<P>
|
|
<P>
|
|
(<A REL=DEFINITION HREF="../Body/s_let_l.htm#let"><B>let</B></A> ((<A REL=DEFINITION HREF="../Body/v_pr_rda.htm#STprint-readablyST"><B>*print-readably*</B></A> t))<P>
|
|
(<A REL=DEFINITION HREF="../Body/f_format.htm#format"><B>format</B></A> t "<~A>" '|Foo|))<P>
|
|
<P>
|
|
If you said <Foo>, that's what I expect it to output. However a close<P>
|
|
reading of CLtL2 shows that it is specified to print <|Foo|>. Similarly<P>
|
|
~A is specified to put on a package prefix if ~S would, when<P>
|
|
<A REL=DEFINITION HREF="../Body/v_pr_rda.htm#STprint-readablyST"><B>*PRINT-READABLY*</B></A> is T. ~D, etc. have the same problem, as does <A REL=DEFINITION HREF="../Body/f_wr_pr.htm#princ"><B>PRINC</B></A>.<P>
|
|
If <A REL=DEFINITION HREF="../Body/v_pr_rda.htm#STprint-readablyST"><B>*PRINT-READABLY*</B></A> is true, the binding of <A REL=DEFINITION HREF="../Body/v_pr_esc.htm#STprint-escapeST"><B>*PRINT-ESCAPE*</B></A> by these<P>
|
|
<A REL=DEFINITION HREF="../Body/f_format.htm#format"><B>FORMAT</B></A> operators and by <A REL=DEFINITION HREF="../Body/f_wr_pr.htm#princ"><B>PRINC</B></A> has no effect. <P>
|
|
<P>
|
|
See CLtL2 p.558 for the specification that *print-readably* overrides<P>
|
|
*print-escape*, CLtL2 p.583 for the specification that ~A only binds<P>
|
|
the printer control variables it is explicitly specified to bind,<P>
|
|
CLtL2 p.584 for the specification that ~A only binds *print-escape*<P>
|
|
(*print-readably* is not listed), and CLtL2 p.578 for the specification<P>
|
|
that princ is the same as write with :escape nil (but not :readably nil).<P>
|
|
<P>
|
|
Part of the problem appears to be that issue <A HREF="iss089.htm">DATA-IO</A> was written up<P>
|
|
without any reference to issue <A HREF="iss169.htm">FORMAT-PRETTY-PRINT</A>. I apologize.<P>
|
|
<P>
|
|
A related problem is that the following form<P>
|
|
<P>
|
|
(<A REL=DEFINITION HREF="../Body/s_let_l.htm#let"><B>let</B></A> ((<A REL=DEFINITION HREF="../Body/v_pr_cir.htm#STprint-circleST"><B>*print-circle*</B></A> t) (s "foo"))<P>
|
|
(<A REL=DEFINITION HREF="../Body/f_format.htm#format"><B>format</B></A> t "~A ~A(~A, ~A)"<P>
|
|
"moe" "bar" s s))<P>
|
|
<P>
|
|
is specified to print ``moe bar(#1=foo, #1#)'' rather than<P>
|
|
printing ``moe bar(foo, foo)''.<P>
|
|
<P>
|
|
I discovered these problems when Macintosh Common Lisp was changed to<P>
|
|
obey the letter of the law (as handed down in CLtL2) and a program of<P>
|
|
mine stopped working.<P>
|
|
<P>
|
|
<B>Proposal (PRINC-READABLY:FIX-BUGS):<P>
|
|
</B><P>
|
|
1. Specify that ~A binds <A REL=DEFINITION HREF="../Body/v_pr_rda.htm#STprint-readablyST"><B>*PRINT-READABLY*</B></A> to <A REL=DEFINITION HREF="../Body/a_nil.htm#nil"><B>NIL</B></A>.<P>
|
|
<P>
|
|
2. Specify the same for ~B, ~D, ~E, ~F, ~G, ~O, ~nR, ~X, and ~$ (which<P>
|
|
all turn into ~A for non-numeric arguments).<P>
|
|
<P>
|
|
3. Change the specification of (<A REL=DEFINITION HREF="../Body/f_wr_pr.htm#princ"><B>PRINC</B></A> object stream) as equivalent to <P>
|
|
<P>
|
|
(<A REL=DEFINITION HREF="../Body/f_wr_pr.htm#write"><B>WRITE</B></A> object :STREAM <A REL=DEFINITION HREF="../Body/t_stream.htm#stream"><B>stream</B></A> :ESCAPE <A REL=DEFINITION HREF="../Body/a_nil.htm#nil"><B>NIL</B></A>)<P>
|
|
<P>
|
|
to instead be equivalent to<P>
|
|
<P>
|
|
(<A REL=DEFINITION HREF="../Body/f_wr_pr.htm#write"><B>WRITE</B></A> object :STREAM <A REL=DEFINITION HREF="../Body/t_stream.htm#stream"><B>stream</B></A> :ESCAPE <A REL=DEFINITION HREF="../Body/a_nil.htm#nil"><B>NIL</B></A> :READABLY <A REL=DEFINITION HREF="../Body/a_nil.htm#nil"><B>NIL</B></A>)<P>
|
|
<P>
|
|
4. Change <A REL=DEFINITION HREF="../Body/f_wr_to_.htm#princ-to-string"><B>PRINC-TO-STRING</B></A> the same way.<P>
|
|
<P>
|
|
5. Change items 1 and 2 above also to bind <A REL=DEFINITION HREF="../Body/v_pr_cir.htm#STprint-circleST"><B>*PRINT-CIRCLE*</B></A> to <A REL=DEFINITION HREF="../Body/a_nil.htm#nil"><B>NIL</B></A>.<P>
|
|
Change items 3 and 4 above also to specify :CIRCLE <A REL=DEFINITION HREF="../Body/a_nil.htm#nil"><B>NIL</B></A>.<P>
|
|
This has been broken out into a separate numbered item to allow<P>
|
|
for the possibility of voting separately on this change.<P>
|
|
<P>
|
|
<B>Test Cases/Examples:<P>
|
|
</B><P>
|
|
See "Problem description."<P>
|
|
<P>
|
|
<B>Rationale:<P>
|
|
</B><P>
|
|
Proposal <A HREF="iss089.htm">DATA-IO:ADD-SUPPORT</A> was not intended to "break" ~A;<P>
|
|
this was an accident.<P>
|
|
<P>
|
|
~A and <A REL=DEFINITION HREF="../Body/f_wr_pr.htm#princ"><B>PRINC</B></A> are supposed to produce "human-readable" output, so<P>
|
|
they should not put on machine-readability decorations such as<P>
|
|
vertical bars, backslashes, package prefixes, and #1#.<P>
|
|
<P>
|
|
Point 5 means that ~A might not terminate when given a circular<P>
|
|
<A REL=DEFINITION HREF="../Body/f_docume.htm#structure"><B>structure</B></A> to print, even if <A REL=DEFINITION HREF="../Body/v_pr_cir.htm#STprint-circleST"><B>*PRINT-CIRCLE*</B></A> is true. The real problem<P>
|
|
here is that <A REL=DEFINITION HREF="../Body/v_pr_cir.htm#STprint-circleST"><B>*PRINT-CIRCLE*</B></A> is being used for two distinct purposes,<P>
|
|
detecting circular <A REL=DEFINITION HREF="../Body/f_docume.htm#structure"><B>structure</B></A> and detecting shared <A REL=DEFINITION HREF="../Body/f_docume.htm#structure"><B>structure</B></A>. We do<P>
|
|
not propose here to separate those two features (X3J13 voted<P>
|
|
down a proposal, PRINT-CIRCLE-SHARED:NEW-VARIABLE, to do so once before).<P>
|
|
<P>
|
|
<B>Current practice:<P>
|
|
</B><P>
|
|
Macintosh Common Lisp 2.0b3c4 does not implement this proposal; it<P>
|
|
implements exactly what CLtL2 specifies.<P>
|
|
<P>
|
|
Symbolics Genera 8.1 implements the proposal, or at least produces the<P>
|
|
proposed result for both test cases. This might be due to assuming<P>
|
|
that CLtL2 says something reasonable rather than reading the book with<P>
|
|
a magnifying glass.<P>
|
|
<P>
|
|
<B>Cost to Implementors:<P>
|
|
</B><P>
|
|
Implementing the changes should take very little effort.<P>
|
|
<P>
|
|
<B>Cost to Users:<P>
|
|
</B><P>
|
|
Conceivably existing code could depend on the specified behavior,<P>
|
|
but that seems quite unlikely, so the cost to users is probably minimal.<P>
|
|
<P>
|
|
<B>Cost of non-Adoption:<P>
|
|
</B><P>
|
|
A silly hassle for anyone using ~A and ~S to generate comments and<P>
|
|
code respectively, with <A REL=DEFINITION HREF="../Body/v_pr_rda.htm#STprint-readablyST"><B>*PRINT-READABLY*</B></A> and/or <A REL=DEFINITION HREF="../Body/v_pr_cir.htm#STprint-circleST"><B>*PRINT-CIRCLE*</B></A> turned<P>
|
|
on for the benefit of the ~S.<P>
|
|
<P>
|
|
<B>Benefits:<P>
|
|
</B><P>
|
|
Fewer silly hassles.<P>
|
|
<P>
|
|
<B>Aesthetics:<P>
|
|
</B><P>
|
|
Does <A REL=DEFINITION HREF="../Body/f_format.htm#format"><B>FORMAT</B></A> have aesthetics? If it does, I think the change improves<P>
|
|
them slightly.<P>
|
|
<P>
|
|
<B>Discussion:<P>
|
|
</B><P>
|
|
Dave Moon and Guy Steele were both surprised that CLtL2 says what it says.<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>
|