← Back to AILP Home

Pick Basics

pick dispatches on a single selector value. Each arm is a pattern in parentheses followed by a brace block; arms are separated by commas.

func:failsafe = int32(tbb32:err) { exit 1i32; };
func:main = int32() {
    int32:x = 2;
    pick (x) {
        (1) { println("one"); },
        (2) { println("two"); },
        (*) { println("other"); }
    }
    exit 0i32;
};

The shape of an arm

(pattern) { body }

The * catch-all

For a selector with an infinite domain (int32, string, …) you must provide a (*) arm, or cover the domain some other way, or the compiler rejects the program as non-exhaustive:

error: Non-exhaustive pick statement. Missing cases: -2147483648..0, 3..2147483647

* is the only spelling of the wildcard. Writing _ is a compile error:

pick (x) {
    (1) { exit 1i32; },
    (_) { exit 0i32; }   // ARIA-PICK-001
}
error: ARIA-PICK-001: '_' is not a pick wildcard pattern — use '*' for the catch-all arm

No implicit fallthrough

Unlike a C switch, control never falls from one arm into the next. When an arm finishes, the whole pick is done. To deliberately continue into another arm, use fall.

The failsafe endpoint

Every Nitpick program defines func:failsafe. It is the error endpoint reached by unrecoverable failures; a pick over a tbb selector whose value is the ERR sentinel routes there. See the tbb chapter.

(K test 031 covers integer arm matching; K test 032 covers bool selectors.)