Modula-2 Reloaded

A Modern Typesafe & Literate Programming Notation

Site Menu

Project

Specification

Implementation

Recommendations

Reference

Needs Updating

Work in Progress

Wastebasket

Wiki Manual

edit SideBar

Universal Write F

WiP.UniversalWriteF History

Hide minor edits - Show changes to output

2015-07-16 00:00 by Rick S -
Changed line 8 from:
A @@`WriteF@@ procedure is required for typed @@BYTE@@. If the value of @@SYSTEM.BITSPERBYTE@@ is other than eight @@BYTE@@ and @@ADDRESS@@ may share a single implementation.
to:
A @@`WriteF@@ procedure is required for type @@BYTE@@. If the value of @@SYSTEM.BITSPERBYTE@@ is other than eight @@BYTE@@ and @@ADDRESS@@ may possibly share a single implementation.
2015-07-15 23:58 by Rick S -
Changed lines 86-98 from:
word1 := CAST (WORD, 0);
word2 := CAST (WORD, 123);
WordIO.WriteF( f, "N", word1, word2 ); (* assuming 32-bit word size *)
=> 00000000
, 0000007B

WordIO.WriteF( f
, "b", word1, word2 );
=> 0b0, 0b00000000'00000000'00000000'01111001

WordIO.WriteF( f, "x", word1, word2
);
=> 0x0, 0x7B

WordIO.WriteF( f, "_4", word1, word2 ); (* assuming 32-bit word size *)
=> 0000 0000, 0000 007B
to:
  word1 := CAST (WORD, 0);
  word2 := CAST (WORD, 123);
  word3 := CAST (WORD, 65535);
  WordIO.Write3F( f, "N|\n"
, word1, word2, word3 ); (* first two in default array format *)
  WordIO.Write3F( f, "b|\n", word1, word2, word3 );
  WordIO.Write3F( f, "x\n", word1, word2, word3 );
  WordIO.Write3F( f
, "d\n", word1, word2, word3 );
  WordIO.Write3F( f, "_4\n", word1, word2, word3 );
=> { 00000000, 0000007B, 0000FFFF }
  { 0b0, 0b00000000'00000000'00000000'01111011, 0b00000000'00000000'11111111'11111111 }
  0x0, 0x0000007B, 0x0000FFFF
  0, 123, 65535
  0000 0000, 0000 007B, 0000 FFFF
