Syntax Basics

Zith's syntax is designed to be explicit, readable, and consistent — drawing from C-family familiarity while removing ceremony.

Comments

// Line comment

/* Block comment */

/** Doc comment — attached to the following declaration */

Identifiers

Identifiers use camelCase. Start with a letter or _, followed by letters, digits, or _.

playerName    // OK
_private      // OK
2beOrNot      // Error: starts with digit

Keywords

Category Keywords
Declarations fn, let, var, const, global, struct, enum, union, component, trait, implement, type
Control flow if, else, for, when, is, ->, or
Functions async, yield, flow, marker, dock, jump, entry, raw, unsafe
Ownership lend, view, unique, share, belong
Modules import, from, export, pub, mod, alias, use
Error handling ?, !, or, with, catch, fail, must, throw
Other spawn, await, comptime, scene, dyn, opaque, Trust

Expressions & Statements

Almost everything is an expression. The last expression in a block is the return value (implicit return).

fn add(a: i32, b: i32): i32 { a + b }

fn main() {
    let result = if (x > 0) { x * 2 } else { 0 };
    @println("{result}");
}

Operators

Category Operators
Arithmetic +, -, *, /, %
Comparison ==, !=, <, >, <=, >=
Logical and, or, not
Chain -> (pipe forward), .. (previous value)
Error ? (optional), ! (failable), ?? (null coalesce)
Type is (type check), as (cast), : (type annotation)
Ownership lend, view (borrow modifiers on types)

Naming Conventions


Next: Types