byron@archone.tamu.edu (Byron Rakitzis) (01/16/91)
In article <1991Jan15.213533.9992@maytag.waterloo.edu> himacdon@maytag.uwaterloo.ca (Hamish Macdonald) writes: >>>>>> In article <andy.663963786@xwkg>, andy@xwkg.Icom.Com (Andrew H. >>>>>> Marrinson) writes: > >Andrew> if (command) { >Andrew> if (command) >Andrew> command >Andrew> } >Andrew> if not >Andrew> command > >Andrew> I suspect the if not applies to the second if, not the first. >Andrew> Naming it else would cause people to expect it to apply to the >Andrew> first if, as an else would. Calling it if not makes it clear >Andrew> it is different from else: it applies to the last if command >Andrew> run, and knows nothing about the lexical structure of the >Andrew> script. > >Nope. The "if not" applies to the first if (by experimentation). >"rc" must stack the results of the "if"s. I suspect it uses "if not" >because the: > if not > command >is a separate statement. > The reason is that "if not" looks at the preceeding COMMAND, at that level of scoping. The braced "argument" of the first if never comes into consideration. The place the if not burns you most, if you think of it as an else, is here: if (command) { foo } else { bar } This causes a syntax error in the parser, because the syntax of the if statement is "if (cmd) cmd" and an rc command must either end in newline, semicolon or &. Thus the "correct" way to write the above command would be: if (cmd) { foo }; else { bar } and hence: if (cmd) { foo } if not { bar } I agree that this is all hopelessly ugly, and I'm still waiting for an appropriate solution. The best suggestion I've heard to date is to make an else clause mandatory in an if statement (this is not without precedent---ML does this, though for different reasons) and then to use && for a simple-if. Thus: if (foo) bar ==> foo && bar This has its problems also, but at least makes the syntax for if-statements acceptable. --- A human being should be able to change a diaper, plan an invasion, butcher a hog, conn a ship, design a building, write a sonnet, balance accounts, build a wall, set a bone, comfort the dying, take orders, give orders, cooperate, act alone, solve equations, analyze a new problem, pitch manure, program a computer, cook a tasty meal, fight efficiently, die galantly. Specialization is for insects. --- Robert A. Heinlein (1916-1988) Byron Rakitzis, System Administrator Visualization Lab, College of Architecture Texas A&M University College Station, TX 77843 Work: 409-845-5691 Home: 409-693-7273