Skip to content

Fundamentals

Three declaration keywords with distinct semantics:

KeywordMeaning
constCompile-time constant. Never changes.
letRuntime immutable. Assigned once.
varMutable. Can be reassigned.
const MAX_HEALTH = 100.0
let name = "Hero" // type inferred from value
let name: string = "Hero" // explicit type
var health = 100.0
health = 80.0 // ok
name = "Villain" // compile error — let is immutable

Types are non-nullable by default. See Error Handling for Optional<T>.


Writ typeDescription
intInteger. Stored as i32, automatically promoted to i64 on overflow.
floatFloating point. Stored as f32, promoted to f64 when precision needs it.
booltrue or false.
stringUTF-8 text.

The VM picks the smallest representation that fits and promotes transparently — scripts always see int and float.

let x: int = 42
let y: float = 3.15
let alive: bool = true
let name: string = "Hero"

KindConventionExample
Primitiveslowercaseint, float, string
User-defined typesPascalCasePlayer, Entity, Weapon
Methods and functionscamelCasetakeDamage, getHealth
FieldscamelCasemaxHealth, currentSpeed
Enum variantsPascalCaseDirection.North

let name = "Hero"
// Interpolation
let greeting = "Hello, $name!"
let msg = "HP: ${player.health}"
let calc = "Total: ${a + b}"
// Escape the dollar sign
let literal = "Cost: \$50"
// Multi-line
let block = """
Player: $name
Health: $health
"""
// Concatenation
let full = "Hello" .. ", " .. name

a + b // add
a - b // subtract
a * b // multiply
a / b // divide
a % b // modulo
a == b a != b
a < b a > b
a <= b a >= b
a && b // and
a || b // or
!a // not
x = 10
x += 5
x -= 2
x *= 3
x /= 2
x %= 4
OperatorMeaning
??Null coalescing — use right side if left is null
?.Safe member access — short-circuits to null
?Error propagation — return early on failure
..String concatenation
...Spread into array or dict
asType cast
a ? b : cTernary
0..10 // exclusive: 0 to 9
0..=10 // inclusive: 0 to 10

// Single line
/* Multi line
comment */
// Doc comment — placed directly above a declaration
// The type checker and tooling pick these up automatically.
func takeDamage(amount: float) { }

Curly braces delimit blocks. Semicolons are optional — newlines terminate statements. Unclosed brackets defer termination to their closing bracket:

let x = 10
let x = 10; // also valid
let result = someFunction(
arg1,
arg2 // newline ignored inside parens
)