← Back to AILP Home

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

  1. Basics — arm syntax, the * catch-all, no implicit fallthrough, and the failsafe requirement.
  2. Integer dispatch & jump tables — literal integer arms, ranges, and when the backend lowers a pick to an LLVM jump table.
  3. Enums & exhaustiveness — variant arms, tagged payloads, and how covering every variant makes * optional.
  4. Strings — string-literal arms and the npk_string_equals dispatch chain.
  5. Balanced ternary (tbb) — the finite trit domain, the ERR sentinel, and sticky-ERR propagation.
  6. Fall — explicit labelled fallthrough with fall <label>; and the ARIA-PICK-004 label diagnostics.
  7. Nested picks — picks inside arm bodies, tagged-payload inner picks, and how fall resolves to the nearest enclosing pick.
  8. Guards (where) — the v0.37.6 where arm modifier, why guarded arms are excluded from exhaustiveness, and binding-scope guard expressions.
  9. Expression pick (give) — the v0.37.7 form: pick used as a value, the give <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

Validation status (v0.37.8)