Expressions — Advanced topics |
This topic describes details of expression evaluation. If you're experienced in Java, note that most behavior of PRPC expressions correspond to the Java Language Specification, Chapter 15.
Expressions are evaluated as follows:
@if()
, @and()
, and @or()
, and the conditional operators (&&
, ||
and ?:
) only those operands needed to determine the true or false result are evaluated.Add (+) and subtract (-) operations
This table shows the valid combinations of types when the operator is + or -. To understand the calculation of the expression A + B, find the type of A in the Left Hand Side (rows) of each table. Find the type of B in the Right Hand Side (columns) if the table. Consult the numbered notes for the details of casting or conversion.
Right Hand Side |
|
|
|
|
|
|
|
Other (text) |
Left Hand Side |
||||||||
|
3 |
3 |
3 |
5 |
5 |
5 |
X |
1 |
|
X |
3 |
4 |
5 |
5 |
5 |
X |
1 |
|
X |
4 |
3 |
X |
5 |
5 |
X |
1 |
|
5 |
5 |
X |
2 |
2 |
2 |
X |
1 |
|
5 |
5 |
5 |
2 |
2 |
2 |
X |
1 |
|
5 |
5 |
5 |
2 |
2 |
2 |
X |
1 |
|
X |
X |
X |
X |
X |
X |
X |
1 |
Other (text) |
1 |
1 |
1 |
1 |
1 |
1 |
1 |
1 |
X indicates that a casting, promotion or conversion is not supported. PRPC reports an error.
+
, performs Java String concatenation (result is of mode Single Value
). The minus operator (-
) is not permitted.Integer
> Double
> Decimal
until both operands have same type, then perform operation. Result is of the promoted type. (Converts directly to the target type without performing intermediate conversions.)+
operator is not permitted. The -
operator converts operands to Decimal
and performs the operation, yielding Decimal
number of days and fraction of day.+
operator converts operands to Decimal
and performs the operation, yielding a DateTime
with GMT assumed. The - operator is not permitted.Decimal
and performs the operation, yielding a Date
(rounded), Time of Day
or DateTime
(depending upon type of original non-numeric operand)Multiply, divide, and remainder operations (*, /, %)
This table shows the valid combinations of types when the operator is *, / or %. To understand the calculation of the expression A * B, find the type of A in the Left Hand Side (rows) of each table. Find the type of B in the Right Hand Side (columns) if the table. Consult the numbered notes for the details of casting or conversion.
Right Hand Side |
|
|
|
|
|
|
|
Other (text) |
Left Hand Side |
||||||||
|
X |
X |
X |
X |
X |
X |
X |
X |
|
X |
X |
X |
X |
X |
X |
X |
X |
|
X |
X |
X |
X |
X |
X |
X |
X |
|
X |
X |
X |
1 |
1 |
1 |
X |
X |
|
X |
X |
X |
1 |
1 |
1 |
X |
X |
|
X |
X |
X |
1 |
1 |
1 |
X |
X |
|
X |
X |
X |
X |
X |
X |
X |
X |
Other (text) |
X |
X |
X |
X |
X |
X |
X |
X |
Notes for multiplication, division, and remainder operations:
Integer > Double > BigDecimal
until both operands have same type, then perform operation. The result is of the promoted type. (Conversion is directly to target type without performing additional intermediate conversions.)@divide
(dividend, divisor, mode) with Integer
or Decimal
operations to compute a result that contains at least two decimal places and rounds half values up: @divide(10, 6) = 1.67. Rounding modes are the same as for the BigDecimal class:
ceiling
— round to a more positive integerdown
— round towards zerofloor
— round to a more negative numberhalf_down
— round to the nearest neighbor, where an equidistant value is rounded downhalf_even
— round to the nearest neighbor, where an equidistant value is rounded to an even valuehalf_up
— round to the nearest neighbor, where an equidistant value is rounded upunnecessary
— assert that no rounding is necessaryup
— round away from zeroComparison operators (<, <=, >=, ==, !=, ...)
This table shows the valid combinations of types for comparison operators. To understand the calculation of the expression A > B, find the type of A in the Left Hand Side (rows) of each table. Find the type of B in the Right Hand Side (columns) if the table. Consult the numbered notes for the details of casting or conversion.
The operator ~=
evaluates using equalsIgnoreCase()
.
Right Hand Side |
|
|
|
|
|
|
|
Other (text) |
Left Hand Side |
||||||||
|
1 |
3 |
X |
3 |
3 |
3 |
X |
X |
|
3 |
1 |
X |
3 |
3 |
3 |
X |
X |
|
X |
X |
1 |
X |
3 |
3 |
X |
X |
|
3 |
3 |
X |
2 |
2 |
2 |
X |
X |
|
3 |
3 |
3 |
2 |
2 |
2 |
X |
X |
|
3 |
3 |
3 |
2 |
2 |
2 |
X |
X |
|
X |
X |
X |
X |
X |
X |
4 |
X |
Other (text) |
X |
X |
X |
X |
X |
X |
X |
5 |
Legend:
X |
A casting, promotion, or conversion is not supported. PRPC reports an error. |
1 |
Permitted. Depending upon complexity of expression and intermediate conversions that may have occurred, use either the original ClipboardProperty String form or Java |
2 |
Permitted. Converts |
3 |
Permitted. Converts to the preferred Java type (and if necessary, promote as described in note 2) and performs the operation. |
4 |
Permitted. Converts to Java boolean and performs the operation. |
5 |
Permitted. Evaluate using |