Language guide · 4 of 12

Operators

Arithmetic & Modulo

sum  := 10 + 5   // 15
diff := 10 - 5   // 5
prod := 10 * 5   // 50
quot := 10 / 5   // 2
rem  := 10 % 3   // 1
Open in playground

Compound Assignment

var x := 10
x += 5   // 15
x -= 2   // 13
x *= 2   // 26
x /= 2   // 13
x %= 4   // 1
Open in playground

Compound assignment also works on object fields, class fields and subscripts. The target and key are evaluated once. Because only one fiber of an instance runs Evie code at a time, this.count += 1 across concurrent tasks never loses updates:

var stats := { hits: 0 }
stats.hits += 1
stats["hits"] *= 2

var scores := [10, 20, 30]
scores[0] += 5
scores[-1] -= 1

class Counter(count) {
    fn inc() {
        this.count += 1
    }
}
Open in playground

Comparisons

All standard comparison operators are supported:

a == b    // equality
a != b    // inequality
a < b     // less than
a <= b    // less than or equal
a > b     // greater than
a >= b    // greater than or equal
Open in playground

Logical Operators

Short-circuiting boolean operations:

isReady && hasPermission  // logical AND
isCached || fetchRemote   // logical OR
!isCompleted              // logical NOT
Open in playground

Type Checking (is Operator)

Evie provides a built-in is operator for safe runtime type assertions:

42 is number           // true
"hello" is string      // true
true is bool           // true
[1, 2] is array        // true
{ a: 1 } is object     // true
t is task              // true
err is error           // true
buf is buffer          // true
p is Person            // true (class instance check)
dog is Animal          // true (polymorphic inheritance check)
Open in playground

The type names double as conversion functions:

number("2.5")   // 2.5 (throws if the string is not a number)
number(true)    // 1
bool(0)         // false (truthiness)
string(42)      // "42"
Open in playground

Edit this page on GitHub