Data Types & Casting
Djazair features a clean set of primitive and compound data types. Every value carries its own type metadata at runtime, inspectable using type(v).
Primitive Data Types
| Type | Description | Example Literal |
|---|---|---|
Int |
Signed 32-bit integer for counts, indexing, and arithmetic. | 42, -17, 100_000 |
Float |
IEEE 754 64-bit double precision floating-point number. | 3.14159, -0.5, 1.0 |
String |
Immutable, UTF-8 encoded text sequence. | "hello", `multiline` |
Bool |
Boolean truth values: True and False. |
True, False |
Null |
Represents the intentional absence of any value. | Null |
Compound & Object Types
| Type | Description | Example Literal |
|---|---|---|
Array |
Ordered dynamic list supporting mixed types and nested structures. | [1, "two", True, [3, 4]] |
Map |
Hash table storing key-value associations of any types. | {"name": "Riad", "age": 30} |
Range |
Inclusive integer sequence for loops and slicing. | 0..5, 10 to 20 |
Function |
First-class callable closures or native function pointers. | fn(x) => x * 2 |
Class / Instance |
Object-oriented classes and instantiated objects. | class User ... end |
Explicit Type Casting
Djazair provides five global conversion functions: int(), float(), str(), bool(), and num():
djazair
# Converting to Int
let a = int("42") # 42
let b = int(3.99) # 3 (truncation)
let c = int(True) # 1
# Converting to Float
let d = float("3.14") # 3.14
let e = float(10) # 10.0
# Converting to String
let f = str(123) # "123"
let g = str(True) # "True"
let h = str(Null) # "Null"
# Converting to Boolean (Truthy / Falsy semantics)
print(bool(1)) # True
print(bool(0)) # False
print(bool("hello")) # True
print(bool("")) # False
print(bool([])) # False (empty collections are falsy)
print(bool(Null)) # False
# num() parses strings to either int or float automatically
print(num("100")) # 100 (Int)
print(num("100.5")) # 100.5 (Float)
Type Introspection
You can check a value's runtime type with type(v) or use dedicated type predicate functions:
djazair
let val = [1, 2, 3]
print(type(val)) # => Array
print(isArray(val)) # => True
print(isString(val)) # => False
print(isNumber(42)) # => True
print(isNull(Null)) # => True