Engine

3.1. Values🔗

What rules compute with: literals, fields, arithmetic and a few functions. The written forms and the runtime values:

🔗inductive type

A value expression: an expression in rule text that evaluates to a Value (which may be null).

Spec.ValueExpr.field (f : String) : ValueExpr

bare field: field of the picked event; in per, a named value

Spec.ValueExpr.incoming (f : String) : ValueExpr

$field: field of the incoming event (preconditions only; in on the incoming event is also the picked one)

Spec.ValueExpr.lit (v : Value) : ValueExpr

a literal: 500, 'Minibar', 2026-12-01

Spec.ValueExpr.arith (op : ArithOp) (a b : ValueExpr) :
  ValueExpr

a + b, a - b, a * b, a / b

Spec.ValueExpr.fn (f : Fn) (a : ValueExpr) : ValueExpr

round(a), floor(a), ceil(a), lower(a), weekday(a), day(a), time_of_day(a)

Spec.ValueExpr.range (a b : ValueExpr) : ValueExpr

range(a, b), end excluded

Spec.ValueExpr.dur (n : Nat) (u : TimeUnit) : ValueExpr

90 days

Spec.ValueExpr.now : ValueExpr

now(): the incoming event's at (preconditions only)

Spec.ValueExpr.lastField (s : Selector) (f : String) :
  ValueExpr

(last of s).field

Spec.ValueExpr.sum (s : Selector) (f : String) : ValueExpr

sum(T.f) is sum (type T) f; sum((T where c today).f) is sum (window (filter (type T) c) today) f

Spec.ValueExpr.count (s : Selector) : ValueExpr

count(s): how many events s picks

Spec.ValueExpr.min (s : Selector) (f : String) : ValueExpr

min((S).f): like sum; null if no picked event has a non-null f

Spec.ValueExpr.max (s : Selector) (f : String) : ValueExpr

max((S).f): like min, the largest

🔗inductive type
Spec.Value : Type
Spec.Value : Type

Runtime values. Numbers are exact fractions, unbounded (Rat; a decimal input 12.50 is 1250/100). Timestamps are exact fractions of a microsecond since 1970-01-01T00:00:00Z (UTC), dates are days since 1970-01-01, durations are exact fractions of a microsecond: nothing is ever rounded. Date ranges are half-open [lo, hi).

Spec.Value.null : Value

a missing field, last of with nothing picked, undefined arithmetic

Spec.Value.bool (b : Bool) : Value

true, false

Spec.Value.num (q : Rat) : Value

an exact fraction

Spec.Value.str (s : String) : Value

text

Spec.Value.timestamp (micros : Rat) : Value

microseconds since 1970-01-01T00:00:00Z, exact

Spec.Value.date (days : Int) : Value

days since 1970-01-01

Spec.Value.dur (micros : Rat) : Value

microseconds, exact

Spec.Value.dateRange (lo hi : Int) : Value

the dates lo up to, not including, hi

3.1.1. Null and division🔗

A value that is missing is null; arithmetic with null gives null, and so does a division by zero. Division is exact, never rounded. Written in a rule:

Rule text

Value

Claim

1 / 0

null

One divided by zero is null.

(last of Missing).x + 1

null: no event is picked, so x is null

A missing value plus one is null.

1 / 3 * 3

1, exactly

One third times three is one.

3.1.2. Rounding🔗

Only round, floor and ceil round; they give whole numbers. round goes half away from zero.

Rule text

Value

Claim

round(2.5), round(0 - 2.5)

3, -3

Round of 2 5 is 3 and of minus 2 5 is minus 3.

floor(2.9), ceil(2.1)

2, 3

Floor of 2 9 is 2 and ceil of 2 1 is 3.

3.1.3. Text🔗

lower lowercases text, for comparing emails that differ in case.

Rule text

Value

Claim

lower('Ann@X.ch')

ann@x.ch

Lower of a mixed case email is lowercase.

3.1.4. Timestamps and durations🔗

A timestamp plus a duration is a timestamp, a date plus days is a date; two timestamps subtract to a duration. A week is 7 days and a month 30, whatever the calendar says.

Rule text

Value

Claim

2026-12-01T10:00:00Z + 1 day

2026-12-02T10:00:00Z

A day after a timestamp is the same time the next day.

2026-12-01 + 3 days

2026-12-04

Three days after a date is the date three days later.

1 week, 1 month

7 days, 30 days

A week is 7 days and a month is 30 days.

The units:

Arithmetic:

3.1.5. Calendar functions🔗

Three functions read the calendar, in UTC: weekday(d) is the weekday of a date (1 to 7, Monday = 1), day(t) the date of a timestamp, time_of_day(t) the duration since that date's midnight. Their names stay usable as field names: they are functions only when ( follows. Shifts start Monday to Friday, at 06:00 or later:

    - on: ShiftCreated
      requires: weekday(day($starts_at)) <= 5 and time_of_day($starts_at) >= 6 hours

3.1.6. Ranges🔗

A range of dates is every date from the first up to, not including, the second. It is used with each in a grouped invariant, for example one booking per room and night.

Rule text

Value

Claim

range(2026-12-01, 2026-12-04)

the dates 1, 2 and 3 December

The range from the 1st to the 4th of december has 3 days.