Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!usc!samsung!umich!yale!cmcl2!kramden.acf.nyu.edu!brnstnd From: brnstnd@kramden.acf.nyu.edu (Dan Bernstein) Newsgroups: comp.lang.misc Subject: Re: Algol, and language design Message-ID: <1720:Jul2823:44:0890@kramden.acf.nyu.edu> Date: 28 Jul 90 23:44:08 GMT References: <1990Jul26.024449.1777@esegue.segue.boston.ma.us> <2406@l.cc.purdue.edu> <1990Jul27.010930.12560@lth.se> Distribution: usa Organization: IR Lines: 85 In article <1990Jul27.010930.12560@lth.se> bengtl@maths.lth.se (Bengt Larsson) writes: > In article <2406@l.cc.purdue.edu> cik@l.cc.purdue.edu (Herman Rubin) writes: > >I do not see IF and FI as any better than BEGIN and END. Better would be > >to have labels (including temporary labels not going into the symbol table) > >and end statements which would carry the label. The END statement, even > >without a BEGIN statement, was in common use at the time; All processors > >need to know when to stop. > It seems you haven't heard about Ada. [ surveys the Ada control structures ] Q does the job better. The syntax and semantics of control structures are actually rather complex, and I'm still putting together a series of four articles to describe them, but here are several syntactic features: The basic form for control structure foo is foo end. The end can be specified, as in endfoo. The foo and end can be labelled, as in foo:main ... end:main. fi is a standard abbreviation for endif. Actually, control structures may include additional words: the form of an if statement, for example, is if(C) D [anyway] E fi. Here anyway is a keyword, which may have labels like if and fi; it is a once-at-most keyword, with default position just before the fi. A nonexistent label is taken as the empty label, or the label of the previous word in the same structure if that is applicable. else is a standard abbreviation for ``break anyway''; here break is the simplest example of an even more flexible syntax for exiting a control structure. This is just one example of how redundant control structures are replaced by macros. > In Ada, different constructs (loops and blocks come to mind) may have labels. > Like: > > MAIN_LOOP: loop > -- stuff > SUB_LOOP: loop > -- more stuff > exit MAIN_LOOP; -- exit 2 levels of loop > end loop SUB_LOOP; > end loop MAIN_LOOP; loop:MAIN /// stuff loop:SUB /// more stuff break^2; /// or breakloop:MAIN, or breakloop^2, or break:MAIN, or ... end; /// or endloop, or end:SUB, or pool, or endloop:SUB, or ... end; I find the Q version much more readable. (Okay, the semicolons aren't necessary. Shame on me.) > If a loop is started by a label and a ":", the same label must be repeated > after "end loop". Which is bad. The programmer shouldn't be forced into this style. Q does require that the labels match, but as explained above it will assume the loop label if the end label isn't provided. > The "exit" statement by default exits one level of loops, > it may also exit to a named level, as in the example. Q's breaking is nicer. (Note that Q's break doesn't distinguish between if, loop, switch, or any other structures. This greatly simplifies the semantics, and of course would have prevented the AT&T crash a few months back. [grin]) > All constructs have their own (two word) delimiter, like: > if A < B then > -- something > end if; Which is another annoyance. The programmer should be allowed to type just end. > Even if Ada isn't best at everything, I think they got the syntax right. Ada is best at nothing. Syntax is no exception. > I like "if then else end if" better than "if then begin end else begin end". Yes. There are many studies showing that explicitly terminated blocks are easier to write, reduce errors, are easier to read, etc. ---Dan