1
Examples SamplePrograms
erick-alcachofa edited this page 2025-12-30 03:08:14 +00:00

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 using for types and functions.
  • Generics: struct definitions with <typename T>, turbofish instantiations (e.g., Point::<i32>).
  • Functions: regular functions and methods (this parameter syntax), return types via ->.
  • Enums: tagged unions with Result::<T, E> usage and variant initialization (Err{ -1 }, Ok{}).
  • Variables: let/def with 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: match with bindings, _ default; switch for value cases.
  • Resource management: defer, errdefer for 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.