Variables and Mutability
Last modified: 24 May 2026
What is this?
Variables in ArkCode are strongly typed, safely managed data containers. They follow a strict immutability-by-default design inspired by Kotlin, abandoning the traditional const and let paradigms in favor of a much stricter, intent-driven syntax.
What is its purpose?
The purpose is to store string, number, or object data in memory without risking memory leaks, type confusion, or accidental data mutation.
Where and how it can be used
You use them everywhere to store state. There are exactly two ways to store state in ArkCode. You define a strict constant with value, and a dynamic mutable container with varue.
value maxRetries = 5 // Immutable
varue currentStatus = "Booting" // Mutable
// Later in execution...
currentStatus = "Online"How it works
Under the hood, ArkCode uses RcValue (Automatic Reference Counting utilizing std::shared_ptr) to handle all heap values and prevent memory leaks. String variables are represented by SsoString, which implements Small String Optimization (SSO)—storing strings up to 15 characters in an inline stack buffer to avoid expensive heap allocations, while dynamically allocating memory on the heap only for longer strings.
If a script attempts to overwrite an immutable value, the compiler will catch it, preventing compile or JIT operations. Additionally, the static analyzer performs checks to detect variables declared as mutable varue but never reassigned, issuing a warning diagnostic: [ArkCode Warning] Variable '...' is declared mutable 'varue' but is never modified. Consider using 'value' instead.
Where it can't be used and why
You cannot use variables without initializing them immediately. Because ArkCode enforces absolute safety, uninitialized variables (e.g., value x;) are syntactically forbidden to completely eradicate null pointer exceptions and undefined memory states.