Keywords

Reserved words in Chic, with a short explanation and a one-line example for each keyword.

Reserved words

These spellings are recognized by Chic's lexer and cannot be used as ordinary identifiers. Keywords are case-sensitive.

Built-in type names such as i32, f64, and bool belong on the Types page.

Examples are independent snippets. Names such as Point, ptr, and values refer to types or values in your program. The error-handling examples assume read_value() returns a value and an error status, with zero indicating success.

KeywordRole and example
aliasGives an existing type another name.alias UserId : i64
breakExits an enclosing loop or switch.for i in 0..10 { if i == 5 break }
caseIntroduces a branch in a switch.switch (code) { case 0: return 0 }
castExplicitly converts a value to a specified type.value := cast<f64>(42)
continueSkips to the next loop iteration.for i in 0..10 { if i == 0 continue }
defaultIntroduces the fallback branch of a switch.switch (code) { default: return -1 }
deferSchedules an action for the end of the current scope.defer release ptr
elseIntroduces an alternative branch.if ready { return 1 } else { return 0 }
enumDeclares an enumeration type.Color : enum { Red, Green, Blue }
falseThe false boolean value.enabled := false
forBegins a loop.for i in 0..3 {}
funcDeclares a function or a callable type.add : func(a : i32, b : i32) -> i32 { return a + b }
funcptrDescribes a raw function pointer type.callback : funcptr(i32) -> i32 = null
ifBegins a conditional branch.if ready { return 1 }
importImports a package.import fmt = core.fmt
inSeparates a loop binding from its sequence or range.for item in values {}
inlineEmbeds a structure's members in another structure.NamedPoint : struct { inline Point }
letExplicitly declares a constant binding.let limit : i32 = 10
matchSelects a result through pattern matching.label := match (code) { 0 => "ok", else => "unknown" }
newAllocates and initializes a value.ptr := new Point {}
nullThe null pointer value.ptr : ^Point = null
or_defaultSupplies a fallback value for an error result.value := read_value() or_default 0
or_errorSubstitutes an error during error propagation.value := try read_value() or_error Error.Failed
raw_unionDeclares a union without a runtime tag.Value : raw_union { number : i32; decimal : f32 }
releaseReleases an allocated value.release ptr
returnExits a function, optionally returning a value.return 42
sizeofQueries a type's size.bytes := sizeof(Point)
stepSets the increment of a range loop.for i in 0..10 step 2 {}
structDeclares a structure containing named fields.Point : struct { x : f32; y : f32 }
switchBranches on a value using cases.switch (code) { case 0: return 0; default: return -1 }
trueThe true boolean value.enabled := true
tryPropagates an error result to the caller.value := try read_value() or_default 0
typeofObtains runtime type metadata.info := typeof(i32)
unionDeclares a tagged union; the enum kind identifies the active member.ValueKind : enum { Number, Text }; Value : union(kind : ValueKind) { number : i32; text : string }
varDeclares a mutable binding.var count := 0

Directives and attributes

Directives begin with #. Attributes begin with @ and annotate declarations.

SpellingRole
#if, #elif, #else, #endConditional compilation.
#packageDeclares a logical package.
#import_libDeclares a native library dependency.
@extensionMakes a function available through method-call syntax.
@internalRestricts a declaration to its package.

Attribute names such as extension are not reserved word keywords.

Constants

Chic declares compile-time constants with ::.

MaxItems :: 128
PacketLimit :: u16 = 65_535