Multivariable & COLLAPSE
A multivariable is created when two or more AND branches bind to the same variable name. Using a multivariable as the operand to any verb or operation triggers parallel execution across all branches simultaneously. This is the core mechanic — one verb call, running in parallel over every branch result.
When you don't need a multivariable
Different variable names per branch — just regular variables, emit directly.
Creating a multivariable
Use the same variable name across AND branches. OQL stores each result at its branch index.
Operand fan-out — parallel execution
When you pass a multivariable as the operand to any verb, OQL executes that verb in parallel across all active branches. The output is a new multivariable — one result per branch. This is not a loop. All branches run simultaneously.
This chains — each subsequent verb that receives a multivariable keeps fanning out in parallel:
EMIT on a multivariable — one result at random
EMIT does not fan-out. It returns one active branch result at random. This is intentional — useful when parallel sources are redundant and any result will do.
COLLAPSE — all branches as an ordered array
Each element has branch (0-based index) and result. Failed branches have result: null, failed: true, plus code and message.
Accessing collapsed branches
FOREACH over collapsed results
Failed branches
A failed branch is pruned — it does not fail the entire chain. The remaining branches continue normally.
| Pattern | Variable names | Behaviour |
|---|---|---|
| Independent parallel | Different: SET ?a, SET ?b | Regular vars — emit directly |
| Multivariable + EMIT | Same: SET ?r | One random active branch result |
| Multivariable + verb operand | Same: SET ?r | Verb fires in parallel on every branch |
| Multivariable + COLLAPSE | Same: SET ?r | All results as ordered array |