Basics & Types
This guide covers the fundamental building blocks of the REK language. REK is dynamically typed, meaning you don't need to specify types when declaring variables.
Variables
Use let for mutable variables and const for constants.
let name = "REK"
name = "REK Language" // Valid
const pi = 3.14159
// pi = 3.14 // Error: Cannot assign to constant
Data Types
Primitives
- Number: Floats and Integers (e.g.,
42,3.14). - String: Double-quoted text (e.g.,
"Hello"). - Boolean:
trueorfalse. - Null: Represents absence of value
null.
Lists
Ordered collections of values. Lists can hold mixed types.
let items = [1, "two", true]
log(items[0]) // 1
items[1] = "three"
Maps
Key-value pairs. Keys are strings.
let user = {
"name": "Alice",
"age": 30,
"isAdmin": true
}
log(user["name"]) // Alice
user["role"] = "Editor" // Add new field
Control Flow
If / Else
Conditional execution with if, elif, and else.
let score = 85
if score >= 90 {
log("A")
} elif score >= 80 {
log("B")
} else {
log("Try again")
}
While Loops
Repeat code while a condition is true.
let count = 0
while count < 5 {
log(count)
count = count + 1
}
For Loops
Iterate over lists.
let colors = ["red", "green", "blue"]
for color in colors {
log(color)
}
Comments
Use // for single-line comments.
// This is a comment
let x = 10 // Inline comment