Skip to content

Language Guide

torvik-lang edited this page Jul 4, 2026 · 8 revisions

Torvik Language Guide (v1.0)

This guide covers everything implemented in Torvik v1.0. For planned features, see the Roadmap.

Table of Contents


Hello World

df main() -> void {
    echo!("Hello from Torvik!");
}

Every program needs a main function. Compile with torvc or use rune run.


Comments

// Line comments start with //
set x: i64 = 42;  // trailing comment

Block comments are not yet supported in v1.0.


Variables

  • 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.


Types

Integers: i8, i16, i32, i64, i128 | u8, u16, u32, u64, u128 Float: f64 Boolean: bool String: str

Examples

set age: i64 = 28;
fixed pi: f64 = 3.14159;
fixed active: bool = true;
fixed message: str = "Hello";

Operators

  • Arithmetic: + - * / %
  • Comparison: == != < > <= >=
  • Logical: && || !
  • Bitwise: & | ^ ~ << >>
  • Compound: += -= *= /= %=

Printing

  • 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.");

Conditionals

check / fallback

check n > 0 {
    echo!("positive");
} fallback {
    echo!("non-positive");
}

Ternary

fixed result: str = n > 0 ?> "positive" !> "negative";

Guard

guard n != 0 fallback {
    return "undefined";
}
// n is now known to be non-zero

Loops

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.


Functions

df add(a: i64, b: i64) -> i64 {
    return a + b;
}

df main() -> void {
    echo!(add(3, 7));
}

Recursion and forward references are supported.


Collections

  • list<T>
  • table<K, V>
  • bag<T>

See the Standard Library page for creation and manipulation functions (list_new(), push(), table_set(), etc.).


Memory Model

Torvik uses automatic reference counting (ARC). No garbage collector, no manual free(). Memory is deterministically managed.


Next Steps

Clone this wiki locally