Operators
Djazair provides a rich set of operators for arithmetic, bitwise logic, deep equality comparisons, identity checks, and collection membership.
Arithmetic Operators
| Operator | Description | Example | Result |
|---|---|---|---|
+ | Addition / String Concatenation | 10 + 5 | 15 |
- | Subtraction / Negation | 10 - 5 | 5 |
* | Multiplication | 4 * 3 | 12 |
/ | Division (returns Float) | 7 / 2 | 3.5 |
// | Floor Division (integer division) | 7 // 2 | 3 |
% | Modulo (remainder) | 10 % 3 | 1 |
** | Exponentiation (Power) | 2 ** 8 | 256 |
++, -- | Increment / Decrement (prefix or postfix) | x++ | Increments x by 1 |
Comparison & Deep Equality
In Djazair, the equality operator == performs deep structural equality for collections and hash maps, not just reference comparison:
djazair
# Primitive comparisons
print(10 == 10) # => True
print(10 != 5) # => True
print(10 > 5) # => True
print(10 <= 10) # => True
# Deep Equality on Arrays and Maps!
let listA = [1, [2, 3]]
let listB = [1, [2, 3]]
print(listA == listB) # => True (structural match)
let mapA = {"user": "Riad", "role": "admin"}
let mapB = {"user": "Riad", "role": "admin"}
print(mapA == mapB) # => True (deep equality)
Identity (is) & Membership (in)
Djazair separates value equality (==) from object identity (is), and provides the powerful in operator for testing membership across collections, strings, and classes:
djazair
# Identity check: checks if both variables reference the EXACT same heap object
let x = [1, 2]
let y = x
let z = [1, 2]
print(x is y) # => True (same reference)
print(x is z) # => False (distinct objects)
print(x is not z) # => True
# Membership check: in and not in
let fruits = ["apple", "banana", "orange"]
print("banana" in fruits) # => True
print("grape" not in fruits) # => True
# in on Maps (checks keys)
let user = {"id": 1, "name": "Sarah"}
print("name" in user) # => True
print("email" not in user) # => True
# in on Strings (checks substrings)
print("air" in "Djazair") # => True
Bitwise Operators
djazair
let a = 5 # binary 0101
let b = 3 # binary 0011
print(a & b) # Bitwise AND => 1 (0001)
print(a | b) # Bitwise OR => 7 (0111)
print(a ^ b) # Bitwise XOR => 6 (0110)
print(~a) # Bitwise NOT => -6
print(8 << 2) # Shift Left => 32
print(8 >> 2) # Shift Right => 2