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.
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.
| Keyword | Role and example |
|---|---|
alias | Gives an existing type another name.alias UserId : i64 |
break | Exits an enclosing loop or switch.for i in 0..10 { if i == 5 break } |
case | Introduces a branch in a switch.switch (code) { case 0: return 0 } |
cast | Explicitly converts a value to a specified type.value := cast<f64>(42) |
continue | Skips to the next loop iteration.for i in 0..10 { if i == 0 continue } |
default | Introduces the fallback branch of a switch.switch (code) { default: return -1 } |
defer | Schedules an action for the end of the current scope.defer release ptr |
else | Introduces an alternative branch.if ready { return 1 } else { return 0 } |
enum | Declares an enumeration type.Color : enum { Red, Green, Blue } |
false | The false boolean value.enabled := false |
for | Begins a loop.for i in 0..3 {} |
func | Declares a function or a callable type.add : func(a : i32, b : i32) -> i32 { return a + b } |
funcptr | Describes a raw function pointer type.callback : funcptr(i32) -> i32 = null |
if | Begins a conditional branch.if ready { return 1 } |
import | Imports a package.import fmt = core.fmt |
in | Separates a loop binding from its sequence or range.for item in values {} |
inline | Embeds a structure's members in another structure.NamedPoint : struct { inline Point } |
let | Explicitly declares a constant binding.let limit : i32 = 10 |
match | Selects a result through pattern matching.label := match (code) { 0 => "ok", else => "unknown" } |
new | Allocates and initializes a value.ptr := new Point {} |
null | The null pointer value.ptr : ^Point = null |
or_default | Supplies a fallback value for an error result.value := read_value() or_default 0 |
or_error | Substitutes an error during error propagation.value := try read_value() or_error Error.Failed |
raw_union | Declares a union without a runtime tag.Value : raw_union { number : i32; decimal : f32 } |
release | Releases an allocated value.release ptr |
return | Exits a function, optionally returning a value.return 42 |
sizeof | Queries a type's size.bytes := sizeof(Point) |
step | Sets the increment of a range loop.for i in 0..10 step 2 {} |
struct | Declares a structure containing named fields.Point : struct { x : f32; y : f32 } |
switch | Branches on a value using cases.switch (code) { case 0: return 0; default: return -1 } |
true | The true boolean value.enabled := true |
try | Propagates an error result to the caller.value := try read_value() or_default 0 |
typeof | Obtains runtime type metadata.info := typeof(i32) |
union | Declares a tagged union; the enum kind identifies the active member.ValueKind : enum { Number, Text }; Value : union(kind : ValueKind) { number : i32; text : string } |
var | Declares a mutable binding.var count := 0 |
Directives and attributes
Directives begin with #. Attributes begin with @ and annotate declarations.
| Spelling | Role |
|---|---|
#if, #elif, #else, #end | Conditional compilation. |
#package | Declares a logical package. |
#import_lib | Declares a native library dependency. |
@extension | Makes a function available through method-call syntax. |
@internal | Restricts 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