Progress
Results User’s Guide
for UNIX


Evaluating Expressions

When evaluating expressions, Results uses precedence in determining the result. Consider the following expression:

3 * 5 + 2

The result of this expression is different depending on the order that you process the multiplication and addition operators. For example, 3 * (5 + 2) is 21 but (3 * 5) + 2 is 17.

If an expression contains two operators of equal precedence, Results evaluates the expression from left to right. If the operators are not of equal precedence, Results evaluates the operator of higher precedence first. For example, Results evaluates AND before it evaluates OR. Also, you can use parentheses to change the default order used to evaluate an expression.

Table F–1 shows the precedence, or order of processing, of functions and operators.

Table F–1: Precedence of Functions and Operators 
Name of Operator
Precedence
- UNARY NEGATIVE
+ UNARY POSITIVE
7 (highest)
MODULO
/ DIVISION
* MULTIPLICATION
6
- DATE SUBTRACTION
- SUBTRACTION
+ DATE ADDITION
+ CONCATENATION
+ ADDITION
5
MATCHES
LT OR <
LE OR < =
GT OR >
GE OR > =
EQ OR =
NE < >
BEGINS
4
NOT
3
AND
2
OR
1 (lowest)

Rules

When using an operator, you must leave a space to the left and to the right of that operator. For example, here is a valid use of an operator:

x + y

Whereas, this is an invalid use of an operator:

x+y

Examples

Table F–2 provides examples to help illustrate how Results evaluates expressions.

Table F–2: Examples of Expressions 
Expression
Evaluation
2 * 7 + 2
By default, Results performs the multiplication first, then the addition. Therefore, it interprets this expression as being equal to 16.
(2 * 7) + 2
Results performs the operation inside the parentheses first. Therefore, it interprets this expression as being equal to16.
2 * (7 + 2)
Results performs the operation inside the parentheses first. Therefore, it interprets this expression as being equal to 18.
(St = “MA” OR St = “CA”)
AND Cust-num > 10
Results evaluates the expression inside the parentheses first. Therefore, this expression finds records in Massachusetts or California whose customer number is greater than 10.
Name BEGINS “p” OR
Name BEGINS “l” AND
State = “MA”
Results evaluates the AND before the OR. Therefore, this expression finds the records where the name begins with l that are in Massachusetts and groups them with all the records where the name begins with p. To find the records in Massachusetts where the names begin with l or p, you must use Expert Mode to group the expression with parentheses. For example: (Name BEGINS “p” OR Name BEGINS “l”) AND State = “MA”.


Copyright © 2004 Progress Software Corporation
www.progress.com
Voice: (781) 280-4000
Fax: (781) 280-4095