comp.lang.ada
 help / color / mirror / Atom feed
* Re: Shortcut logicals
  2005-02-01  1:16                                 ` Robert A Duff
@ 2005-02-01  6:49                                   ` Martin Dowie
  2005-02-01 13:46                                     ` Robert A Duff
  0 siblings, 1 reply; 12+ messages in thread
From: Martin Dowie @ 2005-02-01  6:49 UTC (permalink / raw)


Robert A Duff wrote:
> Sorry, I've no idea what the Fortran rules are.
> 
> In Ada, the above expression is syntactically illegal -- compile time
> error.  You can write:
> 
>     (cond1 and cond2) and then (cond3 and cond4)
> 
> or:
> 
>     ((cond1 and cond2) and then cond3) and cond4)
> 
> for example.
> 
> "and" is just a function call.  If you say "X and Y" then X and Y are
> both evaluated (in either order) and passed to the "and" function.  The
> predefined version of "and" returns True if both are True.  But "and
> then" is a short-circuit control form: if you say "X and then Y", X is
> evaluated first, and if it's True, you're done.  Otherwise (X is False)
> Y is evaluated.

Bob,

For clarity, I think you got the last bits a little wrong... If X is 
"True" then Y is evaluated otherwise (X is "False"), Y is not evaluated.

What you said would be right if it was an "or else" short-circuit form.

Cheers

-- Martin



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

* Re: Shortcut logicals (was: Re: F200x )
@ 2005-02-01  8:49 Christoph Grein
  2005-02-01 11:43 ` Martin Krischik
  0 siblings, 1 reply; 12+ messages in thread
From: Christoph Grein @ 2005-02-01  8:49 UTC (permalink / raw)
  To: comp.lang.ada

 > Robert A Duff wrote:
 >
 > > And the syntax rules forbid mixing "and" and "and then" -- you have to
 > > use parens.??All?of?these?("and",?"and?then",?"or",?"or?else",?"xor")
 > > are lower precedence than most other operators in Ada.??So?you?can
 > > write:
 >
 > Are you sure? I did not find anything in the RM to support that. I 
checked
 > both the RM and AARM:

Martin,
of course Robert is sure, if not, who else - you should know, he's 
deeply involved in Ada development.

See RM 4.4(2..7).

You'll find
relation and relation gives an expression,
relation and then relation also gives an expression.

But there is no syntax rule to combine an expression with a relation.
You can only combine a parenthesized expression (a primary) with a relation.

 > http://www.adaic.com/standards/95lrm/html/RM-4-5-1.html
 > http://www.adaic.com/standards/95aarm/html/AA-4-5-1.html
 >
 > (To the Fortran comunity: the the first is the general public 
version, the
 > later the compiler vendor version).

More precisely: The first is the binding reference manual, the second 
has further discussions, explanations and rationales without any binding 
character. Of course there should be no contradictions between the two.

 > Martin





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

* Re: Shortcut logicals (was: Re: F200x )
  2005-02-01  8:49 Shortcut logicals (was: Re: F200x ) Christoph Grein
@ 2005-02-01 11:43 ` Martin Krischik
  2005-02-01 12:45   ` Adrien Plisson
  2005-02-01 13:57   ` Robert A Duff
  0 siblings, 2 replies; 12+ messages in thread
From: Martin Krischik @ 2005-02-01 11:43 UTC (permalink / raw)


Christoph Grein wrote:

>  > Robert A Duff wrote:
>  >
>  > > And the syntax rules forbid mixing "and" and "and then" -- you have
>  > > to use
>  > > parens.??All?of?these?("and",?"and?then",?"or",?"or?else",?"xor") are
>  > > lower precedence than most other operators in Ada.??So?you?can write:
>  >
>  > Are you sure? I did not find anything in the RM to support that. I
> checked
>  > both the RM and AARM:

> of course Robert is sure, if not, who else - you should know, he's
> deeply involved in Ada development.

Ok you are right,  I am a just bit weak on names.

> See RM 4.4(2..7).

For our friends from comp.lang.fortran: You can read it up at
http://www.adaic.com/standards/95lrm/html/RM-4-4.html:
 
> You'll find
> relation and relation gives an expression,
> relation and then relation also gives an expression.

> But there is no syntax rule to combine an expression with a relation.
> You can only combine a parenthesized expression (a primary) with a
> relation.

Sure, you are right. But that rule means that:

 X or Y and Z

is not valid either. Not that I ever noticed - I would always use '()' on
such a term.

>  > http://www.adaic.com/standards/95lrm/html/RM-4-5-1.html
>  > http://www.adaic.com/standards/95aarm/html/AA-4-5-1.html
>  >
>  > (To the Fortran comunity: the the first is the general public
> version, the
>  > later the compiler vendor version).
> 
> More precisely: The first is the binding reference manual, the second
> has further discussions, explanations and rationales without any binding
> character. Of course there should be no contradictions between the two.

You know me: I always try to use easy words.

Martin

-- 
mailto://krischik@users.sourceforge.net
http://www.ada.krischik.com



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

* Re: Shortcut logicals (was: Re: F200x )
  2005-02-01 11:43 ` Martin Krischik
