Focal Point Banner


As of December 1, 2020, Focal Point is retired and repurposed as a reference repository. We value the wealth of knowledge that's been shared here over the years. You'll continue to have access to this treasure trove of knowledge, for search purposes only.

Join the TIBCO Community
TIBCO Community is a collaborative space for users to share knowledge and support one another in making the best use of TIBCO products and services. There are several TIBCO WebFOCUS resources in the community.

  • From the Home page, select Predict: WebFOCUS to view articles, questions, and trending articles.
  • Select Products from the top navigation bar, scroll, and then select the TIBCO WebFOCUS product page to view product overview, articles, and discussions.
  • Request access to the private WebFOCUS User Group (login required) to network with fellow members.

Former myibi community members should have received an email on 8/3/22 to activate their user accounts to join the community. Check your Spam folder for the email. Please get in touch with us at community@tibco.com for further assistance. Reference the community FAQ to learn more about the community.


Focal Point    Focal Point Forums  Hop To Forum Categories  WebFOCUS/FOCUS Forum on Focal Point     [SOLVED] Logical operator precedence

Read-Only Read-Only Topic
Go
Search
Notify
Tools
[SOLVED] Logical operator precedence
 Login/Join
 
Virtuoso
posted
I'm looking at an existing piece of code here (not mine) trying to figure out how it evaluates...

It contains something along these lines:
DEFINE FILE x
A/I1 = IF expr1 AND expr2 OR expr3 THEN 1 ELSE 0;
END

Does that logical expression evaluate as:

  • (expr1 AND expr2) OR expr3, or as
  • expr1 AND (expr2 OR expr3)?


Can you also explain why it evaluates to that one instead of the other?


In the Help I found this list of logical expressions: Creating Reports With Report Painter > Writing Expressions > Writing Logical Expressions

But it doesn't say in what order they get evaluated or what their precedence is.

This message has been edited. Last edited by: Wep5622,


WebFOCUS 8.1.03, Windows 7-64/2008-64, IBM DB2/400, Oracle 11g & RDB, MS SQL-Server 2005, SAP, PostgreSQL 11, Output: HTML, PDF, Excel 2010
: Member of User Group Benelux :
 
Posts: 1669 | Location: Enschede, Netherlands | Registered: August 12, 2010Report This Post
Gold member
posted Hide Post
I think if you do not provide any distribution of conditions through brackets, WF treates the expression as option 2.


Webfocus 7.7.03
Windows XP
Excel, PDF, HTML, APDF, AHTML, Maintain
 
Posts: 59 | Registered: July 22, 2009Report This Post
Virtuoso
posted Hide Post
Okay, thanks. That would mean that OR has precedence over AND.


WebFOCUS 8.1.03, Windows 7-64/2008-64, IBM DB2/400, Oracle 11g & RDB, MS SQL-Server 2005, SAP, PostgreSQL 11, Output: HTML, PDF, Excel 2010
: Member of User Group Benelux :
 
Posts: 1669 | Location: Enschede, Netherlands | Registered: August 12, 2010Report This Post
Master
posted Hide Post
Assuming WF uses the same precendence as the other languages, the order would be:
(),NOT,AND,OR


_____________________
WF: 8.0.0.9 > going 8.2.0.5
 
Posts: 668 | Location: Veghel, The Netherlands | Registered: February 16, 2010Report This Post
Virtuoso
posted Hide Post
Of course, you could also try to create a small procedure to check the precedence, like:
DEFINE FILE CAR
A/A1 = IF COUNTRY EQ 'ENGLAND' AND CAR EQ 'TRIUMPH' OR BODYTYPE EQ 'COUPE' THEN 'A' ELSE ' ';
B/A1 = IF (COUNTRY EQ 'ENGLAND' AND CAR EQ 'TRIUMPH') OR BODYTYPE EQ 'COUPE' THEN 'B' ELSE ' ';
C/A1 = IF COUNTRY EQ 'ENGLAND' AND (CAR EQ 'TRIUMPH' OR BODYTYPE EQ 'COUPE') THEN 'C' ELSE ' ';
END
TABLE FILE CAR
PRINT COUNTRY CAR BODYTYPE A B C
END
and then see what happens...


GamP

- Using AS 8.2.01 on Windows 10 - IE11.
in Focus since 1988
 
Posts: 1961 | Location: Netherlands | Registered: September 25, 2007Report This Post
Virtuoso
posted Hide Post
I couldn't come up with a simple reliable test-case, my brain is currently too numb with a lot of DIY-work at home after my day-job...

An extra benefit is of course that this is now documented in Google.

