From: Tim Moore
Subject: Character arguments to format directives
Date: 
Message-ID: <99cbi8$ets$0@216.39.145.192>
Howdy,

In 22.3 of CLHS, A directive is described thus:

A directive consists of a tilde, optional prefix parameters separated by
commas, optional colon and at-sign modifiers, and a single character 
indicating what kind of directive this is. There is no required ordering
between the at-sign and colon modifier. The case of the directive
character is ignored. Prefix parameters are notated as signed (sign is
optional) decimal numbers, or as a single-quote followed by a character.
For example, ~5,'0d can be used to print an integer in decimal radix in
five columns with leading zeros, or ~5,'*d to get leading asterisks. 

In 22.3.2.1 there's an example:
(format nil "~19,0,' ,4:B" 3333) =>  "0000 1101 0000 0101"

Is the intent to treat single digits as character arguments, or is this
example in error?  Two implementations that I know of (CMUCL and
LispWorks) either spew garbage or signal an error for this example.

Thanks,
Tim

From: Espen Vestre
Subject: Re: Character arguments to format directives
Date: 
Message-ID: <w6elvq6wuz.fsf@wallace.ws.nextra.no>
Tim Moore <·····@herschel.bricoworks.com> writes:

> In 22.3.2.1 there's an example:
> (format nil "~19,0,' ,4:B" 3333) =>  "0000 1101 0000 0101"

the example is wrong, the padchar 0 must be quoted.

> Is the intent to treat single digits as character arguments, or is this
> example in error?  Two implementations that I know of (CMUCL and
> LispWorks) either spew garbage or signal an error for this example.

Hmm, I still get funny results with lispworks:

CL-USER 36 > (format nil "~19,'0,' ,4:B" 3333)
"000001101 0000 0101"

I think this must be a lispworks bug.
-- 
  (espen)
From: Christophe Rhodes
Subject: Re: Character arguments to format directives
Date: 
Message-ID: <sqhf0mxjqw.fsf@lambda.jesus.cam.ac.uk>
Espen Vestre <·····@*do-not-spam-me*.vestre.net> writes:

> Tim Moore <·····@herschel.bricoworks.com> writes:
> 
> > In 22.3.2.1 there's an example:
> > (format nil "~19,0,' ,4:B" 3333) =>  "0000 1101 0000 0101"
> 
> the example is wrong, the padchar 0 must be quoted.
> 
> > Is the intent to treat single digits as character arguments, or is this
> > example in error?  Two implementations that I know of (CMUCL and
> > LispWorks) either spew garbage or signal an error for this example.
> 
> Hmm, I still get funny results with lispworks:
> 
> CL-USER 36 > (format nil "~19,'0,' ,4:B" 3333)
> "000001101 0000 0101"
> 
> I think this must be a lispworks bug.

Well, not just a lispworks bug:

CLISP:
[1]> (format nil "~19,'0,' ,4:B" 3333)
"000001101 0000 0101"

CMUCL:
* (format nil "~19,'0,' ,4:B" 3333)

"000001101 0000 0101"

Hmm.

