Operators
Arithmetic
| Operator | Operation | Example |
|---|---|---|
+ | Addition | 3 + 4 → 7 |
- | Subtraction | 10 - 3 → 7 |
* | Multiplication | 4 * 5 → 20 |
/ | Division (float) | 7 / 2 → 3.5 |
// | Integer division | 7 // 2 → 3 |
% | Modulo | 7 % 3 → 1 |
** | Exponentiation | 2 ** 8 → 256 |
- (unary) | Negate | -5 → -5 |
Comparison
| Operator | Meaning | Example |
|---|---|---|
== | Equal | 3 == 3 → yep |
!= | Not equal | 3 != 4 → yep |
< | Less than | 2 < 5 → yep |
> | Greater than | 5 > 2 → yep |
<= | Less or equal | 3 <= 3 → yep |
>= | Greater or equal | 4 >= 5 → nope |
Logical
| Operator | Meaning | Example |
|---|---|---|
and | Both true | yep and nope → nope |
or | Either true | yep or nope → yep |
not | Invert | not yep → nope |
Short-circuit evaluation: and stops at the first nope, or stops at the first yep.
Bitwise
| Operator | Meaning | Example | ||
|---|---|---|---|---|
& | Bitwise AND | 0b1010 & 0b1100 → 0b1000 | ||
| `\ | ` | Bitwise OR | `0b1010 \ | 0b0101 → 0b1111` |
^ | Bitwise XOR | 0b1010 ^ 0b1100 → 0b0110 | ||
~ | Bitwise NOT | ~5 → -6 | ||
<< | Left shift | 1 << 4 → 16 | ||
>> | Right shift | 16 >> 2 → 4 |
Pipeline |>
Passes the left side as the first argument to the right side:
lhj
forge result = [3, 1, 2] |> sorted |> reversedEquivalent to:
lhj
forge result = reversed(sorted([3, 1, 2]))Pipelines chain left-to-right, which reads more naturally for data transforms.
Range ..
Creates an inclusive integer range:
lhj
forge r = 1..10 ## 1, 2, 3, ..., 10
march i in 1..5:
echo i ## 1 2 3 4 5Arrow assignment <-
Reassigns a variable:
lhj
forge x = 1
x <- x + 1Membership in
Tests whether a value is in a sequence:
lhj
echo 3 in [1, 2, 3, 4] ## yep
echo "key" in {"key": "val"} ## yep
echo "x" in "lexer" ## yepOperator precedence
From highest to lowest:
()— grouping**— exponentiation (right-associative)- Unary
-,not,~ *,/,//,%+,-,..(range)<<,>>&^|==,!=,<,>,<=,>=,inandor|>— pipeline (lowest)
When in doubt, use parentheses.