@ 2005-02-01 12:45   ` Adrien Plisson
  2005-02-01 14:03     ` Martin Krischik
  2005-02-01 13:57   ` Robert A Duff
  1 sibling, 1 reply; 12+ messages in thread
From: Adrien Plisson @ 2005-02-01 12:45 UTC (permalink / raw)


Martin Krischik wrote:
> Christoph Grein wrote:
>>You'll find
>>relation and relation gives an expression,
>>relation and then relation also gives an expression.
>>But there is no syntax rule to combine an expression with a relation.
>>You can only combine a parenthesized expression (a primary) with a
>>relation.
> 
> 
> Sure, you are right. But that rule means that:
> 
>  X or Y and Z
> 
> is not valid either. Not that I ever noticed - I would always use '()' on
> such a term.

it isn't valid. GNAT 3.15p says: mixed logical operators in expression.

See RM Introduction - design goals (§7):
"error-prone notations have been avoided"

and this construct is error-prone (especially if you are used to code 
in other languages than Ada, since each language has its own different 
operator precedence). the use of parenthesis clarifies the expression 
and leverages any ambiguities.

-- 
rien



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

* Re: Shortcut logicals
  2005-02-01  6:49                                   ` Shortcut logicals Martin Dowie
@ 2005-02-01 13:46                                     ` Robert A Duff
  0 siblings, 0 replies; 12+ messages in thread
From: Robert A Duff @ 2005-02-01 13:46 UTC (permalink / raw)


Martin Dowie <martin.dowie@btopenworld.com> writes:

> Bob,
> 
> For clarity, I think you got the last bits a little wrong... If X is
> "True" then Y is evaluated otherwise (X is "False"), Y is not evaluated.
> 
> What you said would be right if it was an "or else" short-circuit form.

Oops.  Thanks for catching that bug.

- Bob



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

* Re: Shortcut logicals (was: Re: F200x )
  2005-02-01 11:43 ` Martin Krischik
  2005-02-01 12:45   ` Adrien Plisson
@ 2005-02-01 13:57   ` Robert A Duff
  2005-02-01 15:35     ` Shortcut logicals Jan Vorbrüggen
  1 sibling, 1 reply; 12+ messages in thread
From: Robert A Duff @ 2005-02-01 13:57 UTC (permalink / raw)


Martin Krischik <martin@krischik.com> writes:

> Christoph Grein wrote:
> 
> >  > Robert A Duff wrote:
> >  >
> >  > > And the syntax rules forbid mixing "and" and "and then" -- you have
> >  > > to use
> >  > > parens.??All?of?these?("and",?"and?then",?"or",?"or?else",?"xor") are
> >  > > lower precedence than most other operators in Ada.??So?you?can write:
> >  >
> >  > Are you sure? I did not find anything in the RM to support that. I
> > checked
> >  > both the RM and AARM:
> 
> > of course Robert is sure, if not, who else - you should know, he's
> > deeply involved in Ada development.

I wouldn't say "of course" -- after all, Martin Dowie pointed out that I
got the run time semantics wrong.  ;-)

> Ok you are right,  I am a just bit weak on names.
> 
> > See RM 4.4(2..7).
> 
> For our friends from comp.lang.fortran: You can read it up at
> http://www.adaic.com/standards/95lrm/html/RM-4-4.html:
>  
> > You'll find
> > relation and relation gives an expression,
> > relation and then relation also gives an expression.
> 
> > But there is no syntax rule to combine an expression with a relation.
> > You can only combine a parenthesized expression (a primary) with a
> > relation.
> 
> Sure, you are right. But that rule means that:
> 
>  X or Y and Z
> 
> is not valid either.

Yes, that's what it means.  You have to say:

    (X or Y) and Z
or
    X or (Y and Z)

in Ada.  In maths, folks usually presume that "and" has higher
precedence than "or".  I'm pretty happy with the Ada rule, though.  In
general, I don't think programming languages should use precedence and
associativity rules beyond the ones folks know by age 9.  Many people
disagree with that, though -- they think "extra" parens cause too much
clutter, and make the code hard to read.

- Bob



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

* Re: Shortcut logicals (was: Re: F200x )
  2005-02-01 12:45   ` Adrien Plisson