2015-07-15 15:38 by Rick S -
Changed lines 494-495 from:
For non-character array output one @@`WriteF@@ procedure is required for each base type.
to:
For non-character array output the @@WriteF@@ procedure that  is required for each base type can also output an array.
Changed lines 501-502 from:
arrayOptions : '|' enclosure | concatenator ;
enclosure :
'{}' | '[]' | '()' ;
to:
arrayOptions : '|' enclosureStart, separator, enclosureEnd | concatenator ;
enclosureStart :
'{' | '[' | '(' ;
enclosureEnd : '}' | ']' | ')' ;
enclosure : ',' | ';[' | '
)' ;
Added line 510:
The start and end enclosures must match
Changed lines 520-532 from:
   y : ARRAY 3 OF REAL = { 67.5, 78.0, 99.1 };

ARRAYOFREAL.WriteF( f, "2.2|{}", x, y );
=> { 1.23, 4.50 }, { 67.50, 78.00, 99.10 }

ARRAYOFREAL.WriteF( f
, "2.2|[]", x, y );
=> [ 1.23, 4.50 ], [ 67.50, 78.00, 99.10 ]

ARRAYOFREAL
.WriteF( f, "2.2|()", x, y );
=> ( 1.23, 4.50 ), ( 67
.50, 78.00, 99.10 )

ARRAYOFREAL
.WriteF( f, "2.2|~", x, y );
=> 1.23, 4
.50, 67.50, 78.00, 99.10
to:
   y : ARRAY 3 OF REAL = { 67.5, 78.0, 99.2 };

  RealIO.Write2ArrayF( f, "F2.2|{,}\n", x, y );
  RealIO.Write2ArrayF( f, "F2.2|[;]\n", x, y );
  RealIO
.Write2ArrayF( f, "F2.2|{ }\n", x, y );
  RealIO.Write2ArrayF( f, "F2.2|~\n", x, y );
=> {  1
.23,  4.50 }, { 67.50, 78.00, 99.20 }
   [  1.23;  4.50 ]; [ 67.50; 78.00; 99.20 ]
   {  1.23  4.50 } { 67.50 78.00 99.20 }
    1.23,  4.50, 67.50, 78.00, 99.20
2015-07-14 16:59 by Rick S -
Changed line 356 from:
fillChar :  '*' |  'z' ;
to:
fillChar :  '*' |  'z' | 's' ;
Added line 378:
[@'s'@] - numerals are left filled with spaces, option requires number of integral digits shown (default if it is omitted)\\
Changed line 409 from:
(* space fill, engineering notation eight integral digits, two fractional digits, two columns, space digit grouping *)
to:
(* asterisk fill, engineering notation eight integral digits, two fractional digits, two columns, space digit grouping *)
Added lines 415-419:
(* space fill, modified floating point notation requiring six sig figs before decimal, adjusted exponent, eight integral digits, two fractional digits, space digit grouping *)
(* note no comma separators in column format *)
LongRealIO.WriteF( f, "S6s8.6_", 123.0, 123456789.0  );
=>  123 000.000 000e-003,  123 456.789 000e+003
(* the space fill trigger "s" is only needed when necessary to separate other elements; it is the default if it can be skipped. *).
2015-07-14 14:47 by Rick S -
Changed lines 391-394 from:
(* asterisk fill, eight integral digits, two fractional digits, comma digit grouping, append " USD" *)
REAL
.WriteF( f, "*8.2;' USD'!1", 123.0, 123456789.0 );
=> *******123.00 USD
   12,345,678.90 USD
to:
(* asterisk fill, fixed point eight integral digits, two fractional digits, single column comma digit grouping *)
LongRealIO.WriteF( f,
"F*8.2!1", 123.0, 123456789.0 );
=>*****123.00
   123456789.00

(* asterisk fill, dollar format which is fixed point eight integral digits, two fractional digits, plus comma digit grouping, append " USD" *)
LongRealIO.WriteF(  f, "$*8;' USD'", 123.0, 123456789.0  );
=> $*****123.00 USD, $123,456,789.00 USD

(* zero fill, fixed point eight integral digits, three fractional digits, comma digit grouping *)
LongRealIO.WriteF( f, "Fz8.3;", 0.0, 123.0, 123456789.0 );
=> 00,000,000.000, 00,000,123.000, 123,456,789.000

(* asterisk fill, scientific notation eight integral digits, six fractional digits, space digit grouping *)
LongRealIO.WriteF( f, "S*8.6_", 0.0, 123.0, 123456789.0 );
=> *******0.000 000e+00, *******1.230 000e+002, *******1.234 568e+008

(* space fill, engineering notation eight integral digits, two fractional digits, two columns, space digit grouping *)
(* note no comma separators in column format *)
LongRealIO.WriteF( f, "E*8.2_!2", 0.0, 123.0, 123456789.0 );
=> *******0.00e+000*****123.00e+000
  *****123.46e+006

2015-07-14 12:48 by Rick S -
Changed lines 334-335 from:
(* same as previous example but separate items with newline *)
IntegerIO.WriteF( f, "+*8;>15\n", 123, -3456789 );
to:
(* same as previous example but separate items with newline by specifying one column *)
IntegerIO.WriteF( f, "+*8;>15!1", 123, -3456789 );
Added line 339:
(* note that to end the entire output with a newline, one appends \n to the format string *)
2015-07-13 23:46 by Rick S -
Changed lines 258-259 from:
For whole number output one @@`WriteF@@ procedure is required for each of the pervasive types @@OCTET@@, @@CARDINAL@@, @@INTEGER@@, @@LONGCARD@@, @@LONGINT@@ and each user defined whole number type.
to:
For whole number output one @@`WriteF@@ procedure is required for each of the pervasive types @@OCTET@@, @@CARDINAL@@, @@INTEGER@@, @@LONGCARD@@, @@LONGINT@@ and any other user defined whole number type.
Changed line 302 from:
INTEGER.WriteF( f, "x", 0, -123 );
to:
IntegerIO.WriteF( f, "x", 0, -123 );
Changed line 306 from:
CARDINAL.WriteF( f, "x", 0, 123, 3456789 );
to:
CardinalIO.WriteF( f, "x", 0, 123, 3456789 );
Changed line 310 from:
INTEGER.WriteF( f, "+", 123, -3456789 );
to:
IntegerIO.WriteF( f, "+", 123, -3456789 );
Changed line 314 from:
INTEGER.WriteF( f, "+8", 123, -3456789 );
to:
IntegerIO.WriteF( f, "+8", 123, -3456789 );
Changed line 318 from:
INTEGER.WriteF( f, "+z8", 123, -3456789 );
to:
IntegerIO.WriteF( f, "+z8", 123, -3456789 );
Changed line 322 from:
INTEGER.WriteF( f, "+*8", 123, -3456789 );
to:
IntegerIO.WriteF( f, "+*8", 123, -3456789 );
Changed line 326 from:
INTEGER.WriteF( f, "+*8;", 123, -3456789 );
to:
IntegerIO.WriteF( f, "+*8;", 123, -3456789 );
Changed line 331 from:
INTEGER.WriteF( f, "+*8;>15", 123, -3456789 );
to:
IntegerIO.WriteF( f, "+*8;>15", 123, -3456789 );
Changed line 335 from:
INTEGER.WriteF( f, "+*8;>15\n", 123, -3456789 );
to:
IntegerIO.WriteF( f, "+*8;>15\n", 123, -3456789 );
2015-07-13 22:49 by Rick S -
Changed line 176 from:
BITSET.WriteF( f, "S", { } , { 2, 5, 7 } );
to:
BitsetIO.WriteF( f, "S", { } , { 2, 5, 7 } );
Changed line 179 from:
BITSET.WriteF( f, "_4", { } , { 2, 5, 7 } ); (* assuming 8-bit bitset *)
to:
BitsetIO.WriteF( f, "_4", { } , { 2, 5, 7 } ); (* assuming 8-bit bitset *)
Changed lines 233-238 from:
ARRAYOFCHAR.WriteF( f, "<16!5", "AND", "ARRAY", "BEGIN", "BY", "CASE", "CONST", "DEFINITION",
                               "DIV", "DO", "ELSE", "ELSIF", "END", "ENUM", "EXIT", "FOR",
                                "FROM, "IF", "IMMUTABLE", "IMPLEMENTATION", "IMPORT", "IN",
                                "IS", "LOOP", "MOD", "MODULE", "NOT", "OF", "OPAQUE", "OR",
                                "POINTER", "PROCEDURE", "RECORD", "REPEAT", "RETURN", "SET",
                                "THEN", "TO", "TYPE", "UNTIL", "VAR", "VARIADIC",
"WHILE" );
to:
ARRAYOFCHAR.WriteF( f, "<16!5",  "ALIAS","AND","ARGLIST","ARRAY","BEGIN"
"BLUEPRINT","BY","CASE","CONST","COPY"
 "DEFINITION","DIV","DO","ELSE","ELSIF"
 "END","EXIT","FOR","FROM","GENLIB"
 "IF","IMPLEMENTATION","IMPORT","IN","INDETERMINATE"
 "LITERAL","LOOP","MOD","MODULE","NEW"
 "NONE","NOT","OF","OPAQUE","OR"
 "POINTER","PROCEDURE","RECORD","REFERENTIAL","RELEASE"
 "REPEAT","RETAIN","RETURN","SET","THEN"
"TO","TYPE","UNTIL","VAR","WHILE" );
Changed lines 244-252 from:
AND            ARRAY          BEGIN          BY            CASE
CONST
          DEFINITION      DIV            DO            ELSE
ELSIF
          END            ENUM            EXIT           FOR
FROM
          IF            IMMUTABLE      IMPLEMENTATION  IMPORT
IN
              IS              LOOP           MOD             MODULE
NOT
             OF             OPAQUE          OR            POINTER
PROCEDURE
      RECORD          REPEAT        RETURN        SET
THEN
            TO              TYPE          UNTIL          VAR
VARIADIC
        WHILE
to:

          ALIAS            AND        ARGLIST          ARRAY          BEGIN
      BLUEPRINT              BY          CASE          CONST          COPY
      DEFINITION             DIV            DO          ELSE          ELSIF
            END            EXIT             FOR           FROM          GENLIB
              IF  IMPLEMENTATION          IMPORT             IN  INDETERMINATE
        LITERAL           LOOP            MOD        MODULE            NEW
            NONE            NOT            OF          OPAQUE              OR
        POINTER      PROCEDURE          RECORD    REFERENTIAL        RELEASE
          REPEAT          RETAIN          RETURN            SET            THEN
              TO            TYPE          UNTIL            VAR 
        WHILE
2015-07-13 17:54 by Rick S -
Changed lines 173-175 from:
BITSET.WriteF( f, "N", { } , { 2, 5, 7 } );
=> { }, { 2, 5, 7 }
to:
BitsetIO.WriteF( f, "N", { } , { 2, 5, 7 } );
=> {  }, { 2, 5, 7 }
Changed lines 177-178 from:
=> { }, { 2, 5, 7 }
to:
=> {  }, { 2, 5, 7 }
Changed line 215 from:
CHAR.WriteF( f, "~", "A", "B", "C", "D", "E" );
to:
CharIO.WriteF( f, "~", "A", "B", "C", "D", "E" );
Changed line 218 from:
CHAR.WriteF( f, "N", "A", "B", "C", "D", "E" );
to:
CharIO.WriteF( f, "N", "A", "B", "C", "D", "E" );
Changed line 221 from:
CHAR.WriteF( f, "Q", "A", "B", "C", "D", "E" );
to:
CharIO.WriteF( f, "Q", "A", "B", "C", "D", "E" );
Changed line 224 from:
CHAR.WriteF ("u", "A");
to:
CharIO.WriteF ("u", "A");
2015-07-13 16:22 by Rick S -
Changed line 131 from:
BOOLEAN.WriteF( f, "T", TRUE, FALSE );
to:
BooleanIO.WriteF( f, "T", TRUE, FALSE );
Changed line 134 from:
BOOLEAN.WriteF( f, "Y", TRUE, FALSE );
to:
BooleanIO.WriteF( f, "Y", TRUE, FALSE );
2015-07-13 15:51 by Rick S -
Changed line 60 from:
literalOptions : 'b' | 'x' ;
to:
literalOptions : 'b' | 'x' | "d" ;
Added line 75:
[@'d'@] - numerals are written in decimal format\\
Changed lines 86-88 from:
WORD.WriteF( f, "N", 0, 123 ); (* assuming 32-bit word size *)
to:
word1 := CAST (WORD, 0);
word2 := CAST (WORD, 123);
WordIO.WriteF( f, "N", word1, word2
); (* assuming 32-bit word size *)
Changed line 91 from:
WORD.WriteF( f, "b", 0, 123 );
to:
WordIO.WriteF( f, "b", word1, word2 );
Changed line 94 from:
WORD.WriteF( f, "x", 0, 123 );
to:
WordIO.WriteF( f, "x", word1, word2 );
Changed line 97 from:
WORD.WriteF( f, "_4", 0, 123 ); (* assuming 32-bit word size *)
to:
WordIO.WriteF( f, "_4", word1, word2 ); (* assuming 32-bit word size *)
2015-07-13 15:43 by Rick S -
Changed line 38 from:
byte1 :=CAST (BYTE, 0);
to:
byte1 := CAST (BYTE, 0);
2015-07-13 15:42 by Rick S -
Changed line 16 from:
numeralOptions : 'b' | 'x' | "d";
to:
numeralOptions : 'b' | 'x' | "d" ;
2015-07-13 15:42 by Rick S - Further separated BYTE from OCTET
2015-07-13 15:42 by Rick S - Further separated BYTE from OCTET
Changed lines 38-40 from:
BYTE.WriteF( f, "N", 0, 123 );
to:
byte1 :=CAST (BYTE, 0);
byte2 := CAST (BYTE, 123);
ByteIO.WriteF(f, "N", byte1, byte2
);
Changed line 43 from:
BYTE.WriteF( f, "b", 0, 123 );
to:
BYTE.WriteF( f, "b", byte1, byte2 );
Changed line 46 from:
BYTE.WriteF( f, "x", 0, 123 );
to:
BYTE.WriteF( f, "x", byte1, byte2 );
2015-07-13 13:33 by Rick S - Further separated BYTE from OCTET
Changed lines 8-11 from:
For octet and byte output one @@`WriteF@@ procedure each is required for types @@OCTET@@ and @@BYTE@@. If the value of @@SYSTEM.BITSPERBYTE@@ is eight, the two procedures may share a single implementation.

