Declarations
Declarations
Zirric is driven by declarations. These constructs define values, types, and
modules and are annotated with metadata.
let
let introduces a variable. Variables are scoped and may be reassigned.
let count = 0
count = count + 1
_ = expr explicitly discards a value.
fn
Functions are declared with fn name(params) { ... }.
fn greet(name) {
"Hello, " + name
}
data
data declares record-like types with named fields.
data Person {
name
age
}
Instances are created by calling the type name as a function.
let alice = Person("Alice", 30)
union
union defines tagged unions. Types listed inside are available at top level.
union Result {
data Ok { value }
data Err { error }
}
extern
extern declares runtime-provided types or functions.
extern type String {
length
}
attr
attr defines metadata schemas used by tooling and the runtime.
attr Returns {
@Type(AnyType) type
}
mod and import
Modules group declarations. Imports bring other modules into scope.
mod http
import code.knabel.dev.zirric_lang.zirric.prelude
import code.knabel.dev.zirric_lang.zirric.future.tasks
Attributes on declarations
Annotations attach metadata and behavior to declarations and fields.
@Deprecated("use newFn")
fn oldFn() { ... }