@ 2005-02-01 14:03     ` Martin Krischik
  2005-02-01 14:56       ` Les
                         ` (2 more replies)
  0 siblings, 3 replies; 12+ messages in thread
From: Martin Krischik @ 2005-02-01 14:03 UTC (permalink / raw)


Adrien Plisson wrote:

> Martin Krischik wrote:
>> Christoph Grein wrote:
>>>You'll find
>>>relation and relation gives an expression,
>>>relation and then relation also gives an expression.
>>>But there is no syntax rule to combine an expression with a relation.
>>>You can only combine a parenthesized expression (a primary) with a
>>>relation.
>> 
>> 
>> Sure, you are right. But that rule means that:
>> 
>>  X or Y and Z
>> 
>> is not valid either. Not that I ever noticed - I would always use '()' on
>> such a term.
> 
> it isn't valid. GNAT 3.15p says: mixed logical operators in expression.
> 
> See RM Introduction - design goals (ᅵ7):
> "error-prone notations have been avoided"
> 
> and this construct is error-prone (especially if you are used to code
> in other languages than Ada, since each language has its own different
> operator precedence). the use of parenthesis clarifies the expression
> and leverages any ambiguities.

I fully agree with you here - and most Ada users will do as well. I would
use () in C and C++ as well - for clarity.

This is of corse a cross post with comp.lang.fortran and I wonder how they
see our solution to the problem. Is it suitable for Fortran 2003 as well or
do they need another solution?

With Regards

Martin
-- 
mailto://krischik@users.sourceforge.net
http://www.ada.krischik.com



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

* Re: Shortcut logicals (was: Re: F200x )
  2005-02-01 14:03     ` Martin Krischik
@ 2005-02-01 14:56       ` Les
  2005-02-01 16:57       ` Frank J. Lhota
  2005-02-01 17:55       ` Dan Nagle
  2 siblings, 0 replies; 12+ messages in thread
From: Les @ 2005-02-01 14:56 UTC (permalink / raw)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 2296 bytes --]


"Martin Krischik" <martin@krischik.com> wrote in message
news:1107266645.d89440009860d548c1e3d72cdc821e0c@teranews...
> Adrien Plisson wrote:
>
> > Martin Krischik wrote:
> >> Christoph Grein wrote:
> >>>You'll find
> >>>relation and relation gives an expression,
> >>>relation and then relation also gives an expression.
> >>>But there is no syntax rule to combine an expression with a relation.
> >>>You can only combine a parenthesized expression (a primary) with a
> >>>relation.
> >>
> >>
> >> Sure, you are right. But that rule means that:
> >>
> >>  X or Y and Z
> >>
> >> is not valid either. Not that I ever noticed - I would always use '()'
on
> >> such a term.
> >
> > it isn't valid. GNAT 3.15p says: mixed logical operators in expression.
> >
> > See RM Introduction - design goals (�7):
> > "error-prone notations have been avoided"
> >
> > and this construct is error-prone (especially if you are used to code
> > in other languages than Ada, since each language has its own different
> > operator precedence). the use of parenthesis clarifies the expression
> > and leverages any ambiguities.
>
> I fully agree with you here - and most Ada users will do as well. I would
> use () in C and C++ as well - for clarity.
>
> This is of corse a cross post with comp.lang.fortran and I wonder how they
> see our solution to the problem. Is it suitable for Fortran 2003 as well
or
> do they need another solution?


My own personal preference is for clarity of (a) readability and (b)
maintainablity.
Relying on my memory for operator precedence (or anything else, as anyone in
my family will testify) is unreliable. Hey I even have to look up the
relationship between TRUE and FALSE with 0 and 1 (or is it 1 and 0)
 :-)

So I use ( ) even if they are redundant.
I would tend to split a complex IF test into multiple tests - where
possible.
Situations where IF (X .and. Y) have side effects (X and/or Y being
functions say, either affecting the other) I also try to avoid and work
round another way.
My style may be "wordy", or niaive, or not to the taste of others, but as
long as I get correct and reasonably efficient code my employer and the
clients will be happy.

Les

>
> With Regards
>
> Martin
> -- 
> mailto://krischik@users.sourceforge.net
> http://www.ada.krischik.com





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

* Re: Shortcut logicals
  2005-02-01 13:57   ` Robert A Duff
