-
Notifications
You must be signed in to change notification settings - Fork 8
Operators
Brom Bresenham edited this page Jul 27, 2025
·
23 revisions
For using operators on objects and compounds, see Operator Methods.
| Operator | Description |
|---|---|
+ |
Add |
- |
Subtract (binary operator), Negate (unary operator) |
* |
Multiply |
/ |
Divide (integer/integer division gives an integer result; division with one or two real numbers gives a real number result) |
% |
Mod AKA Modulo AKA remainder (18%10 → 8, -18%10 → 2) |
^ |
Power (2^8 → 256) |
| Operator | Description |
|---|---|
= |
Assign |
+= |
Add-and-Assign (a = a + b → a += b) |
-= |
Subtract-and-Assign |
*= |
Multiply-and-Assign |
/= |
Divide-and-Assign |
%= |
Mod-and-Assign |
^= |
Power-and-Assign |
&= |
Bitwise-And-and-Assign |
|= |
Bitwise-Or-and-Assign |
~= |
Bitwise-Xor-and-Assign |
:<<:= |
Left-Bit-Shift-and-Assign (a = a:<<:1 → a :<<:= 1) |
:>>:= |
Right-Bit-Shift-with-Zero-Fill-and-Assign |
:>>>:= |
Right-Bit-Shift-with-Sign-Extend-and-Assign |
.= |
Access-and-Assign (st = st.leftmost(5) → st .= leftmost(5)) |
| Operator | Description |
|---|---|
& |
Bitwise And |
| |
Bitwise Or |
~ |
Bitwise Xor (Bitwise Exclusive Or) |
! |
Bitwise Complement (AKA Bitwise Not; unary operator; !0 → -1) |
:<<: |
Bit Shift Left |
:>>: |
Bit Shift Right with Zero Fill |
:>>>: |
Bit Shift Right with Sign Extend |
| Operator | Description |
|---|---|
== |
Equals |
!= |
Not Equals (Is Not Equal To) |
< |
Less Than |
<= |
Less Than or Equal To |
> |
Greater Than |
>= |
Greater Than or Equal To |
| Operator | Description |
|---|---|
|| |
Operand Or. `a |
&& |
Operand And. a && b evaluates to b if a?, otherwise evaluates to null/0/false. |
| Operator | Description |
|---|---|
?. |
Conditional Access (obj?.method or obj?.property?.method etc.). |
?.[...] |
Conditional Context Block (obj?.[ property=value, ... ]). |
?[...] |
Conditional Indexed Access (obj?.[index] = value). |
?// |
Conditional String-Indexed Access (obj?//key = value). |
| Operator | Description |
|---|---|
. |
Context Access (obj.property). |
| Operator | Description |
|---|---|
.[...] |
Context Block Operator that provides a better alternative to call chaining. See Context Blocks. |
| Operator | Description |
|---|---|
-> |
Convert. Convert a value to a different type - a->BType converts value a to type BType. Convert automatically works with primitives. To work with objects and compounds, define method to->Type (e.g. method to->String) and those conversion methods will be automatically invoked when the operator is used. |
?-> |
Conditional conversion. If the left-hand context is null, the result is the default value (0/null/false) of the target type. |
->(as Type) |
Cast-As. When called on reference obj of any type, obj->(as SomeType) produces a reference of type SomeType if obj instanceOf SomeType; otherwise it produces null. |
?->(as Type) |
Conditional Cast-As. |
| Operator | Description |
|---|---|
(...) |
Parens (AKA Parenthesized Expression; (5.0/9.0)*(f-32)) |
| Operator | Description |
|---|---|
[...] |
Indexed Access (AKA Element Access; list[i] = x). An indexed get obj[i] resolves to obj.get(i). An indexed set obj[i] = x resolves to obj.set(i,x).
When used with an |
| Operator | Description |
|---|---|
and |
Logical And |
or |
Logical Or |
xor |
Logical Exclusive Or |
not |
Logical Not (unary operator - not a) |
? |
Logicalize (unary operator - a?). Converts any type of value into a Logical. Non-zero primitives logicalize to true. For compounds, a logicalize operator method (operator?) is called if it exists, or else a Logical conversion method (method to->Logical) must exist and that is called. Reference types are handled the same as compounds except that if neither an operator method nor a conversion method exists then any non-null reference becomes true. |
| Operator | Description |
|---|---|
.. |
Up-To. |
..< |
Up-To-Less-Than. |
..> |
Down-To-Greater-Than. |
downTo |
Down-To. |
| Operator | Description |
|---|---|
is |
a is b returns true if a and b both reference the same object. |
is not |
a is not b returns true if a and b reference different objects. |
| Operator | Description |
|---|---|
++ |
Increment (++a is Pre-increment; a++ is Post-increment) |
-- |
Decrement (--a is Pre-decrement; a-- is Post-decrement) |
| Operator | Description |
|---|---|
// |
table//key is shorthand for table["key"]. table//key = value is shorthand for table["key"] = value. |
| Operator | Description |
|---|---|
instanceOfnot instanceOf
|
a instanceOf T returns true if object or type a is type T or is a direct or indirect subclass of type T. a not instanceOf T is the logical inverse. |
isTypenot isType
|
a isType T returns true if object or type a is exactly type T. This is useful for evaluating template parameters and defined constants for code branching purposes. a not isType T is the logical inverse. |
$hasMethod |
Compile-time meta-command $hasMethod<<context,"method_name">> evaluates to true if the given context has any method with the given name. |
$isCompound |
$isCompound<<Type>> evaluates to true if Type is a compound type. Note that enums count as compound types. |
$isEnum |
$isEnum<<Type>> evaluates to true if Type is an enum type. |
$isPrimitive |
$isPrimitive<<Type>> evaluates to true if Type is a primitive type. |
$isReference |
$isReference<<Type>> evaluates to true if Type is a reference type (object or aspect). |
- The operators below are listed from lowest to highest precedence.
- Assignment operators (
=,+=, ...) are statement-level operators, not expression-level operators. They do not result in a value, cannot be nested in a larger expression, and are not listed here.
| Operator | Description |
|---|---|
|| |
Operand Or (Conditional Operand) |
&& |
Operand And (Conditional Operand) |
xor |
Logical Exclusive Or |
or |
Logical Or |
and |
Logical And |
== != < <= > >=
|
Comparison |
is is not instanceOf isType
|
Reference Comparison and Type Evaluation |
.. ..< ..> downTo
|
Range Operators |
~ |
Bitwise Xor (Bitwise Exclusive Or) |
| |
Bitwise Or |
& |
Bitwise And |
+ -
|
Add and Subtract |
:<<: :>>: :>>>:
|
Bit Shifts (note that Rogue bit shifts have higher precedence than Add & Subtract, unlike C-family languages) |
* / %
|
Multiply, Divide, and Mod |
^ |
Power |
! not - ++ --
|
Bitwise Complement, Logical Not, Negate, Pre-increment, Pre-decrement (unary prefix operators) |
++ -- ?
|
Post-increment, Post-decrement, Logicalize (unary postfix operators) |
. .[...] [...] // -> ->(as Type) ?. ?.[...] ?[...] ?//
|
Access, Context Block, Indexed Access, String-Indexed Access, Convert, Cast-As, Conditional Access, Conditional Context Block, Conditional Indexed Access, Conditional String-Indexed Access |
(...) |
Expression Grouping |