From: Vladimir Zolotykh
Subject: FORMAT ~<·····@> PUZZLE
Date: 
Message-ID: <dmhsoq$unf$1@dcs.eurocom.od.ua>
The following simple function
(defun foo (n)
   (let* ((*print-right-margin* n)
	 (a '("Whan" "you're" "lost" "in" "the" "Wild,"
	      "and" "you're" "scared" "as" "a" "child,"
	      "And" "Death" "looks" "you" "bang"
	      "in" "the" "eye,")))
     (format t ··@<~{~A~^ ····@>" a)))
if called (cl-user::foo 10)
prints one word at a line. So does (cl-user::foo 20),30,40.
And only (cl-user::foo 50) prints

Whan you're lost in the Wild, and you're scared
as a child, And Death looks you bang in the eye,

What's wrong? I'd expect that calls with n less that 50 (e.g 20, 30, 40)
would also print _formatted_ paragraph. Where was I wrong?

-- 
Vladimir Zolotykh

From: Geoffrey Summerhayes
Subject: Re: FORMAT ~<·····@> PUZZLE
Date: 
Message-ID: <1133297939.892181.212650@g14g2000cwa.googlegroups.com>
Vladimir Zolotykh wrote:

> What's wrong? I'd expect that calls with n less that 50 (e.g 20, 30, 40)
> would also print _formatted_ paragraph. Where was I wrong?

Try:

(format t ··@<~{~A~^ ·······@>" a)))

CL-USER 2 > (foo 10)
Whan
you're
lost in
the Wild,
and
you're
scared as
a child,
And Death
looks you
bang in
the eye,
NIL

CL-USER 3 > (foo 20)
Whan you're lost in
the Wild, and
you're scared as a
child, And Death
looks you bang in
the eye,
NIL

CL-USER 4 > (foo 30)
Whan you're lost in the Wild,
and you're scared as a child,
And Death looks you bang in
the eye,
NIL

CL-USER 5 > (foo 40)
Whan you're lost in the Wild, and
you're scared as a child, And Death
looks you bang in the eye,
NIL

--
Geoff
From: Peter Seibel
Subject: Re: FORMAT ~<·····@> PUZZLE
Date: 
Message-ID: <m2mzjnupmh.fsf@gigamonkeys.com>
"Geoffrey Summerhayes" <·······@hotmail.com> writes:

> Vladimir Zolotykh wrote:
>
>> What's wrong? I'd expect that calls with n less that 50 (e.g 20, 30, 40)
>> would also print _formatted_ paragraph. Where was I wrong?
>
> Try:
>
> (format t ··@<~{~A~^ ·······@>" a)))
>
> CL-USER 2 > (foo 10)
> Whan
> you're
> lost in
> the Wild,
> and
> you're
> scared as
> a child,
> And Death
> looks you
> bang in
> the eye,
> NIL

What's the value of *print-miser-width*? Because if I have it set to
something non NIL that doesn't help. In fact it makes it worse (see below).

From the docs for pprint-newline:

Talking about :fill which is what you get with ~:_

  "if miser style is in effect, fill-style conditional newlines act
  like linear-style conditional newlines."

And talking about :linear style:

  "line breaks are either inserted at every linear-style conditional
  newline in a logical block or at none of them."

Which is what I see when the thing is printed in miser-mode:

  CL-USER> *print-miser-width*
  40
  CL-USER> (foo 10)
  Whan

  you're

  lost

  in

  the

  Wild,

  and

  you're

  scared

  as

  a

  child,

  And

  Death

  looks

  you

  bang

  in

  the

  eye,
  NIL
  CL-USER> 
-- 
Peter Seibel           * ·····@gigamonkeys.com
Gigamonkeys Consulting * http://www.gigamonkeys.com/
Practical Common Lisp  * http://www.gigamonkeys.com/book/
From: Geoffrey Summerhayes
Subject: Re: FORMAT ~<·····@> PUZZLE
Date: 
Message-ID: <1133302607.784637.257330@o13g2000cwo.googlegroups.com>
Peter Seibel wrote:
> "Geoffrey Summerhayes" <·······@hotmail.com> writes:
>> Vladimir Zolotykh wrote:
>>>
>>> What's wrong? I'd expect that calls with n less that 50 (e.g 20, 30, 40)
>>> would also print _formatted_ paragraph. Where was I wrong?
>>
>> Try:
>> (format t ··@<~{~A~^ ·······@>" a)))
> What's the value of *print-miser-width*? Because if I have it set to
> something non NIL that doesn't help. In fact it makes it worse (see below).

Realized after posting I should have included that...

(defun foo (n)
   (let ((*print-right-margin* n)
         (*print-miser-width* nil)
         (a '("Whan" "you're" "lost" "in" "the" "Wild,"
              "and" "you're" "scared" "as" "a" "child,"
              "And" "Death" "looks" "you" "bang"
              "in" "the" "eye,")))
     (format t ··@<~{~A~^ ·······@>" a)))

--
Geoff
From: Peter Seibel
Subject: Re: FORMAT ~<·····@> PUZZLE
Date: 
Message-ID: <m2irubum5v.fsf@gigamonkeys.com>
"Geoffrey Summerhayes" <·······@hotmail.com> writes:

> Peter Seibel wrote:
>> "Geoffrey Summerhayes" <·······@hotmail.com> writes:
>>> Vladimir Zolotykh wrote:
>>>>
>>>> What's wrong? I'd expect that calls with n less that 50 (e.g 20, 30, 40)
>>>> would also print _formatted_ paragraph. Where was I wrong?
>>>
>>> Try:
>>> (format t ··@<~{~A~^ ·······@>" a)))
>> What's the value of *print-miser-width*? Because if I have it set to
>> something non NIL that doesn't help. In fact it makes it worse (see below).
>
> Realized after posting I should have included that...
>
> (defun foo (n)
>    (let ((*print-right-margin* n)
>          (*print-miser-width* nil)
>          (a '("Whan" "you're" "lost" "in" "the" "Wild,"
>               "and" "you're" "scared" "as" "a" "child,"
>               "And" "Death" "looks" "you" "bang"
>               "in" "the" "eye,")))
>      (format t ··@<~{~A~^ ·······@>" a)))

So it seems to me that with *PRINT-MISER-WIDTH* set to NIL you don't
need the ~:_ at all.

-Peter

-- 
Peter Seibel           * ·····@gigamonkeys.com
Gigamonkeys Consulting * http://www.gigamonkeys.com/
Practical Common Lisp  * http://www.gigamonkeys.com/book/
From: Geoffrey Summerhayes
Subject: Re: FORMAT ~<·····@> PUZZLE
Date: 
Message-ID: <t7djf.3632$Et5.208106@news20.bellglobal.com>
"Peter Seibel" <·····@gigamonkeys.com> wrote in message ···················@gigamonkeys.com...
> "Geoffrey Summerhayes" <·······@hotmail.com> writes:
>> Realized after posting I should have included that...
>>
>> (defun foo (n)
>>    (let ((*print-right-margin* n)
>>          (*print-miser-width* nil)
>>          (a '("Whan" "you're" "lost" "in" "the" "Wild,"
>>               "and" "you're" "scared" "as" "a" "child,"
>>               "And" "Death" "looks" "you" "bang"
>>               "in" "the" "eye,")))
>>      (format t ··@<~{~A~^ ·······@>" a)))
>
> So it seems to me that with *PRINT-MISER-WIDTH* set to NIL you don't
> need the ~:_ at all.

From the CLHS:

  If ··@> is used to terminate the directive (i.e., ~<·····@>),
  then a fill-style conditional newline is automatically
  inserted after each group of blanks immediately contained
  in the body (except for blanks after a <Newline> directive).

Unfortunately there appears to be more than one way of
interpreting 'immediately'. Most Lisps, AFAIK, take it
to mean all spaces found between ~< and ··@> but LW
appears to take it as 'top-level' spaces leaving the
spaces between the ~{ ~} unchanged. I tested on LW
Personal 4.4.6 Whether it's a bug or not, I'll leave
to the language lawyers.

--
Geoff
From: John Thingstad
Subject: Re: FORMAT ~<·····@> PUZZLE
Date: 
Message-ID: <op.s0120ow1pqzri1@mjolner.upc.no>
On Wed, 30 Nov 2005 05:35:22 +0100, Geoffrey Summerhayes  
<·······@NhOoStPmAaMil.com> wrote:

>
> "Peter Seibel" <·····@gigamonkeys.com> wrote in message  
> ···················@gigamonkeys.com...
>> "Geoffrey Summerhayes" <·······@hotmail.com> writes:
>>> Realized after posting I should have included that...
>>>
>>> (defun foo (n)
>>>    (let ((*print-right-margin* n)
>>>          (*print-miser-width* nil)
>>>          (a '("Whan" "you're" "lost" "in" "the" "Wild,"
>>>               "and" "you're" "scared" "as" "a" "child,"
>>>               "And" "Death" "looks" "you" "bang"
>>>               "in" "the" "eye,")))
>>>      (format t ··@<~{~A~^ ·······@>" a)))
>>
>> So it seems to me that with *PRINT-MISER-WIDTH* set to NIL you don't
>> need the ~:_ at all.
>
> From the CLHS:
>
>   If ··@> is used to terminate the directive (i.e., ~<·····@>),
>   then a fill-style conditional newline is automatically
>   inserted after each group of blanks immediately contained
>   in the body (except for blanks after a <Newline> directive).
>
> Unfortunately there appears to be more than one way of
> interpreting 'immediately'. Most Lisps, AFAIK, take it
> to mean all spaces found between ~< and ··@> but LW
> appears to take it as 'top-level' spaces leaving the
> spaces between the ~{ ~} unchanged. I tested on LW
> Personal 4.4.6 Whether it's a bug or not, I'll leave
> to the language lawyers.
>
> --
> Geoff
>
>

Immediate seems pretty definate to me.
I'll contact LispWorks and see if we can't get this fixed
by the next version.

-- 
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
From: Geoffrey Summerhayes
Subject: Re: FORMAT ~<·····@> PUZZLE
Date: 
Message-ID: <uzyjf.4527$Et5.280484@news20.bellglobal.com>
"John Thingstad" <··············@chello.no> wrote in message ······················@mjolner.upc.no...
>
> Immediate seems pretty definate to me.
> I'll contact LispWorks and see if we can't get this fixed
> by the next version.
>

I don't know, what about nested blocks?
Should "~<...~<...~:>·····@>" be equivalent
to "~<...~<·····@>·····@>"?

--
Geoff
From: Peter Seibel
Subject: Re: FORMAT ~<·····@> PUZZLE
Date: 
Message-ID: <m27jar76mm.fsf@gigamonkeys.com>
Vladimir Zolotykh <······@eurocom.od.ua> writes:

> The following simple function
> (defun foo (n)
>    (let* ((*print-right-margin* n)
> 	 (a '("Whan" "you're" "lost" "in" "the" "Wild,"
> 	      "and" "you're" "scared" "as" "a" "child,"
> 	      "And" "Death" "looks" "you" "bang"
> 	      "in" "the" "eye,")))
>      (format t ··@<~{~A~^ ····@>" a)))
> if called (cl-user::foo 10)
> prints one word at a line. So does (cl-user::foo 20),30,40.
> And only (cl-user::foo 50) prints
>
> Whan you're lost in the Wild, and you're scared
> as a child, And Death looks you bang in the eye,
>
> What's wrong? I'd expect that calls with n less that 50 (e.g 20, 30, 40)
> would also print _formatted_ paragraph. Where was I wrong?

I'm sure I don't actually understand this but poking around a bit I
came up with this:

  (defun foo (n)
    (let ((*print-right-margin* n)
          (*print-miser-width* nil)
          (a '("Whan" "you're" "lost" "in" "the" "Wild,"
               "and" "you're" "scared" "as" "a" "child,"
               "And" "Death" "looks" "you" "bang"
               "in" "the" "eye,")))
      (format t ··@<~;~{~A~^ ······@>" a)))

-Peter

-- 
Peter Seibel           * ·····@gigamonkeys.com
Gigamonkeys Consulting * http://www.gigamonkeys.com/
Practical Common Lisp  * http://www.gigamonkeys.com/book/
From: Vladimir Zolotykh
Subject: Re: FORMAT ~<·····@> PUZZLE
Date: 
Message-ID: <dmi1hr$re6$1@dcs.eurocom.od.ua>
Peter Seibel wrote:
> Vladimir Zolotykh <······@eurocom.od.ua> writes:
> 
> 
>>The following simple function
>>(defun foo (n)
>>   (let* ((*print-right-margin* n)
>>	 (a '("Whan" "you're" "lost" "in" "the" "Wild,"
>>	      "and" "you're" "scared" "as" "a" "child,"
>>	      "And" "Death" "looks" "you" "bang"
>>	      "in" "the" "eye,")))
>>     (format t ··@<~{~A~^ ····@>" a)))
>>if called (cl-user::foo 10)
>>prints one word at a line. So does (cl-user::foo 20),30,40.
>>And only (cl-user::foo 50) prints
>>
>>Whan you're lost in the Wild, and you're scared
>>as a child, And Death looks you bang in the eye,
>>
>>What's wrong? I'd expect that calls with n less that 50 (e.g 20, 30, 40)
>>would also print _formatted_ paragraph. Where was I wrong?
> 
> 
> I'm sure I don't actually understand this but poking around a bit I
> came up with this:
> 
>   (defun foo (n)
>     (let ((*print-right-margin* n)
>           (*print-miser-width* nil)
>           (a '("Whan" "you're" "lost" "in" "the" "Wild,"
>                "and" "you're" "scared" "as" "a" "child,"
>                "And" "Death" "looks" "you" "bang"
>                "in" "the" "eye,")))
>       (format t ··@<~;~{~A~^ ······@>" a)))
Yes, it's kikd of a mistery.
I sure understand less then nothing in the HyperSec section for
*PRINT-MISER-WIDTH*, what's the "miser style" of output mentioned there?

> 
> -Peter
> 


-- 
Vladimir Zolotykh
From: Peter Seibel
Subject: Re: FORMAT ~<·····@> PUZZLE
Date: 
Message-ID: <m23blf6w9q.fsf@gigamonkeys.com>
Vladimir Zolotykh <······@eurocom.od.ua> writes:

> Peter Seibel wrote:
>> Vladimir Zolotykh <······@eurocom.od.ua> writes:
>> 
>>>The following simple function
>>>(defun foo (n)
>>>   (let* ((*print-right-margin* n)
>>>	 (a '("Whan" "you're" "lost" "in" "the" "Wild,"
>>>	      "and" "you're" "scared" "as" "a" "child,"
>>>	      "And" "Death" "looks" "you" "bang"
>>>	      "in" "the" "eye,")))
>>>     (format t ··@<~{~A~^ ····@>" a)))
>>>if called (cl-user::foo 10)
>>>prints one word at a line. So does (cl-user::foo 20),30,40.
>>>And only (cl-user::foo 50) prints
>>>
>>>Whan you're lost in the Wild, and you're scared
>>>as a child, And Death looks you bang in the eye,
>>>
>>>What's wrong? I'd expect that calls with n less that 50 (e.g 20, 30, 40)
>>>would also print _formatted_ paragraph. Where was I wrong?
>> I'm sure I don't actually understand this but poking around a bit I
>> came up with this:
>>   (defun foo (n)
>>     (let ((*print-right-margin* n)
>>           (*print-miser-width* nil)
>>           (a '("Whan" "you're" "lost" "in" "the" "Wild,"
>>                "and" "you're" "scared" "as" "a" "child,"
>>                "And" "Death" "looks" "you" "bang"
>>                "in" "the" "eye,")))
>>       (format t ··@<~;~{~A~^ ······@>" a)))

> Yes, it's kikd of a mistery.  I sure understand less then nothing in
> the HyperSec section for *PRINT-MISER-WIDTH*, what's the "miser
> style" of output mentioned there?

So my vague recollection from reading one of the original papers about
the XP pretty printer (upon which the CL pretty printer is based) is
that the miser-width controls what happens when there's less than
*print-miser-width* columns left until the right margin. The point is
that after you've printed a bunch of levels of stuff (say when you're
printing s-expressions) and the natural indentation has pushed things
over to the right, it can't possibly print things at full width so it
switches over to "miser mode" which is miserly with horizontal space,
i.e. it breaks lines more often.

In both Allegro and OpenMCL (running in SLIME which maybe has
something to do with it) *PRINT-MISER-WIDTH* was set to 40. So when
you set *PRINT-RIGHT-MARGIN* to 40 or less the number of columns left
was less than *PRINT-MISER-WIDTH* so it switches to miser mode and
breaks the lines a lot more than would otherwise be required. But when
*PRINT-RIGHT-MARGIN* was 50 it was greater than *PRINT-MISER-WIDTH*
and, since you start printing in column 0, there was enough space to
print in normal mode.

Anyway, that's how I understand it upon a bit of reflection.

-Peter

-- 
Peter Seibel           * ·····@gigamonkeys.com
Gigamonkeys Consulting * http://www.gigamonkeys.com/
Practical Common Lisp  * http://www.gigamonkeys.com/book/
From: Vladimir Zolotykh
Subject: Re: FORMAT ~<·····@> PUZZLE
Date: 
Message-ID: <dmk1de$vqa$1@dcs.eurocom.od.ua>
Peter Seibel wrote:
> 
> So my vague recollection from reading one of the original papers about
> the XP pretty printer (upon which the CL pretty printer is based) is
> that the miser-width controls what happens when there's less than
> *print-miser-width* columns left until the right margin. The point is
> that after you've printed a bunch of levels of stuff (say when you're
> printing s-expressions) and the natural indentation has pushed things
> over to the right, it can't possibly print things at full width so it
> switches over to "miser mode" which is miserly with horizontal space,
> i.e. it breaks lines more often.
Could we say 'it breaks lines as often as possible' e.g. one unbreakable
item a line ? Or in other words read "miser mode" as one item at a line?
> 
> In both Allegro and OpenMCL (running in SLIME which maybe has
> something to do with it) *PRINT-MISER-WIDTH* was set to 40. So when
> you set *PRINT-RIGHT-MARGIN* to 40 or less the number of columns left
> was less than *PRINT-MISER-WIDTH* so it switches to miser mode and
> breaks the lines a lot more than would otherwise be required. But when
> *PRINT-RIGHT-MARGIN* was 50 it was greater than *PRINT-MISER-WIDTH*
> and, since you start printing in column 0, there was enough space to
> print in normal mode.
> 
> Anyway, that's how I understand it upon a bit of reflection.
> 
> -Peter
> 


-- 
Vladimir Zolotykh
From: Harald Hanche-Olsen
Subject: Re: FORMAT ~<·····@> PUZZLE
Date: 
Message-ID: <pcozmnno066.fsf@shuttle.math.ntnu.no>
+ Vladimir Zolotykh <······@eurocom.od.ua>:

| The following simple function [...]
| prints one word at a line. So does (cl-user::foo 20),30,40.

With which Lisp?  I am not seeing what you describe using SBCL.

-- 
* Harald Hanche-Olsen     <URL:http://www.math.ntnu.no/~hanche/>
- Debating gives most of us much more psychological satisfaction
  than thinking does: but it deprives us of whatever chance there is
  of getting closer to the truth.  -- C.P. Snow