From: Antonio Martinez <tonyms@te...> - 2003-05-09 15:37:46
Is the following behaviour a bug?
* (format t "~2,0X" 9)
debugger invoked on condition of type TYPE-ERROR:
The value 0 is not of type BASE-CHAR.
* (format t "~2,0X" 255)
My reading of ANSI makes me think that the 0 digit is to be
interpreted as a padding character, not a number. However,
PARSE-DIRECTIVE in late-format.lisp always parses digits as numbers,
If I'm understanding ANSI aright, parsing the directives is more
complex than the current PARSE-DIRECTIVE, because you need to check
which digits should be converted to numbers and which to padding
characters, depending on the directive.
[ FWIW, CMUCL, Clisp and LispWorks interpret this digit as a number,
too. A superficial muck about with the different implementations
shows wildly varying behaviour if the character isn't a digit. In
particular, the space that the padding character defaults to
(according to ANSI) doesn't work in any of the above implementations,
and a variety of other characters produce very different results (it's
hard to find characters which aren't format directives!), mostly
I'm not sure this note actually contains a clue as such, since my
expectations don't seem to correspond with the behaviour of all the
implementations I tried, so any comments are more than welcome.
From: Antonio Martinez <tonyms@te...> - 2003-05-09 17:08:11
> I think a literal "padchar" is always of the form 'C, that is,
> with a quote mark in front of the character.
> (format t "~2,'0X" 9)
Ah, great, that works. And indeed in 22.3, "Formatted Output":
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
There are multiple examples of this usage in the format examples
section. So I'll run along...
Thanks very much and sorry to have been a bother,