Soplang Logo
Soplang

Variables

Declare dynamic variables with door, static types with abn, jajab, qoraal, bool, teed, and walax, and constants with madoor.

Soplang Variables

Soplang supports dynamic variables, explicitly typed variables, and constants. The declaration determines whether the variable can change type or be reassigned.

Dynamic Variables – door

Use door to declare a dynamically typed variable. Its name is associated with the Somali word doorsoome (variable).

dynamic_variables.sop

dynamic_variables.sop
door magaca = "Aamina"
door da = 19
door xaqiiqo = run

A variable declared with door can hold a value of any type, including a different type after reassignment:

dynamic_reassign.sop
door x = 10
x = "hadda waa qoraal"   // Allowed: a dynamic variable can change type
qor(x)

Declare Once

A name can be declared only once in its scope, including inside a block such as haddii or intay. To update the value, write magac = qiime without repeating door.

declare_once.sop
door a = 1
a = 2          // Valid reassignment
door a = 3     // Khalad nooc: Magaca 'a' mar hore ayaa la qeexay [E020]

Static Variables

Static variables have an explicit type annotation. The compiler and runtime enforce that type on assignments.

TypeKeywordStands forExample
Integerabnabyooneabn tirada = 10
Floatjajabjajabjajab qiime = 3.14
Stringqoraalqoraalqoraal magaca = "Soplang"
Booleanboolboolbool sax = run
Listteedteedteed liis = [1, 2, 3]
Objectwalaxwalaxwalax qof = {magac: "Ali"}

Type Checking

A typed variable keeps its declared type. The analyzer rejects mismatches it can detect before execution; assignments from dynamic values are checked at runtime. A rejected assignment preserves the previous value. An integral floating-point value can be converted to abn, but a fractional value is rejected.

static_type_error.sop
abn tirada = 10
tirada = 20            // Valid: the value is still abn
tirada = "labaatan"    // Khalad nooc: 'tirada' waa abn laakin qiimaheeda 'qoraal' ma ahan abn [E022]

To require explicit variable types, run soplang --strict file.sop. Strict mode rejects door declarations. See CLI & REPL.

Constants – madoor

Use madoor to prevent reassignment. Its name is associated with madoorsoome. A list or object held by a constant can still be changed through mutating methods; the constant does not deeply freeze its contents.

constants_basic.sop

constants_basic.sop
madoor magaca = "Soplang"

Reassigning a constant produces an error:

constants_reassign_error.sop

constants_reassign_error.sop
madoor luqad = "Somali"
luqad = "English"  // Khalad nooc: Ma bedeli kartid qiimaha doorsamaha madoor 'luqad' [E020]

Combine madoor with a static type to check the value's type as well:

constants_typed.sop

constants_typed.sop
madoor abn SANAD = 2025
madoor PI = 3.14159
qor(SANAD)

On this page