Operators#

Precedence#

The levels are LGRA.9.2.1. Parentheses override precedence at any level. Operand and result types are at Operator result types.

(Spec: [LEXP.1.1], [LEXP.1.4], [LEXP.12.2])

Comparison and bitwise levels#

Comparisons bind looser than every bitwise operator and tighter than not: a & 0x4 != 0 is (a & 0x4) != 0, and not a < b is not (a < b).

(Spec: [LEXP.1.2])

Exponent level#

** binds tighter than a unary operator on its left, accepts any expression on its right, and is right-associative: -2 ** 3 is -(2 ** 3), 2 ** -3 is 0.125, and 2 ** 3 ** 2 is 2 ** 9.

(Spec: [LEXP.1.3])

Postfix level#

Member access ., index [ ], call ( ) and the cast :: bind tighter than every prefix and infix operator.

(Spec: [LEXP.1.5])

Comparison chains#

a <op1> b <op2> c …

An expression with any number of comparison operators, which is the conjunction of the pairwise comparisons on consecutive terms.

A chain of N comparisons produces N−1 tests. Any comparison operator stands at any position: a < b > c is (a < b) and (b > c). a < b < c states nothing about a and c. Chain length has no limit.

0 <= r.n < 10

(Spec: [LEXP.2.1], [LEXP.2.2.1], [LEXP.2.2.2], [LEXP.2.2.3], [LEXP.2.3.1], [LEXP.2.4.1])

Members#

receiver.NAME, receiver.NAME(args)

A .NAME call on a receiver whose type is known statically is a member read, resolved by the receiver’s type. A name the type does not carry is refused with DS_VALIDATE_UNKNOWN_MEMBER.

The Int members are at Integer members.

(Spec: [LEXP.7.18], [LGRA.9.6.2])

Expression positions#

One grammar, precedence and set of type rules hold across all positions.

(Spec: [LEXP.12.1])

Where an expression is refused#

  • a pattern’s slot value;

  • a schema declaration, a series declaration or configuration, which take compile-time literals.

Each is a compile error, and arithmetic in a pattern’s slot value or a schema declaration is a parse error. A duration position takes a time_expr, not an expression.

(Spec: [LEXP.8.5], [LEXP.8.6], [LEXP.8.7], [LEXP.8.9.2], [LEXP.10.2.5])

const right-hand side#

A compile-time-constant expression over literals, earlier constants and imported constants:

  • arithmetic, comparison, bitwise and shift operators, and, or and not;

  • unit literals, same-dimension conversion and unit assertions;

  • the global math builtins, and math, distance and calendar members over constant operands.

A member call whose fold would raise is not foldable. Any construct that needs a runtime value is refused with DS_VALIDATE_CONST_NOT_FOLDABLE, naming the construct.

The declaration’s form is at Constant declarations.

(Spec: [LEXP.8.8])

log argument#

The log action head takes one string, literal or interpolated. log info (2 + 2) is a parse error.

(Spec: [LEXP.8.9.1])

Interactions#

Re-evaluation of a where under a logical emit is at Time-dependent tests, and dwell at dwell.

Series aggregations#

A series aggregation is a function-call atom that composes freely in an expression. Its value is recomputed at each test.

(Spec: [LEXP.9.2.1], [LEXP.9.2.2])

where on a join#

A where on a rule with more than one positive pattern does not read state that is not a function of the matched facts. The scope is the rule: a where attached to one pattern is refused as one naming bindings from two is.

Read

Code

a clock read (now(), monotonic_ns(), dwell), a series read or a zone read

DS_VALIDATE_NOW_MULTIPATTERN_UNSUPPORTED

cached(key)

DS_VALIDATE_NONFACT_WHERE_MULTIPATTERN

A rule with one positive pattern is unaffected, and so is a let.

Refused with DS_VALIDATE_NOW_MULTIPATTERN_UNSUPPORTED

rule stale:
    Reading a
    Reading b where now() > a.ts and b.id == a.id
->
    log info "stale"

(Spec: [LEXP.9.6.1], [LTIM.2.6.2])

Errors#

Compile errors#

Condition

Code

/, // or % of Int operands by literal zero

DS_VALIDATE_DIV_BY_ZERO

a builtin called with a count its arities do not hold

DS_VALIDATE_BAD_ARITY

A malformed expression (an unclosed parenthesis, a missing operand, a dangling operator) is a parse error. A Float division by a zero literal is not an error.

Refused with DS_VALIDATE_DIV_BY_ZERO

r.n / 0

The other refusals and faults are at Division by zero, Shifts, Bitwise operators and len of Json.

(Spec: [LEXP.10.2.2], [LEXP.10.2.4], [LEXP.10.2.6], [LEXP.3.1])