Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Appendix B — Operator Reference

Reserved for the second edition. The exhaustive operator + precedence reference will land here once the upcoming language audit completes.

Until then, a quick overview of what the chapters have introduced.

Arithmetic

+, -, *, /, % — addition, subtraction, multiplication, division, modulo. Bind in the conventional order; parentheses disambiguate.

Comparison

==, !=, <, <=, >, >= — equality, inequality, ordering. Both sides can be expressions over bound variables and constants.

Logical / set membership

not <atom> — negation as failure. ?x in <collection> — set membership at rule-atom position. At expression position, x in xs and x not in xs desugar to <TypeOf(xs)>::contains(xs, x) (and its negation).

Collection operators

The collection-op surface is grounded in Chapter 2.8. All forms desugar at elaboration time to qualified calls into the receiver’s std::collection::* (or std::math::Range) submodule.

TokenFormFixityPrecedenceDesugarExample
.xs.m(args)postfixtightest (binds before any binary op)<TypeOf(xs)>::m(xs, args)b.units.size()
[i]xs[i]postfixtightest<TypeOf(xs)>::at(xs, i) (or Map::get)b.units[0]
[i..j] / [i..] / [..j]slicingpostfixtightest<TypeOf(xs)>::slice(xs, Range::new(i, j))b.units[0..3]
..range literalbinary infixbelow + / -, above comparisonRange::new(lo, hi) (half-open)0..10
..=inclusive range literalbinary infixsame as ..Range::inclusive(lo, hi)0..=9
inmembershipbinary infixsame precedence as comparison (==, <, …)<TypeOf(xs)>::contains(xs, x)p in b.tenants
not innon-membershipbinary infixsame as innot <TypeOf(xs)>::contains(xs, x)p not in b.tenants
[expr for x in xs where pred]comprehensionbracket formbracket-boundedxs.filter(<pred>).map(<expr-as-closure>)[u.number for u in b.units]

Comprehensions reuse the aggregate-binding subgrammar. The where clause is optional. Binder shadowing emits OW2403.

Path

a.b.c — field-access path on a value. ?x.b.c — Datalog-binding-position field-access path on a variable.

Cardinality (inside collection types)

>= N, == N, <= N — at-least / exactly / at-most cardinality clauses. Distinct from comparison operators despite sharing tokens.

Type tests / subtype tests

v: T — match-arm type test (also a rule-atom shape). ?x specializes T — subtype predicate (rule-body only). ?x : T — rule-atom typed-binding form.

box(...) — necessity. diamond(...) — possibility. Rule-atom position.

Allen-interval operators

before, after, meets, met_by, overlaps, overlapped_by, starts, started_by, during, contains, finishes, finished_by, equals — interval-relations algebra binary infix operators.

Quantifiers

forall <var>: <T> [where <body>], exists <var>: <T> [where <body>] — restriction and binding forms; tier-classified.

Aggregation

sum, count, min, max, avg — fold-style aggregates over for var in path [where atom].

Module path

:: — module-qualified path separator. pkg::mod::Item.

Rule arrows

:- — body separator. => — consequence (rules) and arm body (match arms). Context disambiguates.

Membership / subtype-by-pattern

The full set is documented in the per-crate API documentation.