Operators
Operators
All operators (except the pipe operator) will require its arguments to be of the same type. So, it will not be possible to add an int to a float without first converting one or the other to the respective type.
Logical
// and
true and true // true
true and false // false
false and false // false// or
true or true // true
true or false // true
false or false // false// not
not true // false
not false // trueConcatenation
Because strings are arrays of characters, the concatenation operator is the same for both.
[a, b, c] <> [d, e, f] == [a, b, c, d, e, f]"Hello" <> " " <> "world" == "Hello world"You can also use the concatenation operator between maps, provided that they are of the same type:
[str]int months_to_num_1 = ["jan": 1, "feb": 2, "mar": 3]
[str]int months_to_num_2 = ["apr": 4, "may": 5, "jun": 6]
[str]int months_to_num_3 = ["jul": 7, "aug": 8, "sep": 9]
[str]int months_to_num_4 = ["oct": 10, "nov": 11, "dec": 12]
[str]int months_to_num = months_to_num_1 <> months_to_num_2 <> months_to_num_3 <> months_to_num_4
// ["jan": 1, "feb": 2, "mar": 3, "apr": 4, ... , "dec": 12]
[str]float different_type = ["new": 13.0]
months_to_num <> different_type // error: cannot concatenate maps of different typesArithmetic
// addition
1 + 2 == 3// subtraction
2 - 1 == 1// exponent
2 ** 6 == 64// modulo
10 % 4 == 2// division
5.0 / 2.0 == 2.5
5 / 2 == 2// multiplication
3 * 2 == 6Comparisons
// equality
1 == 1// inequality
1 != 2// less than
1 < 2// greater than
1 > 0// less than or equal to
5 <= 6
5 <= 5// greater than or equal to
7 >= 4
7 >= 7Bit arithmetic
Bit arithmetic will only be allowed for integers.
// bit shift left
1 << 4 == 16// bit shift right
6 >> 1 == 3// bitwise and
27 & 1 == 1// bitwise or
8 | 1 == 9// bitwise xor
12 ^ 1 == 13// bitwise not
!6 == -7Inclusion
The in keyword acts as the inclusion operator, used for checking if a value is included in a container value. You can check for:
Typein arrayType[]:test "type in type[]" { int[] arr = [1, 2, 3, 4, 5] assert 5 in arr }Keyin map[Key]Value:test "key in map [key]value" { [char]int map = ['a': 1, 'b': 2, 'c': 3] assert 'a' in map }char/strinstr:test "char/str in str" { str string = "Hello world" assert 'H' in string assert "Hello" in string }