Variables & Types
Declaring Variables
Variables are declared with their type first, followed by the name:
int age = 25;float pi = 3.14159;string name = "Cera";bool active = true;char letter = 'A';Primitive Types
| Type | Size | Description |
|---|---|---|
int | 64-bit | Signed integer (default) |
int8, int16, int32, int64 | 8-64 bit | Sized signed integers |
uint8, uint16, uint32, uint64 | 8-64 bit | Unsigned integers |
float | 64-bit | Floating point (default) |
float32, float64 | 32-64 bit | Sized floats |
string | — | Text string |
char | 8-bit | Single character |
bool | — | true or false |
hash | 64-bit | Hash value (via (hash)value) |
float32x4, int32x4, etc. | 128-bit | SIMD vector types |
Constants (const)
Use const to declare compile-time constants. The value must be computable at compile time:
const int MAX_SIZE = 100;const float TAU = 6.28318;const int DOUBLED = MAX_SIZE * 2; // expressions of other consts are fine
int runtimeVar = 5;const int bad = runtimeVar; // ERROR — not a compile-time valueYou can also force any expression to be evaluated at compile time with const (expr):
int x = const (5 + 3); // 8, computed at compile timeint y = const (square(5)); // 25, if square is a const functionImmutability (immut)
Use immut to declare variables that cannot be reassigned or modified after initialization. Unlike const, immut values can be set at runtime — they just can’t change afterwards:
immut int x = ComputeValue(); // runtime value, but frozen after initx = 10; // ERROR — immut variable
immut Point p = Point(10, 20);p.x = 5; // ERROR — immut valueType Conversions
Cast between types explicitly:
int x = 42;float f = (float)x; // 42.0int back = (int)3.99; // 3 (truncates)string s = (string)x; // "42"Strings
Strings support concatenation with + and have built-in methods:
string greeting = "Hello, " + "world!";int len = greeting.Length;string upper = greeting.ToUpper();string sub = greeting.SubString(0, 5); // "Hello"Next Steps
Learn how to organize code with functions.