Operators
This page describes all operators available in Felico.
Arithmetic Operators
+ Addition
let x = 5 + 3 // 8
- Subtraction
let x = 10 - 3 // 7
* Multiplication
let x = 4 * 5 // 20
/ Division
let x = 15 / 3 // 5
% Modulo (Remainder)
let x = 10 % 3 // 1
- Unary Negation
let x = -5 // -5
Comparison Operators
== Equal
let result = 5 == 5 // true
!= Not Equal
let result = 5 != 3 // true
< Less Than
let result = 3 < 5 // true
<= Less Than or Equal
let result = 5 <= 5 // true
> Greater Than
let result = 10 > 5 // true
>= Greater Than or Equal
let result = 5 >= 5 // true
Logical Operators
&& Logical AND
let result = true && false // false
Short-circuits: the right side is not evaluated if the left side is false.
|| Logical OR
let result = true || false // true
Short-circuits: the right side is not evaluated if the left side is true.
! Logical NOT
let result = !true // false
Assignment Operators
= Assignment
let x = 42
x = 10
Operator Precedence
From highest to lowest precedence:
| Precedence | Operators | Description |
|---|---|---|
| 1 | () | Function call, grouping |
| 2 | !, - | Unary NOT, negation |
| 3 | *, /, % | Multiplication, division, modulo |
| 4 | +, - | Addition, subtraction |
| 5 | <, <=, >, >= | Comparison |
| 6 | ==, != | Equality |
| 7 | && | Logical AND |
| 8 | ` | |
| 9 | = | Assignment |
String Concatenation
The + operator works with strings:
let greeting = "Hello, " + "World!" // "Hello, World!"
Future Operators
Planned operators for future versions:
+=,-=,*=,/=- Compound assignment++,--- Increment, decrement (maybe)?.- Optional chaining??- Null coalescing|>- Pipeline operator (maybe)..,..=- Range operators
Operator Overloading
(Future feature: Custom types will be able to define operator behavior)