Chaining AND | AFTER | OR

OcaltQL statements are connected by chain keywords. AFTER runs things in sequence. AND runs things in parallel with a random winner. OR runs the next statement only when the previous returns false, null, or a soft error.

AFTER — Sequential Execution

AFTER waits for the preceding statement to complete before running the next. Output appends in the order statements execute.

Example
EMIT "A" AFTER EMIT "B" AFTER EMIT "C"
(* Output: ABC *)
Sequential Over Multiple Lines
EMIT "start"
AFTER EMIT "middle"
AFTER EMIT "end"
(* Output: startmiddleend *)

AND — Parallel Execution

AND runs both sides simultaneously. The output is intentionally random — one side wins, the other is discarded. This randomness is enforced by the runtime, not a side effect of timing. When used with variables, the winning side writes the value.

AND never produces both results. One wins at random. The other is discarded entirely.
Random Winner
EMIT "heads" AND EMIT "tails"
(* Output: heads OR tails — random, never both *)
AND with Variables
STRING "hello" SET ?a AND STRING "world" SET ?a
(* ?a is either "hello" or "world" — never both *)

AND Creates Multivariables

When the same variable name is assigned across parallel AND branches, it becomes a multivariable — it holds all assigned values simultaneously. Direct emission of a multivariable is random. Use COLLAPSE to convert it into an ordered array.

This is distinct from reassigning with AFTER — an AFTER reassignment simply overwrites the variable. No multivariable is created.

Multivariable via AND
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 *)
AFTER Reassignment — No Multivariable
STRING "first" SET ?var
AFTER STRING "second" SET ?var
AFTER EMIT ?var
(* Output: second — ?var was overwritten, not multiplied *)

OR — Fallback Execution

OR executes its statement only when the preceding statement returns FALSE, NULL, or a soft error. If the preceding statement succeeds, the OR branch is skipped entirely.

OR Fallback
EMIT "primary" OR EMIT "fallback"
(* Output: primary if it succeeds, fallback if primary returns false, null, or soft error *)
OR with Variables
STRING "" SET ?empty OR STRING "fallback" SET ?result
AFTER EMIT ?result
(* Output: fallback *)

Combining Chains

Chain keywords can be combined freely. AFTER waits for all preceding branches — including any AND parallel branches — to complete before continuing.

AFTER Following AND
EMIT "first"
AFTER STRING "X" SET ?x AND STRING "Y" SET ?x
(* Output: first — then ?x is either "X" or "Y"
   AFTER waits for both AND branches before proceeding *)
AFTER always waits for all parallel AND branches to finish before the next statement runs. If a branch fails, it returns null for that branch only — the others continue normally.