Language Guide / Operators & Precedence

Operators & Precedence

Arithmetic, exponentiation, comparison, short-circuiting logical operators, and indexing/slicing.

Operator Precedence

Ordered from highest (tightest binding) to lowest:

OperatorsDescriptionAssociativity
f(...), x[i], x[a:b], x.fieldCall, index, slice, field accessLeft
^ExponentiationRight
+x, -xUnary positive / negationPrefix
*, /, %Multiplication, division, remainderLeft
+, -Addition / string concatenation, subtractionLeft
==, !=, <, <=, >, >=Value comparisonLeft
notLogical negationPrefix
andShort-circuiting logical ANDLeft
orShort-circuiting logical ORLeft

Indexing & Slicing

Lists and strings support 0-based indexing and half-open [start:stop] slices:

ops.dl
nums = [10, 20, 30, 40]
show nums[0]      # 10
show nums[1:3]    # [20, 30]
show 2 ^ 3 ^ 2    # 512 (right-associative)
show "hi " + "there"