comp.lang.ada
 help / color / mirror / Atom feed
From: agate!howland.reston.ans.net!darwin.sura.net!haven.umd.edu!news.umbc.edu! nobody@ucbvax.Berkeley.EDU  (Mike Berman)
Subject: Precedence Rules (was Re: Software vendors not using Ada but C)
Date: 24 Jun 93 13:35:50 GMT	[thread overview]
Message-ID: <20cajmINNqeb@umbc4.umbc.edu> (raw)

mfeldman@seas.gwu.edu (Michael Feldman) writes:
| In article <1993Jun23.163346.29745@sei.cmu.edu> firth@sei.cmu.edu
| (Robert Firth) writes:

| >Good grief.  And I thought Jean Ichbiah was paranoid when he refused to
| >give "and" and "or" the same precedence rules in Ada that they had in the
| >propositional calculus.  Not verbatim, but approximately: "Robert, a
| >programmer should never have to learn a new precedence rule as part of
| >a language.  The language should use only rules everyone already knows."

| And how! Students have more important things to learn than big precedence
| tables. IMHO the precedence rules are designed to make expression
| evaluation well-defined and (reasonably) intuitive, in the absence of
| parentheses. I teach precedence as a more-or-less advanced topic, more
| to illustrate how the language designers thought out the precedence
| than to make the students learn it.

When talking precedence, of course my thoughts turn immediately to mod
and rem (don't yours?).

I have seen the best programmers/mathematicians/all-around-nice-guys
brought down by the seemingly non-intuitive precedence rules surrounding
negative arguments and the mod and rem operators. The expression
-3 mod 2 is interpreted as -(3 mod 2), not (-3) mod 2, as most people
expect (I can make that generalization - we instructors get to ask lots
o' people).

The syntactic reasoning is clear, but not obvious. mod and rem are
grouped with the multiplying operators, which have higher precedence
than unary minus. For * and / this makes no difference in the first
operand, as (-3)*2 and -(3*2) produce the same result. 

When I read Mike and Roberts' comments, I thought "Oh, these rules must
somehow mirror some reality with which I am not familiar". Or something
like that. Checking the Rationale, I found the following (p. 92):

	The operations /, mod, and rem require explanation. There
	is no universal agreement on the semantics of these operations
	for negative operand values. Because different machines
	perform these operations differently, it is tempting not to
	define them for negative values.

So what's the real story-behind-the-story? Is it just easier to set up
the precedence rules this way, or is there some neat anecdote associated
with mod and rem?

Also, (I've always wanted to ask this), does anyone really use mod and
rem with negative operands?


-- 
Mike Berman                           
University of Maryland, Baltimore County           berman@umbc.edu
The views represented in the above post are my own.      

             reply	other threads:[~1993-06-24 13:35 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1993-06-24 13:35 agate!howland.reston.ans.net!darwin.sura.net!haven.umd.edu!news.umbc.edu! [this message]
  -- strict thread matches above, loose matches on Subject: below --
1993-06-24 15:22 Precedence Rules (was Re: Software vendors not using Ada but C) magnesium.club.cc.cmu.edu!news.sei.cmu.edu!ae
1993-06-24 20:18 cis.ohio-state.edu!news.sei.cmu.edu!jbg
1993-06-25 15:09 Jonathan Schilling
1993-06-25 20:50 Michael Feldman
1993-06-29  3:23 cis.ohio-state.edu!math.ohio-state.edu!sdd.hp.com!network.ucsd.edu!munnar
1993-06-29  4:06 Michael Feldman
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox