Examples cookbook
Short, runnable Silicon programs grouped by what they teach. Each page is self-contained — copy the source into src/main.si, sgl run.
| Example | Teaches |
|---|---|
| Hello world | Project scaffold, @fn main, @export |
Sum types + @match | @type, variant constructors, arm-expression form |
| Generics | @fn[T], parametric sum types, HM-lite inference |
Error handling with @try | Result[T,E], prefix-keyword unwrap shorthand |
| Arena allocation | with_arena, parent-arena escape |
| Rc smart pointer | Shared ownership, refcount semantics |
| Writing a stratum | Adding a keyword via @stratum |
| Strata as design solvent | Building a small DSL with strata |
| QBE native compile | sgl build --release, freestanding binary |
| First-class functions | Function references, call_indirect |
How to run any example
sh
sgl init scratch
cd scratch
# paste the example body into src/main.si
sgl runIf an example needs the standard library, add @use 'stdlib/path.si'; at the top — sgl init already wires io.si in for you.
Want more?
These ten cover the surface; the full test suite under src/ is the biggest corpus of real Silicon. Look at any *.test.ts — most embed representative programs as backtick-delimited strings.