Christophe
-- 
Jesus College, Cambridge, CB5 8BL                           +44 1223 524 842
(FORMAT T "(·@{~w ········@{~w~^ ~})" 'FORMAT T "(·@{~w ········@{~w~^ ~})")
From: Espen Vestre
Subject: Re: Character arguments to format directives
Date: 
Message-ID: <w6snk65f5u.fsf@wallace.ws.nextra.no>
Christophe Rhodes <·····@cam.ac.uk> writes:

> Well, not just a lispworks bug:
> 
> CLISP:
> [1]> (format nil "~19,'0,' ,4:B" 3333)
> "000001101 0000 0101"
> 
> CMUCL:
> * (format nil "~19,'0,' ,4:B" 3333)
> 
> "000001101 0000 0101"
> 
> Hmm.

I think there's a potential problem in the standard here.

I.e., if I do

CL-USER 55 > (format nil "~30,' ,',,3:D" 33333333)
"                    33,333,333"

I'm happy that I don't get this:

CL-USER 55 > (format nil "~30,' ,',,3:D" 33333333)
"  ,   ,   ,   ,   , 33,333,333"

On the other hand, I would probably want:

CL-USER 55 > (format nil "~30,'0,',,3:D" 33333333)
"00,000,000,000,000,033,333,333"

Hmm indeed! 
-- 
  (espen)
From: Christophe Rhodes
Subject: Re: Character arguments to format directives
Date: 
Message-ID: <sqd7baxbsk.fsf@lambda.jesus.cam.ac.uk>
Espen Vestre <·····@*do-not-spam-me*.vestre.net> writes:

> Christophe Rhodes <·····@cam.ac.uk> writes:
> 
> > * (format nil "~19,'0,' ,4:B" 3333)
> > 
> > "000001101 0000 0101"
> > 
> > Hmm.
> 
> I think there's a potential problem in the standard here.
> 
> I.e., if I do
> 
> CL-USER 55 > (format nil "~30,' ,',,3:D" 33333333)
> "                    33,333,333"
> 
> I'm happy that I don't get this:
> 
> CL-USER 55 > (format nil "~30,' ,',,3:D" 33333333)
> "  ,   ,   ,   ,   , 33,333,333"
> 
> On the other hand, I would probably want:
> 
> CL-USER 55 > (format nil "~30,'0,',,3:D" 33333333)
> "00,000,000,000,000,033,333,333"
> 
> Hmm indeed! 

Right. So let's get our thinking caps on. The fundamental point seems
to be that people expect something that isn't specified by the
standard in a special case. It would seem to me reasonable to request
that a padchar of #\0 be treated specially with respect to grouping,
as it has a different meaning from (effectively-)whitespace-like
padding (such as #\Space or #\., say).

So, if we have a padchar of #\0, we ask that the comma apply also to
the padding? Is that what people want/expect?

Christophe
-- 
Jesus College, Cambridge, CB5 8BL                           +44 1223 524 842
(FORMAT T "(·@{~w ········@{~w~^ ~})" 'FORMAT T "(·@{~w ········@{~w~^ ~})")
From: Espen Vestre
Subject: Re: Character arguments to format directives
Date: 
Message-ID: <w666h2yq4y.fsf@wallace.ws.nextra.no>
Christophe Rhodes <·····@cam.ac.uk> writes:

> So, if we have a padchar of #\0, we ask that the comma apply also to
> the padding? Is that what people want/expect?

something like that, yes, but I would like that to be a matter of
specifying arguments to the format directive and not leave to the
implementation to guess that I want a different behavoiur with #\0
than with #\Space...
-- 
  (espen)
From: Frode Vatvedt Fjeld
Subject: Re: Character arguments to format directives
Date: 
Message-ID: <2hu24ldh8a.fsf@dslab7.cs.uit.no>
Christophe Rhodes <·····@cam.ac.uk> writes:

> So, if we have a padchar of #\0, we ask that the comma apply also to
> the padding? Is that what people want/expect?

No, I think all padchars should be treated equally, and that grouping
should apply to padding (as the spec currently implies). It would
perhaps be preferrable to have another boolean argument to control
whether grouping should apply to the padding, but then the spec and
the syntax would have to be extended.

-- 
Frode Vatvedt Fjeld
From: Christophe Rhodes
Subject: Re: Character arguments to format directives
Date: 
Message-ID: <sq8zlxyi4e.fsf@lambda.jesus.cam.ac.uk>
Frode Vatvedt Fjeld <······@acm.org> writes:

> Christophe Rhodes <·····@cam.ac.uk> writes:
> 
> > So, if we have a padchar of #\0, we ask that the comma apply also to
> > the padding? Is that what people want/expect?
> 
> No, I think all padchars should be treated equally, and that grouping
> should apply to padding (as the spec currently implies). It would
> perhaps be preferrable to have another boolean argument to control
> whether grouping should apply to the padding, but then the spec and
> the syntax would have to be extended.

Sorry? You mean you want (to take Espen's example):

CL-USER 55 > (format nil "~30,' ,',,3:D" 33333333)
"  ,   ,   ,   ,   , 33,333,333"

? Or am I missing something?

Christophe
-- 
Jesus College, Cambridge, CB5 8BL                           +44 1223 524 842
(FORMAT T "(·@{~w ········@{~w~^ ~})" 'FORMAT T "(·@{~w ········@{~w~^ ~})")
From: Frode Vatvedt Fjeld
Subject: Re: Character arguments to format directives
Date: 
Message-ID: <2hd7b9ddp9.fsf@dslab7.cs.uit.no>
Christophe Rhodes <·····@cam.ac.uk> writes:

> Sorry? You mean you want (to take Espen's example):
> 
> CL-USER 55 > (format nil "~30,' ,',,3:D" 33333333)
> "  ,   ,   ,   ,   , 33,333,333"

Yes, although in this case you'll obviously want to somehow do the
padding differently (which can be inconvenient but not nearly as
inconvenient as doing your own grouping padding when that's what you
need), or you want that extra boolean argument to switch off grouping
padding.

-- 
Frode Vatvedt Fjeld
From: Frode Vatvedt Fjeld
Subject: Re: Character arguments to format directives
Date: 
Message-ID: <2hd7badtqy.fsf@dslab7.cs.uit.no>
Espen Vestre <·····@*do-not-spam-me*.vestre.net> writes:

> Hmm, I still get funny results with lispworks:
> 
> CL-USER 36 > (format nil "~19,'0,' ,4:B" 3333)
> "000001101 0000 0101"
> 
> I think this must be a lispworks bug.

ACL, clisp and cmucl does the same. The problem is, it seems to me,
that you ask for padding with #\0 and you ask for grouping digits in
fours, but the question is, should the grouping also apply to the
padding?

The spec seems to intend the grouping to also apply to the padding
(and it would be useful) but none of the implementations does it,
probably because that would differ from all other padding.

-- 
Frode Vatvedt Fjeld
From: Duane Rettig
Subject: Re: Character arguments to format directives
Date: 
Message-ID: <4lmpxwzrw.fsf@beta.franz.com>
Frode Vatvedt Fjeld <······@acm.org> writes:

> Espen Vestre <·····@*do-not-spam-me*.vestre.net> writes:
> 
> > Hmm, I still get funny results with lispworks:
> > 
> > CL-USER 36 > (format nil "~19,'0,' ,4:B" 3333)
> > "000001101 0000 0101"
> > 
> > I think this must be a lispworks bug.
> 
> ACL, clisp and cmucl does the same. The problem is, it seems to me,
> that you ask for padding with #\0 and you ask for grouping digits in
> fours, but the question is, should the grouping also apply to the
> padding?

No.

> The spec seems to intend the grouping to also apply to the padding
> (and it would be useful) but none of the implementations does it,
> probably because that would differ from all other padding.

The mistaken assumption is that the examples within the text of the
standard are in fact the standard.  In section 1.4.3, Examples are
explicitly excluded from the standard.  If you consider the standard
alone, the apparent ambiguity disappears.  In this case, the example
is simply wrong.

-- 
Duane Rettig          Franz Inc.            http://www.franz.com/ (www)
1995 University Ave Suite 275  Berkeley, CA 94704
Phone: (510) 548-3600; FAX: (510) 548-8253   ·····@Franz.COM (internet)
From: Frode Vatvedt Fjeld
Subject: Re: Character arguments to format directives
Date: 
Message-ID: <2hvgp1bv97.fsf@dslab7.cs.uit.no>
Duane Rettig <·····@franz.com> writes:

> In this case, the example is simply wrong.

Ok. But having grouping of padding would still be very useful, IMHO.

-- 
Frode Vatvedt Fjeld
From: Kent M Pitman
Subject: Re: Character arguments to format directives
Date: 
Message-ID: <sfw1yrpwvth.fsf@world.std.com>
Espen Vestre <·····@*do-not-spam-me*.vestre.net> writes:

> Tim Moore <·····@herschel.bricoworks.com> writes:
> 
> > In 22.3.2.1 there's an example:
> > (format nil "~19,0,' ,4:B" 3333) =>  "0000 1101 0000 0101"
> 
> the example is wrong, the padchar 0 must be quoted.

If you're looking to original intent (which has no weight in interpreting
the correctness of an implementation, btw; it's just historical trivia):

Implementations of the original CLTL often supported, for compatibility,
the notion of using fixnum codes rather than character objects for characters,
especially in FORMAT, since Maclisp (a major parent dialect of CL) used
fixnums.  That is, (equal #/A 65) in Maclisp (which used slash instead of
backslash as its quoting character).  So if it had been the case that this
example really intended to show integers sufficing for characters here, it
would have used 48, not 0, and would have identified itself as implementation
dependent for the use of explicit numeric codes.

For this reason, I agree with Espen that it's just a typo.

> > Is the intent to treat single digits as character arguments, or is this
> > example in error?  Two implementations that I know of (CMUCL and
> > LispWorks) either spew garbage or signal an error for this example.
> 
> Hmm, I still get funny results with lispworks:
> 
> CL-USER 36 > (format nil "~19,'0,' ,4:B" 3333)
> "000001101 0000 0101"
> 
> I think this must be a lispworks bug.

I didn't look at this in detail but vaguely recall this might be a lack of
specificity in the spec.  Consider the following additional example and tell
me what you expect:

(format nil "~19,' ,',,4:B" 3333)