The syntax of a format string for octet and
byte output is as follows:
to:
A @@`WriteF@@ procedure is required for typed @@BYTE@@. If the value of @@SYSTEM.BITSPERBYTE@@ is other than eight @@BYTE@@ and @@ADDRESS@@ may share a single implementation.

The syntax of
a format string for byte output is as follows:
Changed line 14 from:
octetOrByteFmtStr : '"' noFormatting? numeralOptions? alignOptions? columnOptions? '"' ;
to:
ByteFmtStr : '"' noFormatting? numeralOptions? alignOptions? columnOptions? '"' ;
Changed line 16 from:
numeralOptions : 'b' | 'x' ;
to:
numeralOptions : 'b' | 'x' | "d";
Added line 30:
[@'d'@] - numerals are written in decimal format\\
Changed line 38 from:
OCTET.WriteF( f, "N", 0, 123 );
to:
BYTE.WriteF( f, "N", 0, 123 );
Changed line 41 from:
OCTET.WriteF( f, "b", 0, 123 );
to:
BYTE.WriteF( f, "b", 0, 123 );
Changed line 44 from:
OCTET.WriteF( f, "x", 0, 123 );
to:
BYTE.WriteF( f, "x", 0, 123 );
2015-06-08 19:06 by rsutc -
Added lines 158-159:

The meaning of formatting options for the bitset taken as a whole is as follows:\\\
2015-06-08 19:05 by rsutc -
Added line 425:
2015-06-08 19:04 by rsutc -
Added lines 423-424:

The meaning of formatting options for the complex number as a whole is as follows:\\\
2015-06-08 18:10 by rsutc -
Changed lines 336-337 from:
realOptions : 'S' | 'F' | 'E' | '$'
numeralOptions : sign? intDigitOptions? fracDigitOptions? digitGrouping? exponent? suffix?;
to:
realOptions : 'S' digit? digit?| 'F' | 'E' | '$'
numeralOptions : sign? intDigitOptions? fracDigitOptions? digitGrouping? suffix?;
Deleted line 342:
exponent : ( 'e' | 'E' ) digit digit? ;
Changed line 391 from:
realOptions : 'S' | 'F' | 'E' | '$'
to:
realOptions : 'S' digit? digit?| 'F' | 'E'
Changed line 393 from:
numeralOptions : sign? intDigitOptions? fracDigitOptions? digitGrouping? exponent? suffix?;
to:
numeralOptions : sign? intDigitOptions? fracDigitOptions? digitGrouping? suffix?;
Deleted line 398:
exponent : ( 'e' | 'E' ) digit digit? ;
Changed line 412 from:
[@'S'@] - numerals are written in scientific notation "1.9e4"\\
to:
[@'S'@] - numerals are written in (possibly modified) scientific notation. The option specifies the required number of digits before the decimal; default is one "1.9e4"\\
Deleted line 414:
[@'$'@] - numerals are written with the currency prefix and two digits after the decimal in fixed format  "$19000.00"\\
2015-06-08 18:03 by rsutc -
Changed lines 387-406 from:
TO DO

The meaning of formatting options is as follows:\\
[@'i'@] - composite format with suffix i for imaginary part\\
[@'j'@] - composite format with suffix j for imaginary part\\
[@'r'@] - raw format with real and imaginary part in parentheses separated by comma

Examples:

[@
COMPLEX.WriteF( f, "i", {3.5, 6.75} );
=> 3.5+6.75i

COMPLEX.WriteF( f, "j", {3.5, 6.75} );
=> 3.5+6.75j

COMPLEX.WriteF( f, "r", {3.5, 6.75} );
=> ( 3.5, 6.75 )

COMPLEX.WriteF( f, <format-string>, {3.5, 6.75} );
=> ( 3.500000000e+00, 6.750000000e+00 )
to:

>>lrindent round frame bgcolor=#f8f8f8 border='1px solid grey'<<

[@
realNumFmtStr : '"' noFormatting? realOptions? complexOptions? numeralOptions alignOptions? columnOptions? '"' ;
noFormatting : 'N' ;
realOptions : 'S' | 'F' | 'E' | '$'
complexOptions : 'i', | 'j', 'r'
numeralOptions : sign? intDigitOptions? fracDigitOptions? digitGrouping? exponent? suffix?;
intDigitOptions : fillChar? digit digit? ;
fracDigitOptions : ( '.' | ',' ) digit digit? ;
sign : '+' | '-'  ;
fillChar :  '*' |  'z' ;
digitGrouping : '_' | ';' ;
exponent : ( 'e' | 'E' ) digit digit? ;
suffix : "'" printableCharacter+ "'" ;
alignOptions : alignment fieldWidth ;
alignment : '<' | '>' ;
fieldWidth : digit digit? digit? ;
columnOptions : concatenator | columns ;
concatenator : '~' ;
columns : '!" digit? digit? ;
@]
>><<

The meaning of formatting options for each of the two real components is as follows:\\\

[@'N'@] - normalised, equivalent "S"\\
[@'S'@] - numerals are written in scientific notation "1.9e4"\\
[@'E'@] - numerals are written in engineering notation; exponent is always a multiple of three "19.0e3"\\
[@'F'@] - numerals are written in fixed point notation without an exponenet  "19000"\\
[@'$'@] - numerals are written with the currency prefix and two digits after the decimal in fixed format  "$19000.00"\\
[@'+'@] - numerals are preceded by their sign or whitespace if their value is zero\\
[@'-'@] - numerals are preceded by their sign if negative, otherwise by whitespace\\
[@'*'@] - numerals are left filled with asterisks, option requires number of integral digits shown\\
[@'z'@] - numerals are left filled with zeroes, option requires number of integral digits shown\\
[@'.'@] - numerals are written with a decimal point, option requires number of fractional digits shown\\
[@','@] - numerals are written with a decimal comma, option requires number of fractional digits shown\\
[@'_'@] - numerals are grouped into triads from right to left, separated by whitespace\\
[@';'@] - numerals are grouped into triads from right to left, separated by commas if decimal point, otherwise periods\\
[@'<'@] - numerals are left aligned, option requires field width\\
[@'>'@] - numerals are right aligned, option requires field width\\
[@'''@] - append characters enclosed in single quotes to each numeral\\
[@'~'@] - concatenate numerals to their respective predecessor without separators\\
[@'!'@] - numerals are written in columns, option may be followed by the number of columns


The meaning of the complex formatting options is as follows:\\