Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Algol 68

Name: Anonymous 2013-03-12 23:02

Algol 68 looks like a modern language (except for the uppercase keywords) even though it's older than C. It had real garbage collection and user-defined operators.
This is a program that defines a tree structure and some operations on it:
MODE LEAF = INT;
MODE TREE = STRUCT(REF TREE l, LEAF c, REF TREE r);
MODE ACTION = STRUCT(PROC VOID in, PROC(REF LEAF)VOID leaf, PROC VOID out);
BOOL left = TRUE, right = FALSE;
OP & = (TREE t)REF TREE: HEAP TREE := t;
OP & = (LEAF l)REF TREE: HEAP TREE := (NIL, l, NIL);
OP ^ = (PROC(REF LEAF)VOID p)ACTION: (VOID: EMPTY, p, VOID: EMPTY);
PRIO -> = 1, OP -> = (REF TREE src, REF REF TREE dest)REF REF TREE: dest := src;
OP LEFT = (REF TREE t)REF REF TREE: l OF t;
OP RIGHT = (REF TREE t)REF REF TREE: r OF t;
PROC walk = (REF TREE t, ACTION action)VOID: (t :/=: NIL |
    in OF action;
    walk(l OF t, action);
    (leaf OF action)(c OF t);
    walk(r OF t, action);
    out OF action);
PROC follow = (REF TREE t, []BOOL path)REF REF TREE: (
    PROC loop = (REF REF TREE n, []BOOL path)REF REF TREE:
        IF UPB path < 1 THEN
            n
        ELSE
            loop(IF path[1] THEN l OF n ELSE r OF n FI, path[2:@1])
        FI;
    loop(LOC REF TREE := t, path[@1]));
PROC(REF TREE)VOID display = walk(, (VOID: print("("), (REF LEAF l)VOID: printf(($g(0)$, l)), VOID: print(")")));
PRIO JOIN = 5, OP JOIN = (LEAF init, REF TREE t)LEAF: (
    LEAF coll := init;
    walk(t, ^((REF LEAF l)VOID: coll +:= l));
    coll);

TREE tree := (&TREE(&7, 1, &TREE(&-3, -5, &-4)), 2, &TREE(&8, 3, NIL));
display(tree); print(new line);
print(0 JOIN tree);
&TREE(&5, 6, &7) -> LEFT LEFT tree;
display(RIGHT tree); print(new line);
display(tree); print(new line);
display(follow(tree, (left, right, right)))

This is a similar program in ML for comparison:
datatype 'a tree = NIL | TREE of 'a tree * 'a * 'a tree
type 'a action = (unit -> unit) * ('a -> unit) * (unit -> unit)
fun LEFT (TREE(l, _, _)) = l
  | LEFT NIL = NIL
fun RIGHT (TREE(_, _, r)) = r
  | RIGHT NIL = NIL
fun & l = TREE(NIL, l, NIL)
fun A l = ((fn() => ()), l, (fn() => ()))
fun walk ((TREE(l, c, r)), act as (in', leaf, out)) = (
         in'();
         walk(l, act);
         leaf(c);
         walk(r, act);
         out()
    )
  | walk (NIL, _) = ()
fun follow ((TREE(l, c, r)), (dir :: xs)) = follow(if dir then l else r, xs)
  | follow (t, nil) = t
  | follow (NIL, _) = NIL
fun display conv t = walk(t, (fn() => print("("), fn(l) => print(conv l), fn() => print(")")))
fun JOIN (init, t) = let val coll = ref init in
         walk(t, A(fn(l) => coll := !coll + l));
         !coll
    end
infix JOIN
val tree = TREE(TREE(&7, 1, TREE(& ~3, ~5, & ~4)), 2, TREE(&8, 3, NIL))
val _ = (print o Int.toString)(0 JOIN tree)
val _ = display Int.toString (tree)

Name: Anonymous 2013-03-14 0:22

>>6
This is well-known. C won out because:

 - I/O libraries were standard (unlike Algol, where earlier dialects couldn't agree on a syntax for printing and getting input)
 - Assembly programmers trained in the early 60s who didn't believe a compiled language could ever be efficient were given a form of structured assembly that had minimal overhead.
 - It was absurdly portable (unlike said assembly).
 - It was small (unlike PL/I, which IBM and MIT wanted to become standard).
 - It was terse (LOLBOL).
 - It had good support for block structures (Fortran didn't back then).

But to be honest, C won out largely because of Unix. The only OS remotely similar to Unix at the time was Multics, and that was a very expensive beast written in PL/I (and just enough assembly to keep it from being portable.) Unix, on the other hand, was cheap, minimalist, and easily ported to other architectures. It brought C with it, and not many other OSes ever had a C compiler written for them.

(Windows and DOS don't count in this—MS was internally a Unix shop in the early 80s; their distro was named Xenix, which eventually became SCO Unix.)

There were elaborate operating systems written in Pascal-like languages, such as LILITH (written in Modula-2), but these were in competition with Xerox (Smalltalk) and Symbolics/LSI (Lisp). By that time, Algol was already forgotten behind languages like Lisp, Prolog, and Fortran; theorists preferred functional and logical programming, and scientists needed code that was easy to support on commodity hardware. These were the two major markets for Algol, and without them, it had nothing to fall back on.

Algol still gets a lot of mileage in PLT, though. Standard pseudocode syntax is based on Algol (usually with Pascal influence), and standard semantics textbooks still explore Algol's structure.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List