Pick Cookbook
This subsection of the guide is a focused, example-driven reference for
Nitpick's pick construct as it stands at the close of the v0.37.x cycle. It
complements the shorter overview in
control_flow/pick.md by walking through every
dispatch shape pick supports, the exhaustiveness rules, the fall and
where arm modifiers, and the v0.37.7 expression form that yields a value.
pick is not a C switch. There is no implicit fallthrough, the catch-all
arm is * (never _), arms are comma-separated, and the compiler proves the
match is exhaustive at compile time.
Chapters
- Basics — arm syntax, the
*catch-all, no implicit fallthrough, and thefailsaferequirement. - Integer dispatch & jump tables — literal integer arms, ranges,
and when the backend lowers a
pickto an LLVM jump table. - Enums & exhaustiveness — variant arms, tagged payloads, and how
covering every variant makes
*optional. - Strings — string-literal arms and the
npk_string_equalsdispatch chain. - Balanced ternary (
tbb) — the finitetritdomain, the ERR sentinel, and sticky-ERR propagation. - Fall — explicit labelled fallthrough with
fall <label>;and theARIA-PICK-004label diagnostics. - Nested picks — picks inside arm bodies, tagged-payload inner
picks, and how
fallresolves to the nearest enclosing pick. - Guards (
where) — the v0.37.6wherearm modifier, why guarded arms are excluded from exhaustiveness, and binding-scope guard expressions. - Expression pick (
give) — the v0.37.7 form:pickused as a value, thegive <expr>;yield, arm-type unification, and mandatory exhaustiveness.
Each chapter is short and self-contained — read whichever one matches the problem in front of you.
Conventions used in these chapters
- Examples are minimal
func:mainprograms that compile and run withnpkc. - Every program includes a
func:failsafe— it is the mandatory error endpoint. - The catch-all arm is written
(*)._is not a pick wildcard (ARIA-PICK-001); it is the discard binding used elsewhere in the language. - Diagnostics are quoted as the compiler emits them, with the
ARIA-PICK-NNNcode. - Where K semantics is referenced, the corresponding
tests/core/test number is given in parentheses, e.g.(K test 031).
Validation status (v0.37.8)
- Compiler CTest: 181/181.
- K core tests: 215/215.
- Pick-related bug regressions: bug808 … bug859 (v0.37.0 … v0.37.8).
- Diagnostics:
ARIA-PICK-001(_wildcard),ARIA-PICK-002(duplicate arm),ARIA-PICK-003(unreachable arm),ARIA-PICK-004(badfalllabel).