comp.lang.ada
 help / color / mirror / Atom feed
* Question about Ada expressions
  1989-10-11 18:13   ` Dick Dunn
@ 1989-10-11 22:14     ` Perry Schmidt
  1989-10-12 10:56       ` STEPHEN D. STRADER
                         ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: Perry Schmidt @ 1989-10-11 22:14 UTC (permalink / raw)



In Ada, when building boolean expressions you must put ANDs and ORs (and
OR ELSES, etc) in parents IF you use them in mixed combination.

Ex.  (A and B or C) -- is not legal.  You must write it as...
     (A and (B or C))

So the question is -- WHY?

Does this remove some semantic ambiguity?  Or is it just the "Ada style!"

Thanks for any responses...

Perry Schmidt
(schmidt@green.cs.wisc.edu)

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Question about Ada expressions
  1989-10-11 22:14     ` Question about Ada expressions Perry Schmidt
@ 1989-10-12 10:56       ` STEPHEN D. STRADER
  1989-10-12 12:15       ` Robert Firth
                         ` (2 subsequent siblings)
  3 siblings, 0 replies; 7+ messages in thread
From: STEPHEN D. STRADER @ 1989-10-12 10:56 UTC (permalink / raw)


In article <8834@spool.cs.wisc.edu> schmidt@green.cs.wisc.edu (Perry Schmidt) writes:
>In Ada, when building boolean expressions you must put ANDs and ORs (and
>OR ELSES, etc) in parents IF you use them in mixed combination.
>Ex.  (A and B or C) -- is not legal.  You must write it as...
>     (A and (B or C))
>So the question is -- WHY?

BECAUSE!

No, actually it is to remove ANY ambiguity as to how the expression
should be evaluated.  

Saright?

S

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Question about Ada expressions
  1989-10-11 22:14     ` Question about Ada expressions Perry Schmidt
  1989-10-12 10:56       ` STEPHEN D. STRADER
@ 1989-10-12 12:15       ` Robert Firth
  1989-10-12 22:07       ` stt
  1989-10-13 14:38       ` horst
  3 siblings, 0 replies; 7+ messages in thread
From: Robert Firth @ 1989-10-12 12:15 UTC (permalink / raw)


In article <8834@spool.cs.wisc.edu> schmidt@green.cs.wisc.edu (Perry Schmidt) writes:

>In Ada, when building boolean expressions you must put ANDs and ORs (and
>OR ELSES, etc) in parents IF you use them in mixed combination.

>So the question is -- WHY?

There is no problem of semantic ambiguity, any more than with, say,
A + B*C.  The reason for the restriction is that one of the language
designers believed the relative priorities of the Boolean operators
were sufficiently unfamiliar to the general run of programmers that
expressions such as

	A and B or C

could cause confusion or, worse, be misinterpeted.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Question about Ada expressions
  1989-10-11 22:14     ` Question about Ada expressions Perry Schmidt
  1989-10-12 10:56       ` STEPHEN D. STRADER
  1989-10-12 12:15       ` Robert Firth
@ 1989-10-12 22:07       ` stt
  1989-10-13 14:38       ` horst
  3 siblings, 0 replies; 7+ messages in thread
From: stt @ 1989-10-12 22:07 UTC (permalink / raw)



Ada tried to use the "conventional" precedence
rules when defining operators.  However, it has
never been entirely clear where XOR belongs relative
to AND and OR, nor how regular AND
and short-circuit AND THEN should
fare relative to one another.  The net result
was that they "punted" in this area and said
use parentheses when using two logical operators
in sequence.  

It might have been ideal in some
people's mind if at least AND had clearly higher precedence 
than OR so that your example could be coded without
parentheses, but Ada has always tried to err
on the side of readability over writability.

S. Tucker Taft
Intermetrics, Inc.
Cambridge, MA

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Question about Ada expressions
@ 1989-10-12 23:37 Karl Nyberg
  1989-10-15 20:35 ` Scott Simpson
  0 siblings, 1 reply; 7+ messages in thread
From: Karl Nyberg @ 1989-10-12 23:37 UTC (permalink / raw)


I had a friend call yesterday after spending five hours trying to figure out
why some C code didn't work based on this expression:

	if (variable & MASK == VALUE)

He mistook the rules of precedence, just as Robert Firth expressed it in his
response.  The K&R book explains this reasoning:

	Note that the precedence of the bitwise logical operators &, ^ and |
	falls below == (test for equality) and !=  (test for inequality).
	This implies that bit-testing expressions like

		if ((x & MASK) == 0) ...

	must be fully parenthesized to give proper results.  [p. 49]

Seems like it was kind of the Ada designers to preclude this from the
language.  Getting an error during compile time would have saved my friend
immense difficulty.  Getting a manual might have helped him, too...

-- Karl --

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Question about Ada expressions
  1989-10-11 22:14     ` Question about Ada expressions Perry Schmidt
                         ` (2 preceding siblings ...)
  1989-10-12 22:07       ` stt
@ 1989-10-13 14:38       ` horst
  3 siblings, 0 replies; 7+ messages in thread
From: horst @ 1989-10-13 14:38 UTC (permalink / raw)


In article <8834@spool.cs.wisc.edu> schmidt@green.cs.wisc.edu (Perry Schmidt) writes:
>
>In Ada, when building boolean expressions you must put ANDs and ORs (and
>OR ELSES, etc) in parents IF you use them in mixed combination.
>...
>Does this remove some semantic ambiguity?  Or is it just the "Ada style!"

Yes, there is an ambiguity. The precedence of 'and' and 'or'
is not so commonly agreed as that of '*' and '+'. So the
designers chose to require parenthesis.
Regards,
 horst

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Question about Ada expressions
  1989-10-12 23:37 Question about Ada expressions Karl Nyberg
@ 1989-10-15 20:35 ` Scott Simpson
  0 siblings, 0 replies; 7+ messages in thread
From: Scott Simpson @ 1989-10-15 20:35 UTC (permalink / raw)


In article <8910122337.AA06188@grebyn.com> karl@grebyn.com (Karl Nyberg) writes:
>I had a friend call yesterday after spending five hours trying to figure out
>why some C code didn't work based on this expression:
>
>	if (variable & MASK == VALUE)

Your buddy didn't use lint.  It would have caught this.
	Scott Simpson
	TRW Space and Defense Sector
	usc!trwarcadia!simpson  	(UUCP)
	trwarcadia!simpson@usc.edu	(Internet)

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~1989-10-15 20:35 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1989-10-12 23:37 Question about Ada expressions Karl Nyberg
1989-10-15 20:35 ` Scott Simpson
  -- strict thread matches above, loose matches on Subject: below --
1989-10-06 12:50 Re^2: Ada 9X objectives Robert Munck
1989-10-08 17:07 ` William Thomas Wolfe, 2847 
1989-10-11 18:13   ` Dick Dunn
1989-10-11 22:14     ` Question about Ada expressions Perry Schmidt
1989-10-12 10:56       ` STEPHEN D. STRADER
1989-10-12 12:15       ` Robert Firth
1989-10-12 22:07       ` stt
1989-10-13 14:38       ` horst

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