if (inputs... condition trueCallable falseCallable -- outputs...)
Inputs
inputs...: Zero or more objects supplied to the selected branch; when the condition is unknown, both branches are compiled from the same input stack.condition: Non-NILCond that selects or merges branches.trueCallable: Already-selected Block called whenconditionis true.falseCallable: Already-selected Block called whenconditionis false.
Outputs
outputs...: Objects produced by the selected branch, or merged branch outputs when the condition is unknown at compile time.
if selects between two already-selected Block branches by one non-NIL Cond object.
The selected branch is called through a normal call boundary. Locals created inside a branch do not remain available afterward.
For a known condition, only the selected branch is called. The unselected branch is ignored and may be invalid. For an unknown condition, both branches are compiled separately and their outputs are merged.
Behavior
conditionmust be a non-NILCondobject.- Any additional data inputs used by a branch must already be below
condition,trueCallable, andfalseCallableon the data stack. - Before a branch is called or compiled,
condition,trueCallable, andfalseCallableare removed from the stack. Each branch sees only the remaining underlying data stack as its input. - For a known condition,
TRUEselects the first branch andFALSEselects the second branch. - For an unknown condition, both branches are compiled from the same input stack.
- When both branches are compiled, their stack outputs must be compatible; otherwise compilation fails.
Example
{} 0 {} [
"-- known TRUE selects the first branch --" printCompilerMessage
TRUE [
1
] [
impossibleName
] if printStack _:;
"-- known FALSE selects the second branch --" printCompilerMessage
FALSE [
impossibleOtherName
] [
2
] if printStack _:;
condition: FALSE dynamic;
"-- unknown condition compiles both branches --" printCompilerMessage
condition [
"-- unknown true branch --" printCompilerMessage
1
] [
"-- unknown false branch --" printCompilerMessage
2
] if printStack _:;
0
] "main" exportFunction
Expected Output During Compilation
-- known TRUE selects the first branch --
1
-- known FALSE selects the second branch --
2
-- unknown condition compiles both branches --
-- unknown true branch --
-- unknown false branch --
Int32
See also
callbuiltin(inputs... callable -- outputs...)Calls an already-selected Block, Code, callable Dict, or known Text through a call boundary. No selection happens inside the builtin.loopbuiltin(inputs... callable -- outputs...)Repeatedly calls one already-selected Block through a call boundary. The run-time repetition invariant is(A -- A Cond): each body call preserves the carried stack’s shape — the number of objects and their schemas — not necessarily their values, and leaves a final Cond; known-condition iterations may add items or change schemas.ucallbuiltin(inputs... callable -- outputs...)Processes an already-selected Block or known Text inline in the current scope.uifbuiltin(inputs... condition trueCallable falseCallable -- outputs...)Selects between two already-selected Block branches by a known Cond and processes the selected branch inline. No branch-output merge occurs.