Multivariables & Parallel Execution

When the same variable name is assigned across parallel AND branches, it becomes a multivariable — holding all assigned values simultaneously. Operations on multivariables propagate across every branch in parallel.

Parallel Execution with AND

When AND branches assign the same variable name, no single value wins — the variable becomes a multivariable. Emitting it directly returns one value at random. To access all values, use COLLAPSE.

Same Variable — Multivariable Created
STRING "hello" SET ?var AND STRING "world" SET ?var
(* ?var is either "hello" or "world" — never both *)
Different Variables — All Branches Complete
NUMBER 10 SET ?x AND NUMBER 20 SET ?y AND NUMBER 30 SET ?z
(* ?x, ?y, ?z each get one random value from their parallel branches *)
Branches carry assignments back, not deletions. Each AND branch works on its own copy of the execution state, and only assignments are merged back when the branches rejoin. UNSET inside a branch therefore destroys only that branch's copy and the variable survives into the statements that follow. Give UNSET its own AFTER step instead — see Variables SET | UNSET.

COLLAPSE

COLLAPSE converts a multivariable into an ordered array. The order follows the declaration order of the AND branches in the script. Once collapsed, values are accessible by zero-based index using ?var(n).

COLLAPSE to Ordered Array
STRING "alpha" SET ?arr AND STRING "beta" SET ?arr AND STRING "gamma" SET ?arr
AFTER COLLAPSE ?arr SET ?arr
AFTER EMIT ?arr(0)
AFTER EMIT ?arr(1)
AFTER EMIT ?arr(2)
(* Output: alphabetagamma *)

COLLAPSE to a New Variable

Collapsing to a new variable preserves the original multivariable. The multivariable remains intact while the new variable holds the ordered array.

Preserve Original Multivariable
STRING "first" SET ?multi AND STRING "second" SET ?multi
AFTER COLLAPSE ?multi SET ?collapsed
AFTER EMIT ?collapsed(0)
AFTER EMIT ?collapsed(1)
(* ?multi remains a multivariable, ?collapsed is the ordered array *)

Parallel with Calculations

Parallel branches are not limited to string or number assignment. Any value-returning verb can run in parallel.

Parallel Calculations
CALCULATE 1 + 1 SET ?result AND CALCULATE 2 + 2 SET ?result
(* ?result is either 2 or 4 *)

AFTER Waits for All Branches

AFTER always waits for every parallel AND branch to complete before the next statement runs. If branches set different variables, all variables are available to the next statement.

AFTER Waits for All
STRING "A" SET ?a AND STRING "B" SET ?b
AFTER EMIT ?a & ?b
(* Output: AB — both branches complete before EMIT runs *)

Operations on Multivariables Propagate

When a multivariable is used as an input to a subsequent operation, that operation runs once per branch — in parallel. The result is itself a new multivariable, one branch per input branch.

Propagation Through Calculation
NUMBER 88 SET ?num AND NUMBER 11 SET ?num
AFTER CALCULATE ?num + 12 SET ?newnum
(* ?newnum has TWO branches: 100 AND 23, in parallel *)
AFTER EMIT ?newnum
(* Output: 100 OR 23 — random *)
Propagation Through String Operation
STRING "hello" SET ?greet AND STRING "hi" SET ?greet
AFTER STRING ?greet & " world" SET ?fullgreet
(* ?fullgreet has TWO branches: "hello world" AND "hi world", in parallel *)
AFTER EMIT ?fullgreet
(* Output: "hello world" OR "hi world" — random *)
Operations on multivariables do not collapse them. The parallel structure propagates forward until you explicitly call COLLAPSE.