Code Comments
Programming Forum and web based access to our favorite programming groups.I'm reading COBOL program and can't make sure the meaning of the following abbreviated condition: If A NOT = B AND NOT C Is it equivalent to If A NOT = B AND A = C or If A NOT = B AND A NOT = C ??? Thanks in advance. Thomas Li
Post Follow-up to this messageThomas A. Li <tli@corporola.com> wrote in message news:SN1Ac.4490$7C%1.498@news04.bloor.is. net.cable.rogers.com... > I'm reading COBOL program and can't make sure the meaning of the following > abbreviated condition: > > If A NOT = B AND NOT C > > Is it equivalent to > > If A NOT = B AND A = C No > > or > > If A NOT = B AND A NOT = C ??? Yes Now try IF NOT A = B OR C This ambiguity should convince you NOT to use abbreviation. It can be fatal .
Post Follow-up to this messageOn 16-Jun-2004, "Thomas A. Li" <tli@corporola.com> wrote: > I'm reading COBOL program and can't make sure the meaning of the following > abbreviated condition: Remember this. If the code isn't obvious, then the programmer should have made it obvious. That's a major feature of good CoBOL design. > If A NOT = B AND NOT C > > Is it equivalent to > > If A NOT = B AND A = C > > or > > If A NOT = B AND A NOT = C ??? See if this link helps: http://publibz.boulder.ibm.com/cgi-...927030801&CASE= Unless modified by parentheses, the following precedence rules (from highest to lowest) apply: Arithmetic operations Simple conditions NOT AND OR
Post Follow-up to this messageNope... try it... these are all true. identification division. program-id. testit. environment division. working-storage section. 01 . 05 A pic 9 value 1. 05 B pic 9 value 2. 05 C pic 9 value 1. procedure division. 000-main. if A not = B and not C display 'True'. if not A = B or C display 'True'. if A not = B and A = C display 'True'. goback.
Post Follow-up to this messageAll three standards have an example of an Abbreviated Combined Relation Condition that can be used to figure this out definitively. This example appears in ISO/IEC 1989:2002 on Page 137; in ANSI X3.23-1985 on Page VI-61; and in ANSI X3.23-1974 on Page II-48. This example is the last in a group of Abbreviated Combined Relation Condition examples: NOT (a NOT > b AND c AND NOT d) and it is explicitly described as equivalent to NOT ((((a NOT > b) AND (a NOT > c)) AND (NOT (a NOT > d)))) As I see it: Dropping the outer NOT, this becomes: a NOT > b AND c AND NOT d which is interpreted as (((a NOT > b) AND (a NOT > c)) AND (NOT (a NOT > d ))) Dropping the inner "AND c", we get a NOT > b AND NOT d which is interpreted as ((a NOT > b) AND (NOT (a NOT > d))) Now, making the appropriate operator and letter substitutions in the example, A NOT = B AND NOT C is correctly interpreted as (A NOT = B) AND (NOT (A NOT = C)). Because "NOT (A NOT = C) is the same as "A = C" in this case, the original IF becomes IF (A NOT = B) AND (A = C) ... which is, of course. IF A NOT = B AND A = C ... Many people assume that abbreviation implies some sort of override of the normal precedence rules that doesn't apply when the full specification (without parentheses) is used. 'T'aint so. "NOT =" is a *simple* relational operator in 2002-speak. "NOT [implied subject] [implied relational] C" is "NOT (A NOT = C)" when [implied subject] is "A" and [implied relational] is "NOT =". Lest anyone misunderstand: I Do Not Like Abbreviated Combined Relation Conditions. The 2002 standard warns, just before the examples of abbreviated combined relation conditions: "NOTE The use of NOT often leads to results that are not intuitive and therefore it should be avoided." -Chuck Stevens "Thomas A. Li" <tli@corporola.com> wrote in message news:SN1Ac.4490$7C%1.498@news04.bloor.is.net.cable.rogers.com... > I'm reading COBOL program and can't make sure the meaning of the following > abbreviated condition: > > If A NOT = B AND NOT C > > Is it equivalent to > > If A NOT = B AND A = C > > or > > If A NOT = B AND A NOT = C ??? > > > > Thanks in advance. > > > > Thomas Li > > > >
Post Follow-up to this messageWell you could also interpret it this way: if (value 1 not = value 2) and (not condition c) We have programs that are doing something like: if (field 1 not = field 2) and (not print-detail) do procedure end-if. How that may be interpreted is you are doing a variable comparison and you are checking for false condition. Usually with an 88 level condition you are checking for true or a true condition but in the statement above you are checking for a false condition. I was dealing with a program statement similar to this last w. "Thomas A. Li" <tli@corporola.com> wrote in message news:SN1Ac.4490$7C%1.498@news04.bloor.is.net.cable.rogers.com... > I'm reading COBOL program and can't make sure the meaning of the following > abbreviated condition: > > If A NOT = B AND NOT C > > Is it equivalent to > > If A NOT = B AND A = C > > or > > If A NOT = B AND A NOT = C ??? > > > > Thanks in advance. > > > > Thomas Li > > > >
Post Follow-up to this message"Chuck Stevens" <charles.stevens@unisys.com> wrote > "NOTE The use of NOT often leads to results that are > not intuitive and therefore it should be avoided." I am not quite understanding that, does it mean ?: NOT ( intuitive and therefore it should be avoided ) -> ( NOT intuitive ) OR ( should NOT be avoided )
Post Follow-up to this message"Chuck Stevens" <charles.stevens@unisys.com> wrote: >The 2002 standard warns, just before the examples of abbreviated combined >relation conditions: "NOTE The use of NOT often leads to results that ar e >not intuitive and therefore it should be avoided." One of the Great Problems in programming is that intuition is fails us on lo gic problems even slightly complex, especially when they include NOT. People who argue for 'the best tool for the job' ignore their own advice whe n they stubbornly try to handle such problems with Common Sense and refuse to learn Boolean Algebra. If we are going to spend our lives dealing with logic problems, it seems reasonable to expect the necessary skills. Conversational English is simply inadequate.
Post Follow-up to this messageSo long as you use parentheses to establish the relation conditions and to define their precedence, that's not a problem. The issue is the sometimes-counterintuitive rules surrounding NOT in an *abbreviated combined relation condition* in combination with the fact that abbreviation does not impact precedence at all. It is in the smaller context of abbreviated conditions that the suggestion to avoid NOT is made in the 2002 standard. -Chuck Stevens "Charles W. Cribbs II" <charlescribbs@earthlink.net> wrote in message news:Ip5Ac.13505$Y3.100@newsread2.news.atl.earthlink.net... > Well you could also interpret it this way: > > if (value 1 not = value 2) and > (not condition c) > > We have programs that are doing something like: > > if (field 1 not = field 2) and > (not print-detail) > do procedure > end-if. > > How that may be interpreted is you are doing a variable comparison and you > are checking for false condition. Usually with an 88 level condition you > are checking for true or a true condition but in the statement above you are > checking for a false condition. I was dealing with a program statement > similar to this last w. > > > "Thomas A. Li" <tli@corporola.com> wrote in message > news:SN1Ac.4490$7C%1.498@news04.bloor.is.net.cable.rogers.com... following > >
Post Follow-up to this messageThomas A. Li wrote: > I'm reading COBOL program and can't make sure the meaning of the following > abbreviated condition: > > If A NOT = B AND NOT C Is this an abbreviated condition? It looks like "C" is a condition name, not another variable with a value. It's missing the "=" between "NOT" and "C". > Is it equivalent to > > If A NOT = B AND A = C > > or > > If A NOT = B AND A NOT = C ??? So, if my above premise is true, no, they are not equivalent. If it said something like If A NOT = B AND C then your restatement #2 above would be equivalent. -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~ ~ / \ / ~ Live from Montgomery, AL! ~ ~ / \/ o ~ ~ ~ / /\ - | ~ LXi0007@Netscape.net ~ ~ _____ / \ | ~ http://www.knology.net/~mopsmom/daniel ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ I do not read e-mail at the above address ~ ~ Please see website if you wish to contact me privately ~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~
Post Follow-up to this messagePowered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.