@ 2005-02-01 15:35     ` Jan Vorbrüggen
  0 siblings, 0 replies; 12+ messages in thread
From: Jan Vorbrüggen @ 2005-02-01 15:35 UTC (permalink / raw)


> In maths, folks usually presume that "and" has higher
> precedence than "or".  I'm pretty happy with the Ada rule, though.  In
> general, I don't think programming languages should use precedence and
> associativity rules beyond the ones folks know by age 9.  Many people
> disagree with that, though -- they think "extra" parens cause too much
> clutter, and make the code hard to read.

I'm with you all the way. Anything to make the text clear by itself,
without reliance on external information (in this case, operator precedence
rules). It also forces the programmer to think about what he is writing,
and not go by the seats of his pants, as it were.

	Jan



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

* Re: Shortcut logicals (was: Re: F200x )
  2005-02-01 14:03     ` Martin Krischik
  2005-02-01 14:56       ` Les
@ 2005-02-01 16:57       ` Frank J. Lhota
  2005-02-01 17:55       ` Dan Nagle
  2 siblings, 0 replies; 12+ messages in thread
From: Frank J. Lhota @ 2005-02-01 16:57 UTC (permalink / raw)


"Martin Krischik" <martin@krischik.com> wrote in message 
news:1107266645.d89440009860d548c1e3d72cdc821e0c@teranews...
> I fully agree with you here - and most Ada users will do as well. I would
> use () in C and C++ as well - for clarity.
>
> This is of corse a cross post with comp.lang.fortran and I wonder how they
> see our solution to the problem. Is it suitable for Fortran 2003 as well 
> or
> do they need another solution?

In defense of Fortran, as early as Fortran '66 (back in the bad old days of 
punch cards, batch processing and paper print-outs), it was illegal to write 
something like

    ISGOOD .XOR. ISFREE .XOR. ISHERE

without parentheses, since it is not obvious how this expression was to be 
evaluated.

I'm also glad that Ada does not accept

    A ** B ** C

since I know programming languages that would evaluate this as

    ( A ** B ) ** C

as well as languages that would evaluate this as

    A ** ( B ** C )







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

* Re: Shortcut logicals (was: Re: F200x )
  2005-02-01 14:03     ` Martin Krischik
  2005-02-01 14:56       ` Les
  2005-02-01 16:57       ` Frank J. Lhota
@ 2005-02-01 17:55       ` Dan Nagle
  2005-02-01 18:25         ` James Giles
  2 siblings, 1 reply; 12+ messages in thread
From: Dan Nagle @ 2005-02-01 17:55 UTC (permalink / raw)


Hello,

On Tue, 01 Feb 2005 15:03:58 +0100, Martin Krischik
<martin@krischik.com> wrote:

<snip a bunch>
>
>This is of corse a cross post with comp.lang.fortran and I wonder how they
>see our solution to the problem. Is it suitable for Fortran 2003 as well or
>do they need another solution?
>
>With Regards
>
>Martin

This thread started in c.l.f discussing J3's efforts
to add andthen and orelse operators to Fortran.
J3 was unable to form a consensus regarding the operator precedence,
and tried a different tack.

The way the Fortran standard is written
makes it fairly difficult to delay evaluation
of arguments to operators or to functions.

