Language Guide

This section provides a comprehensive reference for the Zith programming language, aligned with the language specification (docs/Zith-spec.md).

Core Concepts

Syntax Basics

Fundamental syntax: comments, identifiers, literals, expressions, and statements.

Module System

Organising code with import, from, export, alias, use, and visibility modifiers (pub, mod).

Type System

Primitives, slices, arrays, enums, structs, components, unions, packs, generics, and pattern matching with when.

Mutability & Bindings

Variable declaration with let, var, global, const, comptime, deep mutability, and destructuring.

Functions

Function kinds (fn, const fn, async fn, flow fn, raw fn), return types, implicit returns, closures, and the @ prefix rule.

Control Flow

Conditionals, loops (for), pattern matching (when), chain flow (->), and flow functions with markers.

Memory Model — NRA

Node Resource Analysis: ownership keywords (lend, view, unique, share, belong), move semantics, and the four NRA rules.

Memory Management

Allocation strategies, scenes as memory regions, custom allocators, and runtime memory patterns.

Error Handling

Failable types (?T, T!), propagation (?, !), fallback (or), with/catch, fail blocks, and throw.

Generics

Explicit and implicit generic parameters, type constraints with or, and monomorphisation.

Advanced Topics

For more advanced features, see the Advanced Topics section:

Quick Reference

Topic Example
Variables let x: i32 = 5;
Functions fn add(a: i32, b: i32): i32 { a + b }
Ownership lend, view, unique, share, belong
Control Flow if, for, when, ->
Error Handling ?T, T!, ?, !, or
Modules import path as name, from path, pub, mod

See also: Spec: Overview & Design Philosophy


Ready to learn? Start with Syntax Basics