Operators

Karkain provides a small, explicit set of operators. There are no bitwise operators and no ternary operator.

Arithmetic operators

Operator

Name

Works on

+

Addition

int, float64

-

Subtraction

int, float64

*

Multiplication

int, float64

/

Division

int, float64

%

Modulo (remainder)

int

Comparison operators

Operator

Name

==

Equal

!=

Not equal

<

Less than

>

Greater than

<=

Less than or equal

>=

Greater than or equal

Logical operators

Operator

Name

&&

Logical AND

||

Logical OR

!

Logical NOT

Note

&& and || do not short-circuit in the traditional sense. Both sides of a binary logical expression are fully evaluated before the result is computed.

String operators

+ concatenates two strings:

"hello" + " " + "world"

Assignment operator

= assigns a value to a variable or mutable binding:

x = 10

Index operator

[] accesses an element of an array or map by index:

arr[0]
myMap["key"]

Member access operator

. accesses a field of a struct or record, or qualifies a call against an imported module:

point.x
math.twice(21)

Precedence table

Highest to lowest.

Precedence

Operators

1

* / %

2

+ -

3

< > <= >=

4

== !=

5

&& ||

6 (lowest)

=

Note

There are no bitwise operators in the current language. Bitwise operations are planned for a future phase.

There is no ternary operator. Use if as an expression instead:

let result = if x > 0 { x } else { 0 }