← Back to AILP Home

is vs pick vs when

Nitpick has several constructs that look superficially similar. This chapter is the decision guide.

At a glance

Construct Produces a value? Branches on Best for
if / else no (statement) a bool condition running one of two code paths
is ternary yes (expression) a bool condition computing one of two values
pick statement no (statement) a value matched to arms running one of many paths
pick + give yes (expression) a value matched to arms computing one of many values
when no (statement) loop completion reacting to how a loop finished

is vs pick expression

Use is when there are exactly two outcomes selected by a boolean:

int32:x = is (ready) : 1i32 : 0i32;

Use a pick expression with give when you are selecting among several values by matching a subject:

int32:code = pick (status) {
    (200i32) { give 0i32; },
    (404i32) { give 4i32; },
    (500i32) { give 5i32; },
    (*)      { give 9i32; }
};

The pick wildcard arm is (*), not (_) — using _ raises ARIA-PICK-001. The give keyword is what makes a pick an expression; a pick without give is a statement that runs arms for their effects.

Forcing a many-way choice into nested is ternaries works but reads poorly:

// avoid: prefer a pick expression
int32:code = is (status == 200i32) : 0i32
           : (is (status == 404i32) : 4i32
           : (is (status == 500i32) : 5i32 : 9i32));

if vs pick statement

Use if/else if when the branches test independent boolean conditions. Use a pick statement when you are dispatching on the value of a single subject — pick is exhaustive-checked and clearer for value dispatch.

when is not a conditional

when is a loop-completion construct, not a conditional. It runs a then block when a loop exits cleanly and an end block when it exits via break. It appears here only to disambiguate it from the conditional family — see guide/loops/ for its full treatment.

Rule of thumb