What is the output of:
writeln(false);
writeln(true);
In ISO 7185 standard Pascal ? According to page 55 of Douglas
Coopers' Standard Pascal Users Manual, the result is:
false
true
Ie., the values are printed without spaces.
The ISO text governing this is:
=====================================================================
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 integer-type, 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-de ned, 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 character of the value of e in that order.
if 1 <= TotalWidth <= n,
The first through TotalWidth-th characters in that order.
=======================================================================
The idea that a default width true or false value should be printed
without spaces comes from 6.9.3.5 "This shall be equivalent to writing the appropriate character-string 'True' or 'False'". Strings
have a
default field width of their string length.
The problem is in 6.9.3.1: "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."
Its clearly defining a default width for boolean types as
implementation-defined, as opposed to string-types, which have a
default value of their length. In fact, why bother to discuss a
default field width for booleans if that is just going to be superceeded
by the string rule.
Based on this interpretation, that booleans have a default width,
the output for:
write(false);
writeln(true);
Would be:
false
true
or even (for default boolean width 7):
false
true
or even (for default boolean width 2):
se
ue
The standard never said defaults have to be reasonable !
$ type w.pas
program w(output);
begin
writeln(true);
writeln(false);
end.
$ pascal w
$ link w
$ run w
TRUE
FALSE
The default width for Booleans for me is 6. That makes 1 leading space
in front of FALSE and 2 leading spaces in front of TRUE.
--
John Reagan
HP Pascal/{A|I}MACRO for OpenVMS Project Leader
Hewlett-Packard Company
For PascalP the default is 5, resulting in no or one leading space
respectively. This is for booleans, not strings.
--
Chuck F (cbfal...@yahoo.com) (cbfal...@worldnet.att.net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net> USE worldnet address!
$ cat Boole.pas
PROGRAM BOOLE(OUTPUT);
(* A simple test of the Boolean output format *)
BEGIN
WRITELN(true);
WRITELN(false);
END.
$ ./Boole
TRUE
FALSE
$