Operators
DTRules includes 75+ operators for building conditions and actions. This reference
covers all standard operators organized by category. Many operators have multiple
syntax variants (e.g., and / &) for flexibility.
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) |
Arithmetic Examples
// Input: price = 100, quantity = 5, discount = 0.15
set subtotal = price * quantity // Result: 500
set discount_amount = subtotal * discount // Result: 75
set total = subtotal - discount_amount // Result: 425
set rounded = round of (total / 3) // Result: 142
set capped = min of (total, 400) // Result: 400
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 |
Comparison Examples
// Input: age = 25, status = "active", score = 85
age >= 18 // Result: true
age = 30 // Result: false
status != "pending" // Result: true
score >= 70 and score < 90 // Result: true (used with boolean)
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 |
Boolean Examples
// Input: is_member = true, is_active = true, is_suspended = false
is_member and is_active // Result: true
is_member or is_suspended // Result: true
not is_suspended // Result: true
is_member and not is_suspended // Result: true
is_member xor is_active // Result: false (both true)
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" |
String Examples
// Input: first_name = "John", last_name = "Smith", email = "JOHN@EXAMPLE.COM"
first_name + " " + last_name // Result: "John Smith"
length of last_name // Result: 5
uppercase of first_name // Result: "JOHN"
lowercase of email // Result: "john@example.com"
email contains "@" // Result: true
email ends with ".com" // Result: false (case sensitive, ends with ".COM")
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) |
Array Examples
// Input: items = ["apple", "banana", "cherry"], ages = [15, 22, 17, 30]
count of items // Result: 3
is empty items // Result: false
first of items // Result: "apple"
last of items // Result: "cherry"
any a in ages satisfies (a >= 21) // Result: true (22 and 30 qualify)
all a in ages satisfy (a >= 15) // Result: true
no a in ages satisfies (a > 50) // Result: true
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 |
Date Examples
// Input: birth_date = date("1990-06-15"), today = date("2024-03-20")
year of birth_date // Result: 1990
month of birth_date // Result: 6
birth_date + 18 years // Result: date("2008-06-15")
today - 30 days // Result: date("2024-02-19")
birth_date + 18 years < today // Result: true (person is over 18)
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 |
Control Flow Examples
// Conditional assignment
if age >= 18 then set category = "adult" else set category = "minor"
// Iterating over arrays
for each item in cart do
set item.total = item.price * item.quantity
done
// Calling another decision table
perform Calculate_Shipping
perform Apply_Discounts
Entity Operators
| Operator | Description | Example |
new | Create entity | new Person |
copy | Copy entity | copy of original |
type | Get entity type | type of entity |
Entity Examples
// Creating and copying entities
set customer = new Customer
set backup = copy of customer
set entity_type = type of customer // Result: "Customer"
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 |
Null Handling Examples
// Input: discount = null, name = "Alice"
discount is null // Result: true
name is not null // Result: true
discount otherwise 0 // Result: 0 (uses default)
name otherwise "Guest" // Result: "Alice" (uses actual value)
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 |
Type Conversion Examples
// Input: price_string = "99.50", quantity_string = "5", flag = "true"
integer of price_string // Result: 99 (truncated)
decimal of price_string // Result: 99.50
string of 42 // Result: "42"
boolean of flag // Result: true
integer of quantity_string * 10 // Result: 50
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