Standard Functions & Input/Output

These are "reserved" in the sense that they are assumed declared in the environment; a program may redeclare them.

19.1 Standard functions (Revised Report §3.2.4)

-1, 0 or +1 (integer result) sin(E), cos(E) trigonometric (radians) principal value of arctangent largest integer not greater than E (floor), integer result

These are "reserved" in the sense that they are assumed declared in the environment; a program may redeclare them.

19.2 Why ALGOL 60 has no I/O statements

The Paris committee deliberately left input/output out: machines of the time had wildly different devices (paper tape, cards, line printers, typewriters), and the committee felt it could not standardize them. The Report only says such facilities are provided by "code" procedures. The result: every implementation had its own I/O, which seriously harmed portability and ALGOL's adoption in industry.

19.3 Attempts to standardize I/O

1964, IFIP: *Report on Input-Output Procedures for ALGOL 60* — primitive procedures insymbol, outsymbol, length, inreal, outreal, inarray, outarray.

1964, ACM: *A Proposal for Input-Output Conventions in ALGOL 60* (Knuth et al.) — elaborate formatting.

1976, Modified Report: a standard environmental block of procedures, which MARST implements.

19.4 The Modified Report environment (as provided by MARST)

inchar(channel, str, int) read a character; set int to its position in str (0 if absent) outchar(channel, str, int) write the int-th character of str number of characters in a string outstring(channel, str) write a string write a terminator (separator) after a number ininteger(channel, int) read an integer outinteger(channel, int) write an integer inreal(channel, real) outreal(channel, real)

maxreal, minreal, maxint, epsilon fault(str, r) report an error message and value, then stop terminate the program

In MARST, channel 0 is standard input and channel 1 is standard output. MARST's runtime also provides some additional, non-standard procedures; see its manual. Exact number formatting (field width, exponent form) is implementation-defined.

19.5 Character I/O example

inchar maps each character read to its index in the string "aeiou."; any other character gives 0. This "string as character set" idiom replaces a character type.

'begin'
    'integer' c, count;
    count := 0;
    'comment' count vowels until a full stop is read;
next:
    inchar(0, "aeiou.", c);
    'if' c = 6 'then' 'goto' done;
    'if' c > 0 'then' count := count + 1;
    'goto' next;
done:
    outstring(1, "vowels: ");
    outinteger(1, count);
    outstring(1, "\n")
'end'