Chris Burrows wrote:
> "scott moore" <nospam@[EMAIL PROTECTED]
> wrote in message
> news:2audncjwIpTZmcjanZ2dnUVZ_g-dnZ2d@[EMAIL PROTECTED]
>
>> { 8: Numbers and booleans with default width }
>> writeln(1);
>> writeln(true);
>> writeln(false);
>> writeln('Should be similar to:');
>> writeln;
>> writeln(' 1');
>> writeln(' true');
>
> Why the leading space in ' true'? (Ref: ISO 7185: 6.9.3.5, 6.9.3.6)
>
> --
> Chris Burrows
> CFB Software
> http://www.cfbsoftware.com/gpcp
>
>
===========================================================================
6.9.3.1 Write-parameters
A write-parameter shall have one of the following forms
e : TotalWidth : FracDigits
e : TotalWidth
e
where e shall be an expression whose value is to be written on the file
f and shall be of integertype, real-type, char-type, Boolean-type, or a
string-type, and where TotalWidth and FracDigits shall be expressions
of integer-type whose values shall be the field-width parameters . The
values of TotalWidth and FracDigits shall be greater than or equal to
one ; it shall be an error if either value is less than one.
Write(f,e) shall be equivalent to the form write(f,e : TotalWidth),
using a default value for TotalWidth that depends on the type of e ;
for integer-type, real-type, and Boolean-type, the default values
shall be implementation-defined.
6.9.3.5 Boolean-type
If e is of Boolean-type, a representation of the word true or the word
false (as appropriate to the value of e) shall be written on the file f.
This shall be equivalent to writing the appropriate character-string
'True' or 'False' (see 6 .9 .3 .6), where the case of each letter is
implementation-defined, with a field-width parameter of TotalWidth.
6.9.3.6 String-types
If the type of e is a string-type with n components, the default value
of TotalWidth shall be n . The representation shall consist of if
TotalWidth > n, (TotalWidth - n) spaces, the first through n-th
Characters of the value of e in that order. if 1 <= TotalWidth <= n,
the first through TotalWidth-th characters in that order.
==========================================================================
6.9.3.1 Says that the default parameter will be TotalWidth, and that
TotalWidth depends on the type of e. In 6.9.3.5, it says that writes
of boolean are equivalent to string writes, so the writes are:
write('true': TotalWidth);
write('false': TotalWidth);
6.9.3.6 Simply gives the rules of string writes.
This means that for a value of TotalWidth = 5 (the length of false), you
obtain the results shown. If the value is 4, you get:
true
fals
So that does not make sense. If you use 6.9.3.6 to argue that the value
of n is the length of the string, and therefore that Total width is 4
for true and 5 for false, ie., that totalwidth varies according to which
value of boolean is being output, you have done exactly what I did, and
I lost that argument. The two basic reasons are:
1. The language "Write(f,e) shall be equivalent to the form
write(f,e :TotalWidth), using a default value for TotalWidth that
depends on the type of e" says that TotalWidth depends on the TYPE of
e, not the VALUE of e.
2. Wirth himself didn't sup****t the idea. Pascal-S, the P-system
and other examples of his work use the interpretation that one value
of TotalWidth exists for boolean.
Here is a previous discussion of this:
http://groups.google.com/group/comp.lang.pascal.ansi-iso/browse_thread/thread/405be43010883aeb/e0c9318de08e1931?lnk=gst&q=boolean+totalwidth#


|
23 Posts in Topic:
|
scott moore <nospam@[E |
2007-11-28 01:07:17 |
|
Marco van de Voort <ma |
2007-11-28 14:50:56 |
|
scott moore <nospam@[E |
2007-11-29 23:36:21 |
|
scott moore <nospam@[E |
2007-11-30 00:10:35 |
|
Marco van de Voort <ma |
2007-11-30 08:38:41 |
|
scott moore <nospam@[E |
2007-12-01 19:01:06 |
|
Marco van de Voort <ma |
2007-12-02 12:17:14 |
|
scott moore <nospam@[E |
2007-12-03 23:39:48 |
|
"Chris Burrows" |
2007-12-05 09:57:36 |
|
scott moore <nospam@[E |
2007-12-05 00:41:26 |
|
Marco van de Voort <ma |
2007-12-08 16:45:55 |
|
scott moore <nospam@[E |
2007-12-09 18:06:47 |
|
Richard Engebretson <e |
2007-11-29 06:47:30 |
|
scott moore <nospam@[E |
2007-11-29 23:41:53 |
|
Rene Kita <renekita@[E |
2007-11-30 13:16:24 |
|
scott moore <nospam@[E |
2007-12-01 19:01:45 |
|
"gedumer1" < |
2007-12-06 19:06:24 |
|
"gedumer1" < |
2007-12-06 19:10:15 |
|
"Chris Burrows" |
2007-12-07 13:01:29 |
|
scott moore <nospam@[E |
2007-12-09 18:07:39 |
|
Keith Bowes <keith_bow |
2007-12-23 05:05:29 |
|
Richard Engebretson <e |
2007-11-30 04:10:35 |
|
scott moore <nospam@[E |
2007-12-01 19:00:17 |
|