/ Variables and Types
Documentation

Getting Started

Language Guide

SDL2 and Graphics

CLI Reference

Variables and Types

Vexel is a statically typed language. Every variable has a type known at compile time. Type annotations are required on declarations and function signatures — the compiler does not perform global type inference.

Declaring Variables

Local variables are declared with the let keyword followed by the variable name, a colon, the type, an equals sign, and the initial value. All four parts are required.

let x: int = 42
let name: str = "Vexel"
let pi: float = 3.14159
let active: bool = true

Variables declared with let are mutable. Their value can be reassigned after declaration with a plain assignment statement.

let score: int = 0
score = score + 10   # reassignment — allowed
score += 5           # compound assignment — equivalent

Constants

Use const to declare a value that cannot be reassigned. Constants must be initialized with a literal value and are available at file scope.

const MAX_HEALTH: int = 100
const GRAVITY: float = 9.8
const GAME_NAME: str = "My Game"

Built-in Types

int 64-bit signed integer 0, 1, -5, 1000
float 64-bit floating-point number 0.0, 3.14, -1.5
str UTF-8 string literal "hello", "world"
bool Boolean value true, false
null Absence of a value null

Integer literals

Integers are 64-bit signed values. Decimal notation is standard.

let a: int = 42
let b: int = -100
let c: int = 1000000

Float literals

Floats must include a decimal point. A number like 3 is an int; write 3.0 to make it a float.

let x: float = 3.14
let y: float = 0.5
let z: float = -1.0

String literals

Strings are enclosed in double quotes. Standard escape sequences are supported.

let greeting: str = "Hello, World!"
let path: str = "C:\\Users\\player"   # escaped backslash
let tab: str = "col1\tcol2"         # tab character
let line: str = "line1\nline2"        # newline character

Boolean literals

let alive: bool = true
let dead: bool = false

Arrays

Arrays hold a sequence of values of the same type. The type is written as T[]. Array literals use square brackets.

let scores: int[] = [10, 20, 30, 40]
let names: str[] = ["alice", "bob", "carol"]

# Index access (zero-based)
print(scores[0])   # 10
print(names[1])    # bob

# Iterate over an array
for s in scores:
    print(s)

Null

null represents the absence of a value. It is typically used as a sentinel or as the default value of an optional field.

let result: str = null

if result == null:
    print("no result yet")
← Hello World Operators →