Examples
Each example starts from a standalone .ks source file and a sibling .expected file in site/examples/. Its original expected output is checked against the interpreter. Edit the source and choose Run to produce live output, or Debug to inspect statement checkpoints and bindings. Click a recognized token for contextual help.
| Example | What it exercises |
|---|---|
| Fibonacci | Integer arithmetic, loop state, typed functions |
| Word frequency | String transformations, arrays, maps, optional lookup |
| Closure counter | Function values, captured state, independent factory calls |
| Result pipeline | Input contracts, Res, propagation, pattern matching |
| Custom iterator | Kinds, interfaces, mutable iterator state, for |
Run an example
Section titled “Run an example”Run directly in an example’s editor, or use the playground for a separate experiment. The playground guide explains stepping, stopping, resetting, and the execution budget.
From the repository root:
cargo run -- ks site/examples/fibonacci.ksTo compare its output yourself after building:
target/debug/kata ks site/examples/fibonacci.ks > /tmp/fibonacci.actualdiff -u site/examples/fibonacci.expected /tmp/fibonacci.actualNo output from diff means the text matches. If you modify a script, reason through the new output before changing its expected file.
These examples are small enough to inspect completely. They deliberately keep collection growth on direct bindings, avoid custom resource ownership, and use bounded computations. Read language status before generalizing them into larger programs.