Operators

Power Function

a**x for pow(a, x) (as in Python), “raise a to the power of x”.

infix right precedence (group Power), so a**b**c parses as a**(b**c).

Boolean and Bitwise Operators

No mixed types allowed (you need to explicitly cast one side instead).

Logical (Bool) Operators

Example:
aBoolandanotherBool -> Bool

The following word operators are used on Bool (only):

Operator Meaning
and logical and
or logical or
nand logical nand
nor logical nor
xor logical xor
not logical not

Words like and and or IMHO are a bit clearer than && and ||, so they are recommended. And actually and / or are valid C++ keywords, too.

not in addition to ! (for boolean negation), as not is a bit clearer than ! (especially as many modern languages like Rust and Swift use ! also for error handling).

xor in Cilia is a logical/Bool operator (unlike C++, where it is a bitwise operator).

Still also use && and || for boolean operation,

Still also ! for negation, as we keep != for “not equal” anyway. (We could use <> instead of !=, but that’s really not familiar to C/C++ programmers.)

and/or/nand/nor/not are not also used for bitwise operations, because bitwise operators bind more strongly than logical operators.

The keyword not_eq is not supported.

Bitwise (Int) Operators

Example:
anInt&anotherInt -> Int

Operator Meaning
& bitwise and
| bitwise or
~ bitwise negation
^ bitwise xor

All bind tightly.

Operator Meaning
&= bitwise and assign
|= bitwise or assign
^= bitwise xor assign

The keywords bitand, bitor, compl, and_eq, or_eq, xor_eq are not supported.

Equality

Range Operator .. and ..<

Bit-Shift & Rotation

Operator Declaration

Assignment Operator

class Int256 {
    operator =(Int256 other) { ... }
}

Arithmetic Operators

operator (Int256 a) + (Int256 b) -> Int256 { ... }
operator (Int256 a) - (Int256 b) -> Int256 { ... }
operator (Int256 a) * (Int256 b) -> Int256 { ... }
operator (Int256 a) / (Int256 b) -> Int256 { ... }
operator (Int256 a) % (Int256 b) -> Int256 { ... }

Shift and Rotate Operators

operator (Int256 a) << (Int shiftCount) -> Int256 { ... }
operator (Int256 a) >> (Int shiftCount) -> Int256 { ... }
operator (UInt256 a) <<< (Int shiftCount) -> UInt256 { ... }
operator (UInt256 a) >>> (Int shiftCount) -> UInt256 { ... }

Compound Assignment Operators

class Int256 {
    operator +=(Int256 other) { ... }
    operator -=(Int256 other) { ... }
    operator *=(Int256 other) { ... }
    operator /=(Int256 other) { ... }
    operator %=(Int256 other) { ... }
    operator <<=(Int shiftCount) { ... }
    operator >>=(Int shiftCount) { ... }
    operator &=(Int256 other) { ... }
    operator |=(Int256 other) { ... }
    operator ^=(Int256 other) { ... }
}
class UInt256 {
    operator <<<=(Int shiftCount) { ... }
    operator >>>=(Int shiftCount) { ... }
}

Increment and Decrement Operators

operator ++(inout Int256 x) -> Int256& { ... }   // pre-increment
operator (inout Int256 x)++ -> Int256  { ... }   // post-increment
operator --(inout Int256 x) -> Int256& { ... }   // pre-decrement
operator (inout Int256 x)-- -> Int256  { ... }   // post-decrement

Relational and Comparison Operators

operator (Int256 a) == (Int256 b) -> Bool { ... }
operator (Int256 a) != (Int256 b) -> Bool { ... }
operator (Int256 a) < (Int256 b) -> Bool { ... }
operator (Int256 a) > (Int256 b) -> Bool { ... }
operator (Int256 a) <= (Int256 b) -> Bool { ... }
operator (Int256 a) >= (Int256 b) -> Bool { ... }
operator (Int256 a) <=> (Int256 b) -> StrongOrdering { ... }

operator (Int256 a) ≠ (Int256 b) -> Bool { return a != b }
operator (Int256 a) ≤ (Int256 b) -> Bool { return a <= b }
operator (Int256 a) ≥ (Int256 b) -> Bool { return a >= b }

Logical Operators

Subscript/Bracket Operator

class MyArray<type T> {
    // Array subscript
    operator [Int i] -> T& {
        return data[i]
    }
}
class MyImage<type T> {
    // 2D array (i.e. image like) subscript
    operator [Int x, y] -> T& {
        return data[x + y*stride]
    }
}

Parenthesis/Functor Operator

class MyFunctor {
    // Functor call
    operator (Int a, Float b, String c) -> String {
        ...
    }
}