Guenter, although you are correct with respect to Basic as implemented in AOO (and you stated it very well... I enjoyed your post), I am not aware of any other computer language where this is true. For example:

C and C++
http://en.cppreference.com/w/c/language/operator_precedence

Java is the same
https://docs.oracle.com/javase/tutorial/java/nutsandbolts/operators.html

Even VBA gives AND higher precedence than OR
https://msdn.microsoft.com/en-us/library/fw84t893.aspx

General comments on what is expected is listed here:

https://en.wikipedia.org/wiki/Order_of_operations

It is noted that APL, Smalltalk, and Occam do not have operator precedence. Can't say I have used APL in years (like 25 to 30 years). I have not used the other two.

The real question becomes.... should it be changed to follow expected mathematical norms (breaking all existing correct code and fixing all broken code where people assumed it was done in the generally accepted way). I am glad I need not make that call.

On 10/12/2015 08:15 PM, Guenter Marxen wrote:
Hi,

Am 12.10.2015 um 21:40 schrieb Mathias Röllig:
...
What do you expect?
For logical operations AND is equivalent to * and OR is equivalent to +.

no, that's not true. AND and OR have the same priority, just as * and / (division). (* and / have a higher priority than + and -.)

AND should have a higher priority than OR, so I would expect in both

Expressions have to be evaluated from left to right with respect to priority and parenthesis.

Only for those specific operators. And the complaint was that your statement is unexpectedly true.


"and" and "or" are binary operators. Therfore your examples can be written as "A or B" where "B = (C and D)". If you write your example as "A or (C and D)" then it is the same and everyone sees immediatly, how it is evaluated.

I wrote an implementation for a proposed international standard in Fortran 90 many years back.... It was suggested that I assume that people would not know precedence rules so that I should use parenthesis for all statements.... and that I should avoid things like ternary operators since beginning programmers may not know what they were.


In both cases, the result is TRUE, because
"TRUE or anything" is TRUE, just as "TRUE or (anything)".

"(A or B) and C" is totally different.

On http://www.p-roocks.de/truthtable2.php you can create "tables of truth" (Wahrheitstabellen) for logical expressions like "A or B and C" and more complex ones.

cases (because TRUE Or (<anything>) = TRUE):
bResult = TRUE
But you will get
TRUE Or FALSE And TRUE = (TRUE Or FALSE) And TRUE = TRUE
TRUE Or TRUE And FALSE = (TRUE Or TRUE) And FALSE = FALSE

Is there any explanation that AND and OR have (and should have) the same
priority?

It is as it is!

You are correct in that!

--
Andrew Pitonyak
My Macro Document: http://www.pitonyak.org/AndrewMacro.odt
Info:  http://www.pitonyak.org/oo.php


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@openoffice.apache.org
For additional commands, e-mail: dev-h...@openoffice.apache.org

Reply via email to