The results are:
  COUNTRY     CAR               BODYTYPE      A  B  C                                                                             
  -------     ---               --------      -  -  -                                                                             
  ENGLAND     JAGUAR            CONVERTIBLE          
  ENGLAND     JAGUAR            SEDAN                
  ENGLAND     JENSEN            SEDAN                
  ENGLAND     TRIUMPH           HARDTOP       A  B  C
  JAPAN       DATSUN            SEDAN                
  JAPAN       TOYOTA            SEDAN                
  ITALY       ALFA ROMEO        SEDAN                
  ITALY       ALFA ROMEO        COUPE         A  B   
  ITALY       ALFA ROMEO        ROADSTER             
  ITALY       MASERATI          COUPE         A  B   
  W GERMANY   AUDI              SEDAN                
  W GERMANY   BMW               SEDAN                
  W GERMANY   BMW               SEDAN                
  W GERMANY   BMW               SEDAN                
  W GERMANY   BMW               SEDAN                
  W GERMANY   BMW               SEDAN                
  W GERMANY   BMW               SEDAN                
  FRANCE      PEUGEOT           SEDAN                


From which the conclusion can be drawn that AND takes precedence over OR, as implementations 'A' and 'B' behave the same.


WebFOCUS 8.1.03, Windows 7-64/2008-64, IBM DB2/400, Oracle 11g & RDB, MS SQL-Server 2005, SAP, PostgreSQL 11, Output: HTML, PDF, Excel 2010
: Member of User Group Benelux :
 
Posts: 1669 | Location: Enschede, Netherlands | Registered: August 12, 2010Report This Post
Virtuoso
posted Hide Post
quote:
Assuming WF uses the same precendence as the other languages, ...


The headwaters of FOCUS expression semantics lie in FORTRAN.
(And Dialog Manager syntax is rooted in VM's EXEC I, but that's another discussion).


Just to eliminate the possibility that FOCUS gives AND and OR equal precedence, combining the terms in lexical order (a la APL, my eldest son's first computer language):

DEFINE FILE CAR
A/A1 = IF (COUNTRY EQ 'ENGLAND') AND (CAR EQ 'TRIUMPH') OR (BODYTYPE EQ 'COUPE') THEN 'A' ELSE ' ';
a/A1 = IF (BODYTYPE EQ 'COUPE') OR (CAR EQ 'TRIUMPH') AND (COUNTRY EQ 'ENGLAND') THEN 'a' ELSE ' ';
B/A1 = IF (COUNTRY EQ 'ENGLAND' AND CAR EQ 'TRIUMPH') OR BODYTYPE EQ 'COUPE' THEN 'B' ELSE ' ';
C/A1 = IF COUNTRY EQ 'ENGLAND' AND (CAR EQ 'TRIUMPH' OR BODYTYPE EQ 'COUPE') THEN 'C' ELSE ' ';
END
TABLE FILE CAR
PRINT COUNTRY CAR BODYTYPE A a B C
END

a is seen as equivalent to A, so the equivalence to B is (indeed) based on precedence rather than lexical order


- Jack Gross
WF through 8.1.05
 
Posts: 1925 | Location: NYC | In FOCUS since 1983 | Registered: January 11, 2005Report This Post
Virtuoso
posted Hide Post
I knew there was more to it! Thanks for confirming that.


WebFOCUS 8.1.03, Windows 7-64/2008-64, IBM DB2/400, Oracle 11g & RDB, MS SQL-Server 2005, SAP, PostgreSQL 11, Output: HTML, PDF, Excel 2010
: Member of User Group Benelux :
 
Posts: 1669 | Location: Enschede, Netherlands | Registered: August 12, 2010Report This Post
Master
posted Hide Post
Obligitory posting that it is always best practice to use brackets to group items so they are are forced to eval as intended versus relying on the interpreter to do the needful.

Or, as your coworker: Make this easy so I don't have to think about it.

- ABT


------------------------------------
WF Environment:
------------------------------------
Server/Client, ReportCaster, Dev Studio: 7.6.11
Resource Analyzer, Resource Governor, Library, Maintain, InfoAssist
OS: Windows Server 2003
Application/Web Server: Tomcat 5.5.25
Java: JDK 1.6.0_03
Authentication: LDAP, MRREALM Driver
Output: PDF, EXL2K, HTM

------------------------------------
Databases:
------------------------------------
Oracle 10g
DB2 (AS/400)
MSSQL Server 2005
Access/FoxPro
 
Posts: 561 | Registered: February 03, 2010Report This Post
  Powered by Social Strata  

Read-Only Read-Only Topic

Focal Point    Focal Point Forums  Hop To Forum Categories  WebFOCUS/FOCUS Forum on Focal Point     [SOLVED] Logical operator precedence

Copyright © 1996-2020 Information Builders