Clone
1
Examples SamplePrograms
erick-alcachofa edited this page 2025-12-30 03:08:14 +00:00
Table of Contents
Sample Program Overview
This section highlights the language features exercised by the canonical overview program distributed with the project.
- Imports: module wildcards, specific symbols, and module aliases.
- Type aliases with
usingfor types and functions. - Generics: struct definitions with
<typename T>, turbofish instantiations (e.g.,Point::<i32>). - Functions: regular functions and methods (
thisparameter syntax), return types via->. - Enums: tagged unions with
Result::<T, E>usage and variant initialization (Err{ -1 },Ok{}). - Variables:
let/defwith type inference, complex pointer/optional qualifiers (*$?combinations). - Slices: literals
[]Type { ... }, slicing syntax[start:end], specialized suffixes (.*,.#,.[len]). - Control flow: if/else with unwrapping, while loops (condition-based and iterator-style), do/while, C-style for loops, range for loops, labeled loops.
- Pattern matching:
matchwith bindings,_default;switchfor value cases. - Resource management:
defer,errdeferfor cleanup semantics. - Reflection:
. @operator to fetch metadata (.@,. @alignment,. @size).
These features can be explored by running the parser CLI against any artichoke
source file to inspect the resulting AST or diagnostics.