Operators
DTRules includes 179+ operators for building conditions and actions. This reference
covers the most commonly used operators organized by category.
Arithmetic Operators
| Operator | Description | Example |
+ | Addition | a + b |
- | Subtraction | a - b |
* | Multiplication | a * b |
/ | Division | a / b |
% | Modulo (remainder) | a % b |
abs | Absolute value | abs of value |
round | Round to nearest integer | round of value |
floor | Round down | floor of value |
ceiling | Round up | ceiling of value |
min | Minimum of two values | min of (a, b) |
max | Maximum of two values | max of (a, b) |
Comparison Operators
| Operator | Description | Example |
= | Equal to | age = 18 |
!= | Not equal to | status != "pending" |
< | Less than | income < threshold |
<= | Less than or equal | age <= 17 |
> | Greater than | count > 0 |
>= | Greater than or equal | age >= 18 |
Boolean Operators
| Operator | Description | Example |
and | Logical AND | a and b |
or | Logical OR | a or b |
not | Logical NOT | not a |
xor | Exclusive OR | a xor b |
& | AND (alternate syntax) | a & b |
| | OR (alternate syntax) | a | b |
! | NOT (alternate syntax) | !a |
String Operators
| Operator | Description | Example |
+ | Concatenation | first_name + " " + last_name |
length | String length | length of name |
substring | Extract substring | substring of name from 0 to 5 |
uppercase | Convert to uppercase | uppercase of text |
lowercase | Convert to lowercase | lowercase of text |
trim | Remove whitespace | trim of text |
contains | Check if contains substring | text contains "search" |
starts with | Check prefix | text starts with "pre" |
ends with | Check suffix | text ends with "fix" |
Array Operators
| Operator | Description | Example |
count | Number of elements | count of members |
is empty | Check if empty | is empty items |
is not empty | Check if not empty | is not empty items |
add | Add element | add item to list |
remove | Remove element | remove item from list |
clear | Remove all elements | clear list |
first | First element | first of items |
last | Last element | last of items |
any...satisfies | Exists check | any m in members satisfies (m.age >= 18) |
all...satisfy | Universal check | all m in members satisfy (m.valid) |
no...satisfies | None check | no m in members satisfies (m.rejected) |
Date Operators
| Operator | Description | Example |
date | Create date | date("2024-01-15") |
today | Current date | today |
year | Extract year | year of birth_date |
month | Extract month | month of birth_date |
day | Extract day | day of birth_date |
+ days | Add days | start_date + 30 days |
+ months | Add months | start_date + 6 months |
+ years | Add years | birth_date + 18 years |
- days | Subtract days | end_date - 7 days |
Control Flow Operators
| Operator | Description | Example |
if...then | Conditional | if age >= 18 then set adult = true |
if...then...else | Conditional with else | if a then x else y |
for each...do...done | Iterate array | for each m in members do ... done |
perform | Call decision table | perform Calculate_Tax |
set | Assignment | set total = subtotal * tax |
Entity Operators
| Operator | Description | Example |
new | Create entity | new Person |
copy | Copy entity | copy of original |
type | Get entity type | type of entity |
Null Handling Operators
| Operator | Description | Example |
is null | Check for null | value is null |
is not null | Check for not null | value is not null |
otherwise | Default value | value otherwise 0 |
Type Conversion Operators
| Operator | Description | Example |
integer | Convert to integer | integer of value |
decimal | Convert to decimal | decimal of value |
string | Convert to string | string of value |
boolean | Convert to boolean | boolean of value |
Operator Precedence
From highest to lowest precedence:
- Parentheses
() - Unary operators
not, - - Multiplication, division
*, /, % - Addition, subtraction
+, - - Comparison
=, !=, <, >, <=, >= - Boolean AND
and - Boolean OR
or
Use parentheses when precedence is unclear:
// Clear
(a + b) * c
a and (b or c)
// Ambiguous - use parentheses
a + b * c // Is this (a + b) * c or a + (b * c)?
Next Steps