if

if (condition trueCallable falseCallable -- branchResult)

Inputs

Outputs

if selects between two already-selected Block branches by one non-NIL Cond value.

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

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