* Re: Shortcut logicals (was: Re: F200x ) @ 2005-02-01 8:49 Christoph Grein 2005-02-01 11:43 ` Martin Krischik 0 siblings, 1 reply; 18+ 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] 18+ 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; 18+ 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] 18+ 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; 18+ 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] 18+ 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; 18+ 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] 18+ 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; 18+ 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] 18+ 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; 18+ 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] 18+ 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; 18+ 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] 18+ 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; 18+ 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] 18+ 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; 18+ 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] 18+ 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; 18+ 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] 18+ messages in thread
[parent not found: <41f94cab$1@news1.ethz.ch>]
[parent not found: <INfKd.13707$bh6.378409@weber.videotron.net>]
[parent not found: <nospam-6F7AE0.11340228012005@news.supernews.com>]
[parent not found: <lqjnv01969glk2mbv1plvjdn5idkb1c3db@4ax.com>]
[parent not found: <1107060103.157135.325010@z14g2000cwz.googlegroups.com>]
[parent not found: <8u2pv0tdd9b1v689rtqc2c2tlm9pn9t1t6@4ax.com>]
[parent not found: <1107085125.849687.318060@c13g2000cwb.googlegroups.com>]
[parent not found: <1107096062.786125.100030@f14g2000cwb.googlegroups.com>]
[parent not found: <10vq094k09igv3c@corp.supernews.com>]
[parent not found: <eudLd.43724$8u5.37685@bgtnsc04-news.ops.worldnet.att.net>]
[parent not found: <1107160100.162171.223490@f14g2000cwb.googlegroups.com>]
[parent not found: <cTxLd.126318$w62.46060@bgtnsc05-news.ops.worldnet.att.net>]
[parent not found: <xfKdnUflrtW3I2PcRVn-og@comcast.com>]
[parent not found: <rEzLd.68$xR1.54@bgtnsc04-news.ops.worldnet.att.net>]
[parent not found: <ON-dnSQzGfXOVWPcRVn-1A@comcast.com>]
[parent not found: <mXzLd.100$xR1.94@bgtnsc04-news.ops.worldnet.att.net>]
* Re: Shortcut logicals (was: Re: F200x ) [not found] ` <mXzLd.100$xR1.94@bgtnsc04-news.ops.worldnet.att.net> @ 2005-02-01 0:56 ` James Van Buskirk 2005-02-01 1:16 ` Robert A Duff 2005-02-01 1:43 ` James Giles 0 siblings, 2 replies; 18+ messages in thread From: James Van Buskirk @ 2005-02-01 0:56 UTC (permalink / raw) [-- Warning: decoded text below may be mangled, UTF-8 assumed --] [-- Attachment #1: Type: text/plain, Size: 3072 bytes --] "James Giles" <jamesgiles@worldnet.att.net> wrote in message news:mXzLd.100$xR1.94@bgtnsc04-news.ops.worldnet.att.net... > Well, I have the F2003 FCD open right now, in �7.4.3 Masked array > assignment - WHERE. So, perhaps you can point out what part of > it resolves the issue I raised: > cond1 .and. cond2 .andthen. cond3 .and. cond4 > Is COND4 permitted to be evaluated or not? I don't see that > WHERE tells me. It has a concept of "pending control" which > I see can be applied on nested constructs, but in the above > expression, not of the terms actually present are part of any > "pending" condition. Or, are you talking about some other > aspect of WHERE entirely? OK, I have added comp.lang.ada, so hopefully someone there can answer the question about the effect of precedence on your snippet, and also discuss the ergonomics of Ada short- circuiting logical operators, or whatever they call them. I would answer your question above, assuming cond1 .AND. cond2 evaluate to scaler .FALSE._lk to be that it all depends; either cond3 or cond4 or neither or both could be 'short-circuited'. In the f95 standard I see some verbiage to the effect that: "If a nonelemental function reference occurs in the expr or variable of a where-assignment-statement or in a mask-expr, the function is evaluated without any masked control; that is, all of its argument expressions are fully evaluated and the function is fully evaluated. If the result is an array and the reference is not within the argument list of a nonelemental function, elements corresponding to true values in the control mask are selected for use in evaluating the expr, variable, or mask-expr. "If an elemental operation or function reference occurs in the expr or variable of a where-assignment-stmt or in a mask-expr, and is not within the argument list of a nonelemental function reference, the operation is performed or the function is evaluated only for the elements corresopnding to true values of the control mask. "If an array constructor appears in a where-assignment-stmt or in a mask-expr, the array constructor is evaluated without any masked control and then the where-assignment-stmt is executed or the mask-expr is evaluated." For .AND_THEN. and .OR_ELSE., if added to the Fortran language, the language would have to be changed somewhat to make it in terms of evaluating expressions rather than masked assignment. Also there should be something about scalar function references in there as well. I'm not even sure about what the standard thinks in WHERE, if an elemental function reference is used in a scalar context, such as WHERE(cond1) x = f(y)*g(z) given that cond1, x, and g(z) all have the same shape, f is elemental, and y is scalar. Is any(cond1) == .FALSE. then is the standard saying you still have to evaluate f(y) if it's a scalar function but not if it's elemental. This last paragraph shouldn't be considered a well-formed thought. -- write(*,*) transfer((/17.392111325966148d0,6.5794487871554595D-85, & 6.0134700243160014d-154/),(/'x'/)); end ^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: Shortcut logicals (was: Re: F200x ) 2005-02-01 0:56 ` Shortcut logicals (was: Re: F200x ) James Van Buskirk @ 2005-02-01 1:16 ` Robert A Duff 2005-02-01 8:08 ` Martin Krischik 2005-02-01 1:43 ` James Giles 1 sibling, 1 reply; 18+ messages in thread From: Robert A Duff @ 2005-02-01 1:16 UTC (permalink / raw) "James Van Buskirk" <not_valid@comcast.net> writes: > "James Giles" <jamesgiles@worldnet.att.net> wrote in message > news:mXzLd.100$xR1.94@bgtnsc04-news.ops.worldnet.att.net... > > > Well, I have the F2003 FCD open right now, in �7.4.3 Masked array > > assignment - WHERE. So, perhaps you can point out what part of > > it resolves the issue I raised: > > > cond1 .and. cond2 .andthen. cond3 .and. cond4 > > > Is COND4 permitted to be evaluated or not? I don't see that > > WHERE tells me. It has a concept of "pending control" which > > I see can be applied on nested constructs, but in the above > > expression, not of the terms actually present are part of any > > "pending" condition. Or, are you talking about some other > > aspect of WHERE entirely? > > OK, I have added comp.lang.ada, so hopefully someone there > can answer the question about the effect of precedence on > your snippet, and also discuss the ergonomics of Ada short- > circuiting logical operators, or whatever they call them. 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. 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: A <= B and B <= C which means the same as: (A <= B) and (B <= C) The point of "and then" is so you can write things like: Y /= 0 and then X/Y < 10 where X/Y makes no sense if Y is zero. - Bob ^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: Shortcut logicals (was: Re: F200x ) 2005-02-01 1:16 ` Robert A Duff @ 2005-02-01 8:08 ` Martin Krischik 0 siblings, 0 replies; 18+ messages in thread From: Martin Krischik @ 2005-02-01 8:08 UTC (permalink / raw) 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: 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). Martin -- mailto://krischik@users.sourceforge.net http://www.ada.krischik.com ^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: Shortcut logicals (was: Re: F200x ) 2005-02-01 0:56 ` Shortcut logicals (was: Re: F200x ) James Van Buskirk 2005-02-01 1:16 ` Robert A Duff @ 2005-02-01 1:43 ` James Giles 2005-02-01 2:33 ` James Van Buskirk 1 sibling, 1 reply; 18+ messages in thread From: James Giles @ 2005-02-01 1:43 UTC (permalink / raw) [-- Warning: decoded text below may be mangled, UTF-8 assumed --] [-- Attachment #1: Type: text/plain, Size: 3878 bytes --] James Van Buskirk wrote: > "James Giles" <jamesgiles@worldnet.att.net> wrote in message > news:mXzLd.100$xR1.94@bgtnsc04-news.ops.worldnet.att.net... > >> Well, I have the F2003 FCD open right now, in �7.4.3 Masked array >> assignment - WHERE. So, perhaps you can point out what part of >> it resolves the issue I raised: > >> cond1 .and. cond2 .andthen. cond3 .and. cond4 > >> Is COND4 permitted to be evaluated or not? I don't see that >> WHERE tells me. It has a concept of "pending control" which >> I see can be applied on nested constructs, but in the above >> expression, not of the terms actually present are part of any >> "pending" condition. Or, are you talking about some other >> aspect of WHERE entirely? > > OK, I have added comp.lang.ada, so hopefully someone there > can answer the question about the effect of precedence on > your snippet, and also discuss the ergonomics of Ada short- > circuiting logical operators, or whatever they call them. > > I would answer your question above, assuming cond1 .AND. cond2 > evaluate to scaler .FALSE._lk to be that it all depends; either > cond3 or cond4 or neither or both could be 'short-circuited'. But, that's just the problem. The whole purpose of the separate short-circuit operators is to eliminate ambiguities about whether a given condition is evaluated. That allows the programmer to prevent evaluation of conditions if such evaluation would cause exceptions or program termination. Merely saying "it depends" doesn't help. But, making a different rule - that the new operators are lower precedence than the non-shortcut ones, for example - does help. That makes the example unambiguous. The standard permits logical operators (and their operands) to be evaluated in any order that produces a logically equivalent result. Presumably that would be changed with respect to the shortcut operators to require the right operand be evaluated conditionally based on the value of the left. In the example in question, assuming that the operators all have the same precedence, the actual order of evaluation might be pretty much anything. COND1, COND2, and COND4 might all be ecaluated before any of the operators are done at all. So, the expression might be as if it were rewritten as either of (as well as others): cond4 .and. cond1 .and. cond2 .andthen. cond3 cond2 .andthen. cond3 .and. cond4 .and. cond1 In fact, the only requires order (as far as I can tell) is that COND3 can't be evaluated before COND2 is found to be .true. (If COND2 is array valued, the elements of COND3 corresponding to those elements of COND2 that were .true. would also *may* have to be evaluated. I can see that in this case only an analogy to how WHERE works is appropriate.) But this is the same result as if the shortcut operator had lower precedence than the non-shortcut operator. Now consider: cond1 .or. cond2 .andthen. cond3 .or. cond4 Even given that .andthen. has higher precedence than .or., the rules of Fortran still suggest that COND1, COND2, and COND3 might all be evaluated before the .andthen. operator is executed. After all, reordering the .or. operator is still permitted. Both the following are allowed interpretations as well as others): cond4 .or. cond1 .or. cond2 .andthen. cond3 cond2 .andthen. cond3 .or. cond4 .or. cond1 Now, not only do I find this confusing, I'm sure it will hide latent errors in the code of others. Requiring parentheses or using a function-call notation eliminates all ambiguities. Making the new operators lower precedence than everything else helps a little. -- 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] 18+ messages in thread
* Re: Shortcut logicals (was: Re: F200x ) 2005-02-01 1:43 ` James Giles @ 2005-02-01 2:33 ` James Van Buskirk 2005-02-01 2:53 ` James Giles 0 siblings, 1 reply; 18+ messages in thread From: James Van Buskirk @ 2005-02-01 2:33 UTC (permalink / raw) "James Giles" <jamesgiles@worldnet.att.net> wrote in message news:i9BLd.316$xR1.179@bgtnsc04-news.ops.worldnet.att.net... > Now, not only do I find this confusing, I'm sure it will hide latent > errors in the code of others. Requiring parentheses or using a > function-call notation eliminates all ambiguities. Making the new > operators lower precedence than everything else helps a little. Jeez, it took me so much time to punch all that stuff from the standard in and you didn't even bother to read it. Precedence has nothing to do with the question of whether cond4 is evaluated in your original expression. Hint: suppose cond4 has rank 1 and all others are scalar. Same thing happens in WHERE except that the question is: how do you do shape matching unless you get far enough through an expression to determine its shape even though the mask it will be subjected to is all false? -- write(*,*) transfer((/17.392111325966148d0,6.5794487871554595D-85, & 6.0134700243160014d-154/),(/'x'/)); end ^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: Shortcut logicals (was: Re: F200x ) 2005-02-01 2:33 ` James Van Buskirk @ 2005-02-01 2:53 ` James Giles 2005-02-01 3:49 ` James Van Buskirk 0 siblings, 1 reply; 18+ messages in thread From: James Giles @ 2005-02-01 2:53 UTC (permalink / raw) James Van Buskirk wrote: > "James Giles" <jamesgiles@worldnet.att.net> wrote in message > news:i9BLd.316$xR1.179@bgtnsc04-news.ops.worldnet.att.net... > >> Now, not only do I find this confusing, I'm sure it will hide latent >> errors in the code of others. Requiring parentheses or using a >> function-call notation eliminates all ambiguities. Making the new >> operators lower precedence than everything else helps a little. > > Jeez, it took me so much time to punch all that stuff from the > standard in and you didn't even bother to read it. Precedence > has nothing to do with the question of whether cond4 is evaluated > in your original expression. [...] I might say the same thing. On the other hand, you did explicitly state that even if the value of cond1.and.cond2 were .false. the answer still "depends". That seemed like an ambiguous response to me. > [...] Hint: suppose cond4 has rank 1 and > all others are scalar. [...] Hint: suppose they're *all* scalars. I still don't see the subtle point you're making. If it requires me to assume that any of the operands are not scalar befor the answer is apparent, I'll need more than a hint. But it does seem to me that a paragraph beginning "If an array constructor appears ..." it's not immediately obvious how that applies to an example with no arrays at all. Similarly, it's difficult to figure how other things you quote apply when the conditional expression in my example may not even involve WHERE. > [...] Same thing happens in WHERE except that > the question is: how do you do shape matching unless you get > far enough through an expression to determine its shape even > though the mask it will be subjected to is all false? Well, if all the operands are scalar, the shape is pretty obvious. The question isn't shape (or even value). The question is whether the program crashes or continues running. Explain again how the disection of WHERE allows me to decide whether the original example may be legally rearranged (asuming scalar X): x/=0.0 .and. cond2 .andthen. cond3 .and. 5.0/x>10.0 ?=> 5.0/x>10.0 .and. x/=0.0 .and. cond2 .andthen. cond3 or cond2 .andthen. cond3 .and. 5.0/x>10.0 .and. x/=0.0 etc. One of the reasons it took me a while to respond is that I *did* read what you wrote (and couldn't find the subtle relevance you assert) - I've just reread it again. My puzzlement still remains. It does seem to me that the case where all operands are scalar ought to be simpler than more exotic possibilities. And a simple IF (or even a scalar logical assignment statement) ought to be simpler to discuss that a WHERE construct. -- 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] 18+ messages in thread
* Re: Shortcut logicals (was: Re: F200x ) 2005-02-01 2:53 ` James Giles @ 2005-02-01 3:49 ` James Van Buskirk 2005-02-01 4:31 ` James Giles 0 siblings, 1 reply; 18+ messages in thread From: James Van Buskirk @ 2005-02-01 3:49 UTC (permalink / raw) "James Giles" <jamesgiles@worldnet.att.net> wrote in message news:ZaCLd.474$xR1.216@bgtnsc04-news.ops.worldnet.att.net... > x/=0.0 .and. cond2 .andthen. cond3 .and. 5.0/x>10.0 > ?=> > 5.0/x>10.0 .and. x/=0.0 .and. cond2 .andthen. cond3 > cond2 .andthen. cond3 .and. 5.0/x>10.0 .and. x/=0.0 Obviously the first short-circuits the DIVCHK and the last two don't. > One of the reasons it took me a while to respond is that I *did* > read what you wrote (and couldn't find the subtle relevance you > assert) - I've just reread it again. My puzzlement still remains. > It does seem to me that the case where all operands are scalar > ought to be simpler than more exotic possibilities. And a simple > IF (or even a scalar logical assignment statement) ought to be > simpler to discuss that a WHERE construct. Obviously you don't get it. How do you know what array gets passed to sub: module mymod implicit none contains subroutine sub(x) logical, intent(in) :: x(:) write(*,*) size(x) end subroutine sub function f(n) integer, intent(in) :: n logical f(n) integer i f = mod(mod((17+(/(i,i=1,n)/))**2,97),2) == 0 end function f end module mymod program test use mymod implicit none integer n real x write(*,'(a)',advance='no') 'Enter the size of the array:> ' read(*,*) n write(*,'(a)',advance='no') 'Enter a number:> ' read(*,*) x call sub(x/=0 .AND_THEN. n > 0 .AND. f(n)) end program test So pick apart the first typo you find and tell me you still don't get it... [sigh]. -- write(*,*) transfer((/17.392111325966148d0,6.5794487871554595D-85, & 6.0134700243160014d-154/),(/'x'/)); end ^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: Shortcut logicals (was: Re: F200x ) 2005-02-01 3:49 ` James Van Buskirk @ 2005-02-01 4:31 ` James Giles 0 siblings, 0 replies; 18+ messages in thread From: James Giles @ 2005-02-01 4:31 UTC (permalink / raw) James Van Buskirk wrote: > "James Giles" <jamesgiles@worldnet.att.net> wrote in message > news:ZaCLd.474$xR1.216@bgtnsc04-news.ops.worldnet.att.net... > >> x/=0.0 .and. cond2 .andthen. cond3 .and. 5.0/x>10.0 > >> ?=> > >> 5.0/x>10.0 .and. x/=0.0 .and. cond2 .andthen. cond3 > >> cond2 .andthen. cond3 .and. 5.0/x>10.0 .and. x/=0.0 > > Obviously the first short-circuits the DIVCHK and the last two > don't. But, *all* are allowed rearrangements of the first! That's the existing Fortran rule. Notice I *did* assume that rearrangement of the .andthen. operation could *not* be rearranged, but the above still remain permitted implementation dependent rearrangements with respect to .and. > Obviously you don't get it. How do you know what array gets > passed to sub: You're right, I don't get it. You still insist on answering the question with an irrelevant excursion into arrayhood. Until I see the answer for scalars, I'm not sure I even want to ask about arrays. > call sub(x/=0 .AND_THEN. n > 0 .AND. f(n)) I think that even after *my* question is answered, your's still is not. If the implementation of .andthen. required parenthesis, that would answer my question. Notice that ends the relevance of Ada to this thread, since we've already been told that Ada does require parentheses. With the required parentheses rule, the above would not be syntactiaclly allowed and you would have to write: call sub(x/=0 .AND_THEN. (n > 0 .AND. f(n) ) ) But the issue you are concerned with would still exist. I suppose *this* issue address might really be solved with reference to WHERE. -- 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] 18+ messages in thread
end of thread, other threads:[~2005-02-01 18:25 UTC | newest] Thread overview: 18+ 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 8:08 ` Martin Krischik 2005-02-01 1:43 ` James Giles 2005-02-01 2:33 ` James Van Buskirk 2005-02-01 2:53 ` James Giles 2005-02-01 3:49 ` James Van Buskirk 2005-02-01 4:31 ` James Giles
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox