ALGOL W

When WG 2.1 chose van Wijngaarden's direction for ALGOL X, Niklaus Wirth and C.

22.1 Origins

When WG 2.1 chose van Wijngaarden's direction for ALGOL X, Niklaus Wirth and C. A. R. (Tony) Hoare published their more conservative proposal, "A Contribution to the Development of ALGOL" (CACM, June 1966). Wirth implemented it on the IBM System/360 at Stanford as ALGOL W, which was widely used for teaching in the late 1960s and 1970s. A modern compiler, awe (Glyn Webster), translates ALGOL W to C.

22.2 What ALGOL W changed

Records & references record node (integer val; reference(node) next); heap allocation with garbage collection; null fixed-length string(n), substrings s(start|length)

long real, complex, long complex, bits, logical (Boolean) call by value, result, value result, and by name (default)

while... do, case... of begin... end, for i:= a until b do with limit evaluated once and an implicitly declared, local control variable typed procedures whose body is an expression built-in read, readon, write, writeon, with editing variables assert statement a program ends with end.

Field access uses the field name as a function: val(p), next(p).

22.3 ALGOL W example (awe)

Parameters are specified in the heading: (integer value n).

Node(i, head) allocates a record and initializes its fields.

Comments: comment ... ; or % ... % (awe accepts both; check its manual).

~= is awe's ASCII coding of ALGOL W's ¬=.

begin
    integer procedure fact(integer value n);
        if n = 0 then 1 else n * fact(n - 1);

    record Node (integer val; reference(Node) next);
    reference(Node) head, p;

    for i := 0 until 10 do write(i, fact(i));

    head := null;
    for i := 1 until 5 do head := Node(i, head);   % build list 5 4 3 2 1 %
    p := head;
    write("list:");
    while p ~= null do
    begin
        writeon(val(p));
        p := next(p)
    end
end.

22.4 Value-result parameters

result parameters are copied back to the caller on exit; value result copies in and out. ALGOL W arrays use parentheses for subscripts and (*) for formal array bounds.

procedure minmax(real array a(*); integer value n; real result lo, hi);
begin
    lo := hi := a(1);
    for i := 2 until n do
    begin
        if a(i) < lo then lo := a(i);
        if a(i) > hi then hi := a(i)
    end
end;

22.5 Legacy

ALGOL W's records, references, case and while led directly to Pascal (1970). Hoare's paper on records ("Record Handling", 1965–66) influenced Simula 67's classes. ALGOL W was also the first implementation language for several Stanford projects and the teaching language of a generation of computer scientists.