Subject: Re: Printing introduces newlines
From: (Rob Warnock)
Date: Thu, 13 Nov 2008 05:03:22 -0600
Newsgroups: comp.lang.lisp
Message-ID: <>
Thomas M. Hermann <> wrote:
| (Rob Warnock) wrote:
| > Since pretty-printing is typically a serious performance hog anyway
| > [see many past threads here on that issue], you'll generally want to
| > disable it if you're doing any sort of massive textual output not
| > intended for humans to read, such as HTML or JavaScript generation.
| This is what confused me about the question. I generally use FORMAT
| for output. What are the situations where one would rely on the Lisp
| printer for output other than working with the REPL?

FORMAT uses the pretty-printer internally if *PRINT-PRETTY* is true,
see CLHS 22.3.4 "FORMAT Printer Operations" (especially
"Tilde W: Write") and 22.3.5 "FORMAT Pretty Printer Operations",
etc., etc. So if you're using FORMAT you *are* using "the Lisp printer"

And, yes, that also implies that even FORMAT'd output can be sped up
tremendously by binding *PRINT-PRETTY* to NIL. [Well, assuming you
don't *need* the pretty-printing functions in that situation...]

The CLHS non-normative issue writeup FORMAT-PRETTY-PRINT:YES
clarified the relationship between the behavior of FORMAT and
various output functions such as PRINC & PRIN1. In particular,
FORMAT-PRETTY-PRINT:YES contains a handy reference of which
FORMAT controls bind which pretty-printer variables to what
values (though it's only partial, e.g., it doesn't mention
that ~:W binds *PRINT-PRETTY* to true). And this little bit
indirectly addresses your question above:

    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.

[Ditto FORMAT/~A and PRINC.]

Thus while most people do indeed use FORMAT most of the time, some
prefer to use PRINC, PRIN1, WRITE (plus keywords), etc., because
it feels "more Lisp-y" to them. And sometimes you just need to do
something that simply isn't convenient or even possible with FORMAT,
so you handle it by wrapping however complex CL code you need around
the functional printer interface PRINC/PRIN1/WRITE [and, in extremis,
WRITE-CHAR], possibly even using the PPRINT-xxx functions explicitly.

| The only one I had read about was writing out Lisp data to be
| read back in with READ.

See above re FORMAT/~S vs. PRIN1.


Rob Warnock			<>
627 26th Avenue			<URL:>
San Mateo, CA 94403		(650)572-2607