Operators - Spicery/Nutmeg GitHub Wiki

Infix operators in Nutmeg are ordered by precedence, higher precedences binding tighter than lower values. The lowest precedence is 0.

Operator Precedence Band Description
x or y 30 B Short-circuit boolean OR of x and y
x and y 40 B Short-circuit boolean AND of x and y
x == y 50 C Equality of x & y
x != y 50 C Non-equality of x & y
x =^= y 50 C Identity of x & y
x !^= y 50 C Non-identity of x & y
a ..< b 60 R Half-open range
a ... b 60 R Closed range
x + y 100 A Adds two numbers
x - y 100 A Subtracts y from x
x * y 200 A Multiplies x and y
x / y 200 A Floating point division
x // y 200 A Integer division c.f. x.div(y)
x ^ y 300 A x to the power of y c.f. x.exp(y)
x ++ y 500 R Append operator

Bands

In addition, operators are grouped into bands and may only be compared if their bands overlap. If the bands do not overlap then the parser will require parentheses to force disambiguation.

Band Overlaps Description
A ACR Arithmetic operator
B BC Boolean operator
C ABC Comparison operator
R A Range operator

Another way of visualising the 'overlaps' relationship is shown below as a matrix.

Band A B C R
A x x x
B x x
C x x x
R x

Notes

  • Unlike many programming languages not is not a prefix operator but a built-in function.
  • Bands syntactically enforce some rules that would emerge from type analysis. When Nutmeg has type checking, the parser is excused from flagging precedence violations that would be caught by the type checker.