Operators#

Meta: lead with the precedence table — it's what people scroll back to. Per-operator notes can be terse if the table is precise.

Precedence (low → high)#

Precedence follows the DefaultExpr → … → MultiplicativeExpr → Term chain in pkg/dang/dang.peg.

level operators assoc
1 ?? right
2 or left
3 and left
4 ==, != left
5 <, <=, >, >= left
6 +, - left
7 *, /, % left
8 ! (prefix), - (unary), & (prefix)
9 ! (postfix), ., .{{ }}, .{ }, [], () left

Arithmetic#

Comparison#

Logical#

Default (??)#

Non-null assertion (postfix !)#

let name: String = user.nickname   # nullable
print(name!.length)                # assert non-null, then call

# asserting a value that is null raises at runtime
let missing: String = null
missing!                           # -> non-null assertion failed: value is null

Compound assignment#

Cast / type hint: ::#

Unary#

Meta: it's worth a paragraph on why and/or are keywords (readability) rather than &&/||. Same for != vs <>.