From: Kenny Tilton
Subject: pprint hunh?
Date: 
Message-ID: <lO8vf.26239$GW1.22209@news-wrt-01.rdc-nyc.rr.com>
This is a bit of a newby Q since I have never before needed or messed 
with pretty-printing. The CLHS 22.4.26 shows an example:

  (let ((*print-pretty* t))
    (progn (write '(let ((a 1) (b 2) (c 3)) (+ a b c))) nil)) ->
(LET ((A 1)
       (B 2)
       (C 3))
   (+ A B C))
   NIL

AllegroCL and Lispworks just give me:

CL-USER(14): (LET ((A 1) (B 2) (C 3)) (+ A B C))
NIL

wtf?

kt

From: Brian Downing
Subject: Re: pprint hunh?
Date: 
Message-ID: <IU8vf.707901$xm3.654004@attbi_s21>
In article <·····················@news-wrt-01.rdc-nyc.rr.com>,
Kenny Tilton  <·············@nyc.rr.com> wrote:
> This is a bit of a newby Q since I have never before needed or messed 
> with pretty-printing. The CLHS 22.4.26 shows an example:
> 
>   (let ((*print-pretty* t))
>     (progn (write '(let ((a 1) (b 2) (c 3)) (+ a b c))) nil)) ->
> (LET ((A 1)
>        (B 2)
>        (C 3))
>    (+ A B C))
>    NIL
> 
> AllegroCL and Lispworks just give me:
> 
> CL-USER(14): (LET ((A 1) (B 2) (C 3)) (+ A B C))
> NIL
> 
> wtf?

It won't break lines unless it has to to make it fit usually.

Try binding *PRINT-RIGHT-MARGIN* to something like 30 and try that
again.

-bcd
-- 
*** Brian Downing <bdowning at lavos dot net> 
From: Kenny Tilton
Subject: Re: pprint hunh?
Date: 
Message-ID: <iLdvf.37750$i1.18089@news-wrt-01.rdc-nyc.rr.com>
Brian Downing wrote:
> In article <·····················@news-wrt-01.rdc-nyc.rr.com>,
> Kenny Tilton  <·············@nyc.rr.com> wrote:
> 
>>This is a bit of a newby Q since I have never before needed or messed 
>>with pretty-printing. The CLHS 22.4.26 shows an example:
>>
>>  (let ((*print-pretty* t))
>>    (progn (write '(let ((a 1) (b 2) (c 3)) (+ a b c))) nil)) ->
>>(LET ((A 1)
>>       (B 2)
>>       (C 3))
>>   (+ A B C))
>>   NIL
>>
>>AllegroCL and Lispworks just give me:
>>
>>CL-USER(14): (LET ((A 1) (B 2) (C 3)) (+ A B C))
>>NIL
>>
>>wtf?
> 
> 
> It won't break lines unless it has to to make it fit usually.
> 
> Try binding *PRINT-RIGHT-MARGIN* to something like 30 and try that
> again.

Thx, I was trying *print-miser-width*. That seems to have no effect, tho 
maybe I misunderstood the effect that was supposed to have.

kt
From: Brian Downing
Subject: Re: pprint hunh?
Date: 
Message-ID: <jHevf.467622$084.229640@attbi_s22>
In article <····················@news-wrt-01.rdc-nyc.rr.com>,
Kenny Tilton  <·············@nyc.rr.com> wrote:
> Thx, I was trying *print-miser-width*. That seems to have no effect, tho 
> maybe I misunderstood the effect that was supposed to have.

AFAIK, after output has proceeded to the right of *PRINT-MISER-WIDTH*,
pretty-printers should be "miserly" with horizontal space.  I think what
this boils down to is that (pprint-newline :miser) will produce a
newline at that point, and some other small behaviors change.

If it didn't do anything likely there were no miserly newlines used,
which makes sense, since what you'd have there would probably be a :fill
newline.

http://www.lispworks.com/reference/HyperSpec/Body/f_ppr_nl.htm

(Note that this is really me talking about of my ass - read the XP paper
to find out what really might be going on.)

-bcd
-- 
*** Brian Downing <bdowning at lavos dot net> 
From: Kenny Tilton
Subject: Re: pprint hunh?
Date: 
Message-ID: <xNovf.38040$i1.28576@news-wrt-01.rdc-nyc.rr.com>
Brian Downing wrote:
> In article <····················@news-wrt-01.rdc-nyc.rr.com>,
> Kenny Tilton  <·············@nyc.rr.com> wrote:
> 
>>Thx, I was trying *print-miser-width*. That seems to have no effect, tho 
>>maybe I misunderstood the effect that was supposed to have.
> 
> 
> AFAIK, after output has proceeded to the right of *PRINT-MISER-WIDTH*,
> pretty-printers should be "miserly" with horizontal space.  I think what
> this boils down to is that (pprint-newline :miser) will produce a
> newline at that point, and some other small behaviors change.
> 
> If it didn't do anything likely there were no miserly newlines used,
> which makes sense, since what you'd have there would probably be a :fill
> newline.
> 
> http://www.lispworks.com/reference/HyperSpec/Body/f_ppr_nl.htm

Ah, missed that section. very nice. It made me laugh at how far the 
langues du jour have to go to catch up with Lisp -- even pretty-printing 
is well-defined and customizable. Sick. Now if only I could understand 
the doc:

"The section immediately containing a conditional newline is the 
shortest section that contains the conditional newline in question. In 
the next figure, the first conditional newline is immediately contained 
in the section marked with 0's, the second and third conditional 
newlines are immediately contained in the section before the fourth 
conditional newline, and the fourth conditional newline is immediately 
contained in the section after the first conditional newline.

  <-1---<--<--2---3->--4-->->
  000000000000000000000000000
  11 111111111111111111111111
            22 222
               333 3333
         44444444444444 44444"

wtf? I should check my records to see if English is /my/ native 
language. And they went to so much trouble to make it clear!


kt
From: Gareth McCaughan
Subject: Re: pprint hunh?
Date: 
Message-ID: <87oe2noa8v.fsf@g.mccaughan.ntlworld.com>
Kenny Tilton wrote:

> Now if only I could understand the doc:
> 
> "The section immediately containing a conditional newline is the
> shortest section that contains the conditional newline in question. In
> the next figure, the first conditional newline is immediately
> contained in the section marked with 0's, the second and third
> conditional newlines are immediately contained in the section before
> the fourth conditional newline, and the fourth conditional newline is
> immediately contained in the section after the first conditional
> newline.
> 
>   <-1---<--<--2---3->--4-->->
>   000000000000000000000000000
>   11 111111111111111111111111
>             22 222
>                333 3333
>          44444444444444 44444"
> 
> wtf? I should check my records to see if English is /my/ native
> language. And they went to so much trouble to make it clear!

I think you're expecting it to be saying something
interesting and subtle, which it isn't. :-)

There are things called "sections". This term is defined by
the foregoing matter: the whole output is a section, and
for each conditional newline there's a "section before"
and a "section after".

The purpose of the extract you quoted is to define
another term, the "section immediately containing"
each conditional newline, and to illustrate it with
some examples.

* Definition of "immediately containing":

So, pick one of those conditional newlines. It lies
within at least one section (the whole output); perhaps
it lies within some others too. Call the *shortest*
such section the one "immediately containing" that
conditional newline.

    (The existence of a shortest one follows
    from the fact that any two sections are
    either disjoint or nested.)

* Illustration:

In the figure, each section is indicated by a block
of identical digits. There's one section labelled 0
(the whole output) and two each labelled 1,2,3,4
(the sections before and after the conditional newlines
labelled 1,2,3,4).

The only section containing conditional newline 1
is the whole output, so that's its immediately-containing
section.

The sections containing conditional newline 2 are
0, after-1 and before-4. The last of these is the
shortest, so that's the "section immediately
containing conditional newline 2".

The sections containing conditional newline 3
are 0, after-1 and before-4 (same as for 2). So
its immediately containing section, too, is
before-4.

The sections containing conditional newline 4
are 0 and after-1 only. So the section immediately
containing conditional newline 4 is after-1.

-- 
Gareth McCaughan
.sig under construc
From: Espen Vestre
Subject: Re: pprint hunh?
Date: 
Message-ID: <m1k6de95gs.fsf@mordac.netfonds.no>
Kenny Tilton <·············@nyc.rr.com> writes:

> AllegroCL and Lispworks just give me:
> 
> CL-USER(14): (LET ((A 1) (B 2) (C 3)) (+ A B C))
> NIL
> 
> wtf?

I think the pretty-printer thinks one-liners is the prettiest thing
in the world ;)

If you give it a similar but wordier form, it will print as you
expected:

CL-USER 127 > (let ((*print-pretty* t))(write '(let ((alpha 100000000000000) (beta 200000000000) (gamma 3000000000)) (+ abrakadabra foobar gazonk))) nil)
(LET ((ALPHA 100000000000000) (BETA 200000000000) (GAMMA 3000000000))
  (+ ABRAKADABRA FOOBAR GAZONK))

I do a lot of code-printing with pprint, since I do s-exp-level diffs
of source code to create patches, and although the code is mostly 
perfectly readable, I'm sometimes put off by the printing style of
the pretty printer (LW in my case). In particular (and you can see that above)
I dislike multiple LET-bindings on one line. Another thing I really
dislike, is that it seems to assume that I always want the lambda list
of a method on the next line. Here's a really ugly example:

(defmethod cell-layout-description
  ((tab table) i j)
  (with-slots (cells dimensions) tab
    (let ((x-dim (first dimensions)) (y-dim (second dimensions)))
      (when (and (< i x-dim) (< j y-dim)) (aref cells i j)))))

-- 
  (espen)
From: Paolo Amoroso
Subject: Re: pprint hunh?
Date: 
Message-ID: <87k6dezcqt.fsf@plato.moon.paoloamoroso.it>
Kenny Tilton <·············@nyc.rr.com> writes:

> This is a bit of a newby Q since I have never before needed or messed
> with pretty-printing. The CLHS 22.4.26 shows an example:

Likewise :)  But this is a useful resource on the pretty printer:

  Some Useful Lisp Algorithms: Part 2
  http://www.merl.com/publications/TR1993-017/


Paolo
-- 
Why Lisp? http://wiki.alu.org/RtL%20Highlight%20Film
The Common Lisp Directory: http://www.cl-user.com