Start

Language Tour

Canonical grammar, semantics, constraints, and deferred boundaries for Language Tour.

Topaz is an expression-oriented, statically checked language with a deliberately closed surface. The tour shows how values, types, control flow, collections, errors, resources, concurrency, templates, and modules fit into one contract.

Policy

A program is a sequence of declarations and statements accepted by the current language. Expressions produce values; statement-only forms such as assignment and defer are explicit. Supported output targets preserve the visible behavior defined in this manual.

Specified behavior

Bindings use const, let, and let mut. Functions declare parameter and result types, while lambdas use =>. if, match, value-collecting for, and contextual loop can produce values. Absence uses nullable unions or Option; recoverable failure uses Result and postfix ?; cleanup uses defer or the constrained File using form. Collections are Array<T>, Map<K,V>, and Set<T> with ordered evaluation rules.

Constraints and loud decline

The checker rejects invented dialects rather than guessing intent. There is no async/await, try expression, implicit string indexing, JavaScript record spread, Rust receiver syntax, or alternative collection type shorthand. Canonical modules use only the locked import/export grammar. A backend that cannot support an accepted shape must decline loudly or keep that shape outside its claim.

Deferred boundary

Broader async syntax, fault catching, user-defined template tags, grapheme APIs, iterable spread, higher-rank polymorphism, broader protocol dispatch, and module re-export forms remain outside the canonical surface. The roadmap may discuss them, but current examples cannot use them as if adopted.

Worked example

TOPAZ
type TrafficLight = "red" | "yellow" | "green"

function instruction(light: TrafficLight) -> string {
    match light {
        case "red" => "stop"
        case "yellow" => "slow"
        case "green" => "go"
    }
}

let values: Array<int> = [1, 2, 3]
let doubled = for value in values { value * 2 }
print("{instruction("green")}: {doubled}")