Expressions Reference

Operators, quantifiers, aggregations, and collection handling in SEA™ DSL.


Operators

Arithmetic

+   # Addition
-   # Subtraction
*   # Multiplication
/   # Division

Comparison

>   # Greater than
<   # Less than
>=  # Greater or equal
<=  # Less or equal
=   # Equal
!=  # Not equal

Logical

and   # Logical AND
or    # Logical OR
not   # Logical NOT

Special

contains    # String/array contains
startswith  # String prefix
endswith    # String suffix
matches     # Regex match
before      # Temporal before
after       # Temporal after
during      # Temporal during
has_role    # Role check

Precedence (High to Low)

  1. Parentheses ()
  2. Member access .
  3. Cast
  4. Unary operators
  5. Multiplicative *, /
  6. Additive +, -
  7. Comparison >, <, >=, <=, =, !=
  8. not
  9. and
  10. or

Quantifiers

forall

Check condition for all elements:

forall x in <collection>: (<expression>)

Examples:

// All flows have positive quantity
forall f in flows: (f.quantity > 0)

// All orders have customer
forall o in entities where o.name = "Order": (o.customer != null)

exists

Check if at least one element satisfies condition:

exists x in <collection>: (<expression>)

Examples:

// At least one admin exists
exists r in roles: (r.name = "Admin")

// At least one payment flow exists
exists f in flows where f.resource = "Money": true

Collections

Built-in collections:

Collection Contains
flows All Flow declarations
entities All Entity declarations
resources All Resource declarations
instances All Instance declarations
relations All Relation declarations

Filtering:

forall f in flows where f.resource = "Money": (f.quantity > 0)

Aggregations

Functions

Function Description
count Number of elements
sum Sum of values
min Minimum value
max Maximum value
avg Average value

Comprehension Syntax

fn(x in <collection> [over last N "unit"]
   [where <condition>] :
   <expression>)

Examples:

// Count all flows
count(f in flows: 1)

// Sum payment amounts
sum(f in flows where f.resource = "Money": f.quantity)

// Average order value over last 30 days
avg(o in entities over last 30 "days"
    where o.name = "Order":
    o.amount)

// Max quantity
max(f in flows: f.quantity)

Group By

group_by(x in <collection> [where <condition>] : <key>)
{ <aggregation_expression> }

Example:

// Group flows by resource and count
group_by(f in flows: f.resource)
{ count(f: 1) }

Instance References

Reference specific instances with @:

instance order123 of "Order" {
  amount: 100 "USD",
  status: "pending"
}

// Reference in expression
Policy order_check as: (@order123.amount > 50)

Policy Expression Examples

Simple Constraint

Policy positive_amount as: (amount >= 0)

Collection Constraint

Policy all_flows_positive as:
  forall f in flows: (f.quantity > 0)

Conditional Constraint

Policy large_orders_require_approval as:
  forall o in entities where o.name = "Order" and o.amount > 10000:
    (o.approved = true)

Existence Check

Policy payment_exists as:
  exists f in flows where f.resource = "Money": (f.quantity > 0)

Combined Quantifiers

Policy order_has_payment as:
  forall o in flows where o.name = "PlaceOrder":
    exists p in flows where p.name = "ProcessPayment":
      (p.orderId = o.orderId)

Metric Expression Examples

Metric "total_revenue" as:
  sum(f in flows where f.resource = "Money": f.quantity)
  @unit "USD"

Metric "daily_orders" as:
  count(o in entities over last 24 "hours"
        where o.name = "Order": 1)
  @window 24 "hours"
  @threshold 100

Last Updated: January 2026