Operators and arithmetic

XS has the usual arithmetic and comparison operators, plus a pipe operator, null coalescing, and optional chaining.

Arithmetic

scratch.xs

Integer division (/) truncates toward zero, so (-7) / 2 is -3, not -4. Floor division (//) rounds toward negative infinity.

Division by zero raises a catchable runtime error -- it does not silently produce null or NaN:

scratch.xs

Integers are signed 64-bit and promote to arbitrary-precision bigints on overflow:

scratch.xs

Comparison

scratch.xs

Logical operators

Both keyword and symbol forms work. They short-circuit and return the last evaluated operand, not necessarily true or false.

scratch.xs

Pipe operator

x |> f passes x as the first argument to f. Chain multiple pipes to build readable data pipelines.

scratch.xs

Null coalesce

?? returns the left side when it is not null, otherwise the right side.

scratch.xs

Optional chaining

?. short-circuits to null when the receiver is null, instead of throwing.

scratch.xs

Membership

scratch.xs