Repository navigation
Language Guide
torvik-lang edited this page Jul 4, 2026
·
8 revisions
This guide covers everything implemented in Torvik v1.0. For planned features, see the Roadmap.
- Hello World
- Comments
- Variables
- Types
- Operators
- Printing
- Conditionals
- Loops
- Functions
- Collections
- Memory Model
df main() -> void {
echo!("Hello from Torvik!");
}
Every program needs a main function. Compile with torvc or use rune run.
// Line comments start with //
set x: i64 = 42; // trailing comment
Block comments are not yet supported in v1.0.
-
set→ mutable variable -
fixed→ immutable binding
set count: i64 = 0; // can be changed
fixed name: str = "Freya"; // cannot be reassigned
count += 1;
Type annotations are always required.
Integers: i8, i16, i32, i64, i128 | u8, u16, u32, u64, u128
Float: f64
Boolean: bool
String: str
set age: i64 = 28;
fixed pi: f64 = 3.14159;
fixed active: bool = true;
fixed message: str = "Hello";
- Arithmetic:
+ - * / % - Comparison:
== != < > <= >= - Logical:
&& || ! - Bitwise:
& | ^ ~ << >> - Compound:
+= -= *= /= %=
-
echo!(value)→ prints with newline -
echo(value)→ prints without newline
Interpolation works directly:
fixed name: str = "Thor";
set count: i64 = 5;
echo!("Hello {name}!");
echo!("You have {count} items.");
check / fallback
check n > 0 {
echo!("positive");
} fallback {
echo!("non-positive");
}
fixed result: str = n > 0 ?> "positive" !> "negative";
guard n != 0 fallback {
return "undefined";
}
// n is now known to be non-zero
whilst
set i: i64 = 0;
whilst i < 5 {
echo!(i);
i += 1;
}
each (range loop)
each i in 0..5 {
echo!(i); // 0 1 2 3 4
}
break and continue are supported.
df add(a: i64, b: i64) -> i64 {
return a + b;
}
df main() -> void {
echo!(add(3, 7));
}
Recursion and forward references are supported.
list<T>table<K, V>bag<T>
See the Standard Library page for creation and manipulation functions (list_new(), push(), table_set(), etc.).
Torvik uses automatic reference counting (ARC). No garbage collector, no manual free(). Memory is deterministically managed.
- Explore the Toolchain for compiler and project tools
- Check the Standard Library reference
- See the full detailed guide in the repo: docs/GUIDE.md