Variables SET | UNSET

Variables in OcaltQL are declared by type, assigned with SET, and addressed with a ? prefix. They are case-sensitive, exist at runtime level, and can be explicitly destroyed with UNSET.

Declaring a Variable

A variable is created by combining a type constructor with SET ?name. The type constructor defines what kind of value is being stored.

Number Variable
NUMBER 1000 SET ?numbervar
AFTER EMIT ?numbervar
String Variable
STRING "hello" SET ?var
AFTER EMIT ?var

Variable Names

All variable names begin with ?. Variable names are case-sensitive?var and ?Var are two different variables. Everything else in OcaltQL is case-insensitive, but variable names are not.

?var and ?Var are not the same variable.

SET

SET ?name always appears at the tail of a statement. It captures the result of the operation that precedes it and stores it under that variable name for the remainder of the script execution.

A variable can be overwritten by setting it again:

Overwriting a Variable
STRING "hello" SET ?var
AFTER STRING "world" SET ?var
AFTER EMIT ?var

UNSET

UNSET ?name destroys the variable entirely. After an UNSET the variable no longer exists in the current execution state — it is not null, it is gone.

Unsetting a Variable
STRING "hello" SET ?var
AFTER EMIT ?var
AFTER UNSET ?var
AFTER EMIT ?var
UNSET cannot be an AND branch. UNSET must be its own AFTER step. Placed directly in an AND statement it destroys only that branch's own copy of the variable, and the original survives — the deletion does not cross back when the branches rejoin. This is true wherever the AND sits, including on a line of its own.
Wrong — UNSET Directly in an AND Statement
STRING "hhhh" SET ?u
AFTER CALCULATE 1 + 1 SET ?v AND UNSET ?u
AFTER EMIT ?u
(* Emits hhhh. ?u still exists — the UNSET ran in a parallel branch
   and destroyed only that branch's copy *)
Right — UNSET as its Own AFTER Step
STRING "hhhh" SET ?u
AFTER CALCULATE 1 + 1 SET ?v
AFTER UNSET ?u
AFTER EMIT ?u
(* Emits nothing — ?u is gone *)
Inside an IF, WHILE or LOOP body UNSET behaves normally — a block shares the surrounding execution state, so the variable is genuinely destroyed. Only a parallel AND branch is separate.

Checking if a Variable Exists

Use IF ?var IS SET to check whether a variable currently holds a non-null value. A variable that was never declared, or was explicitly UNSET, is not SET — but a variable holding an empty string, an empty array, false, or 0 is still SET, since it exists and is not null. See Execution States for the full state reference.

OR following an IF block acts as the fallback — it executes when the condition is false.

IS SET Check
STRING "hello" SET ?var
AFTER EMIT ?var
AFTER UNSET ?var
AFTER IF ?var IS SET
OPEN
  EMIT "exists"
CLOSE
OR
OPEN
  EMIT "gone"
CLOSE
In the example above, EMIT "gone" fires because ?var was unset before the check. The variable does not exist — it was not set to null, it was removed entirely.

Variable-to-Variable Assignment

A variable can be assigned directly from another variable, without a type constructor. Two equivalent forms exist:

SET ... AS Form
STRING "hello" SET ?var1
AFTER SET ?var2 AS ?var1
AFTER EMIT ?var2
VARIABLE ... SET Form
STRING "hello" SET ?var1
AFTER VARIABLE ?var1 SET ?var2
AFTER EMIT ?var2

Both forms also work with objects and arrays — see Arrays & Objects for examples.

Variable Scope

Variables exist for the duration of a single script execution. Every request to the OcaltQL runtime starts with a clean state. Variables do not persist between executions unless explicitly stored using REMEMBER or session mechanisms.