Operators

This is a list of operators currently supported in Cicada:

OperatorSupported TypesResult TypeExample
+number, stringlhs type1 + 23
- (subtract)numbernumber1 - 2-1
*numbernumber2 * 36
/numbernumber10 / 25
mod (modulus)numbernumber10 mod 31
^ (power)numbernumber2 ^ 38
andnumber, boollhs typetrue and falsefalse
ornumber, boollhs typetrue or falsetrue
xornumber, boollhs typetrue xor falsetrue
is (equality)anybool1 is 2false
is not (inequality)anybool1 is not 2true
<numberbool1 < 2true
<=numberbool1 <= 2true
>numberbool1 > 2false
>=numberbool1 >= 2false
instringbool"x" in "y"false
not instringbool"x" not in "y"true
notboolboolnot truefalse
- (negate)numbernumber-(1 - 2)1
= (reassign)anyanyx = 11

For all the above operators, the left and right hand side type must be the same. For example, the following is not allowed:

let x = 1 + "2"

The = (assign) operator is useful when you want to reassign a variable and use it in an expression:

let mut x = 1

if x = f():
  # use x for something