On Fri, 11 Sep 1998 [log in to unmask] wrote:
> In a message dated 9/11/98 4:48:22 AM, [log in to unmask] wrote:
>
> >A simple (?) question:
> >
> >Why is the precedence of .EQV. the second lowest and not the same
> >as ==? Naively I would consider A.eqv.B a relational expression
> >with logical result.
> >Would a higher precedence lead to ambiguities, hence the
> >current rules are the only sensible ones, or are the Fortran rules
> >just one possible definition?
>
> I may be a rarity, but I prefer Fortran's rule, in this case, to that of other
> languages. This ordering of precedences minimizes the amount of
> parenthesization compared to the other languages. In other languages
>
> A .EQ. B .EQV. C .EQ. D
>
> would naturally be parsed as
>
> ( ( A .EQ. B ) .EQV. C) .EQ. D
>
> which yields a type error (assuming C is not logical and the language does not
> identify integers with logicals) so that the desired comparison has to be
> explicitly parenthesized as
>
> ( A .EQ. B ) .EQV. ( C .EQ. D )
I beg to differ on these examples: .EQV. has a lower precedence than
.EQ. (or ==) so that
A==B .EQV. C==D
would be parsed as
(A==B) .eqv. (C==D)
while
A==B==C==D --> ((A==B)==C)==D
is obviously different from
(A==B)==(C==D)
The same argument applies to the repeated application of .AND. so I think
this cannot be used as an argument for the current Fortran rules rather
points more clearly to the awkward exception in Fortran.
The point here is that
a) Fortran has no relational .EQ. for logical values with the same
precedence as for numerical and character expressions
b) other languages have no equivalent to Fortran's .EQV.
They have to use parentheses as above
I think if you would present the above examples to beginning Fortran
programmers they would be more likely to follow my way of thinking.
Cheers,
WWS
-----------------------------------------------------------------------
| Werner W Schulz |
| Dept of Chemistry email: [log in to unmask] |
| University of Cambridge Phone: (+44) (0)1223 336 502 |
| Lensfield Road Secretary: 1223 336 338 |
| Cambridge CB2 1EW Fax: 1223 336 536 |
| United Kingdom WWW: |
-----------------------------------------------------------------------
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|