|
ION Script User's Guide: Variables, Expressions & Operators |
|
Operators are used to perform comparisons and mathematical operations on the terms of an expression. Operators are used between values or expressions in the general form value1 OP value2. Some operators only accept values of a certain type. If the value for a variable is not a type supported by the operation, the operation will fail.
ION Script's mathematical operators are listed in the following table.
ION Script's string operators are listed in the following table.
ION Script's comparison operators are listed in the following table.
ION Script's logical operators are listed in the following table. Note that values used with logical operators can be values, variables, or expressions, but they must evaluate to a boolean value.
The following are examples of valid expressions using the logical operators. For these examples, assume
$BOOL1 = true $BOOL2 = false $A = 1 $B = 2
Table 3-7: Logical Operator ResultsOperator Precedence
The following table lists the ION Script operators in order of precedence. All operators are left associative, meaning that operators of equal precedence (such as + and -) are evaluated from left to right.
Table 3-8: Operator Precedence
Table 3-8: Operator Precedence Precedence OperatorsHighest Lowest ( ) - (negation) ^ NOT *, /, MOD +, - GT, GE, LT, LE, CONTAINS, ISTYPE AND OR EQ, NE
Grouping Expressions With Parentheses
Parentheses are used in ION Script to control the order of evaluation of expressions. Expressions that are contained inside parentheses are evaluated first by ION Script. When multiple sets of parentheses are nested within one another, the expression contained in the innermost set of parentheses is evaluated first.
For example, consider the following code:
<ION_IF EXPR="$Month EQ 'April' OR $Month EQ 'May' AND $Temp EQ 70 ">This statement is equivalent to the following:
<ION_IF EXPR="$Month EQ 'April' OR ($Month EQ 'May' AND $Temp EQ 70)">If your intent was to require $Temp to be 70, but allow the $Month to be April or May, you would need to override the precedence as follows:
<ION_IF EXPR="($Month EQ 'April' OR $Month EQ 'May') AND $Temp EQ 70 ">
Tip
It is good programming practice to use parentheses to control the order of evaluation, even when not technically necessary. This ensures that your expressions are being evaluated in the order you intended, and makes your code more readable.
Examples
The following table gives several examples of the order in which expressions are evaluated in ION Script:
Table 3-9: Expression Evaluation
Table 3-9: Expression Evaluation Expression Result 10 * 5 - 2 48 10 * (5 - 2) 30 3 + 4 * 2 ^ 2 / 2 11 (3 + (4 * 2) ^ 2 / 2) 35
IDL Online Help (March 06, 2007)