J3 often examines the way Ada does something when seeking ideas.
Personally, I believe Ada is a very well designed language,
and I'm much more comfortable getting ideas from Ada
than from many other languages.

The fact that others disagree is probably why this thread
now appears beyond c.l.f.

-- 
Cheers!

Dan Nagle
Purple Sage Computing Solutions, Inc.



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

* Re: Shortcut logicals (was: Re: F200x )
  2005-02-01 17:55       ` Dan Nagle
@ 2005-02-01 18:25         ` James Giles
  0 siblings, 0 replies; 12+ messages in thread
From: James Giles @ 2005-02-01 18:25 UTC (permalink / raw)


Dan Nagle wrote:
...
> J3 often examines the way Ada does something when seeking ideas.
> Personally, I believe Ada is a very well designed language,
> and I'm much more comfortable getting ideas from Ada
> than from many other languages.

Ada has a lot of very useful ideas.  I was against cross-posting
this thread to the Ada group because I had assumed that Ada
would indeed have a perfectly sensible solution to the question,
but it's not necessarily the one Fortran should use.  It turns out
that if Ada does indeed require that the uses of the shortcut
operators (Ada calls them control forms) must parenthesize for
clarity, that is indeed a sensible solution.  It's also one of the
possibilities that occured independently.  Maybe Fortran should
follow suit, but at present the proposed feature solves the problem
differently.  At any rate, the answer hardly needs to concern the
Ada newsgroup anymore, so I for one will not cross-post any
of the further discussion.

-- 
J. Giles

"I conclude that there are two ways of constructing a software
design: One way is to make it so simple that there are obviously
no deficiencies and the other way is to make it so complicated
that there are no obvious deficiencies."   --  C. A. R. Hoare





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

end of thread, other threads:[~2005-02-01 18:25 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-02-01  8:49 Shortcut logicals (was: Re: F200x ) Christoph Grein
2005-02-01 11:43 ` Martin Krischik
2005-02-01 12:45   ` Adrien Plisson
2005-02-01 14:03     ` Martin Krischik
2005-02-01 14:56       ` Les
2005-02-01 16:57       ` Frank J. Lhota
2005-02-01 17:55       ` Dan Nagle
2005-02-01 18:25         ` James Giles
2005-02-01 13:57   ` Robert A Duff
2005-02-01 15:35     ` Shortcut logicals Jan Vorbrüggen
     [not found] <41f94cab$1@news1.ethz.ch>
     [not found] ` <INfKd.13707$bh6.378409@weber.videotron.net>
     [not found]   ` <nospam-6F7AE0.11340228012005@news.supernews.com>
     [not found]     ` <lqjnv01969glk2mbv1plvjdn5idkb1c3db@4ax.com>
     [not found]       ` <1107060103.157135.325010@z14g2000cwz.googlegroups.com>
     [not found]         ` <8u2pv0tdd9b1v689rtqc2c2tlm9pn9t1t6@4ax.com>
     [not found]           ` <1107085125.849687.318060@c13g2000cwb.googlegroups.com>
     [not found]             ` <1107096062.786125.100030@f14g2000cwb.googlegroups.com>
     [not found]               ` <10vq094k09igv3c@corp.supernews.com>
     [not found]                 ` <eudLd.43724$8u5.37685@bgtnsc04-news.ops.worldnet.att.net>
     [not found]                   ` <1107160100.162171.223490@f14g2000cwb.googlegroups.com>
     [not found]                     ` <cTxLd.126318$w62.46060@bgtnsc05-news.ops.worldnet.att.net>
     [not found]                       ` <xfKdnUflrtW3I2PcRVn-og@comcast.com>
     [not found]                         ` <rEzLd.68$xR1.54@bgtnsc04-news.ops.worldnet.att.net>
     [not found]                           ` <ON-dnSQzGfXOVWPcRVn-1A@comcast.com>
     [not found]                             ` <mXzLd.100$xR1.94@bgtnsc04-news.ops.worldnet.att.net>
2005-02-01  0:56                               ` Shortcut logicals (was: Re: F200x ) James Van Buskirk
2005-02-01  1:16                                 ` Robert A Duff
2005-02-01  6:49                                   ` Shortcut logicals Martin Dowie
2005-02-01 13:46                                     ` Robert A Duff

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