Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Posting-Version: version B 2.10.2 9/17/84; site opus.UUCP
Path: utzoo!watmath!clyde!burl!ulysses!allegra!mit-eddie!genrad!panda!talcott!harvard!seismo!hao!nbires!opus!rcd
From: rcd@opus.UUCP (Dick Dunn)
Newsgroups: net.lang
Subject: Re: Operator Precedence
Message-ID: <58@opus.UUCP>
Date: Wed, 18-Sep-85 02:59:29 EDT
Article-I.D.: opus.58
Posted: Wed Sep 18 02:59:29 1985
Date-Received: Fri, 20-Sep-85 06:28:30 EDT
References: <262@pedsgd.UUCP>
Organization: NBI,Inc, Boulder CO
Lines: 40

> I have a question. How did we end up with operator precedence in the
> first place? This seems to cause many more problems than what would
> seem to me to be obvious for algebraic expression - evaluate left
> to right in the absence of parenthesis...

Ahh, yes...the precedence battles.  Contrary to popular belief, precedence
in programming languages is not so much a matter of mathematical practice
as of programming language practice.

Consider that in the presentation of mathematics, the multiplication
operator is normally elided.  The precedence of multiplication in
mathematical usage is more an artifact of the physical "closeness" of the
factors than of any innate property of multiplication.

Next consider division.  If there is any question of the grouping of the
elements of the divisor or dividend, we use a long fraction bar.  Again,
the typographic presentation of the operation conveys more information than
any assumed precedence.

We give addition and subtraction equal precedence because they're "what's
left over" after dealing with multiplication and division by layout rules,
and we give them left associativity because our language works left-to-
right.

Mathematics does not have an "assignment" operator.  The = notation is used
to indicate definition or equality (as defined by context) and occurs only
once in a "statement".  There is a sense of precedence here.

Any more global notations (such as universal or existential quantifiers)
tend to be done with parenthesized notation to avoid ambiguity.

In fact, if you survey existing languages, it is rare to find a pair which
agree on the precedence and associativity of all of the operators they have in
common.  One of the more notable languages at variance with "the rest" is
SNOBOL, in which the precedence of * is higher than /.  If you play around
with it a little bit, you might be surprised at how often the SNOBOL
precedence of * over / gives a more natural notation for an expression.
-- 
Dick Dunn	{hao,ucbvax,allegra}!nbires!rcd		(303)444-5710 x3086
   ...Lately it occurs to me what a long, strange trip it's been.