Waxaan qoraynaa oon dib uhabeyn ku wadnaa docs oo af-soomaali ku qoran, ka qeybqaadasho raac lifaaqaan...Contribution guidelines

Soplang Variables

Variables in Soplang are containers for storing data values. Soplang offers the flexibility of both dynamic and static typing, allowing you to choose the approach that best fits your needs while maintaining type safety.

Variable Declaration

Dynamic Typing

In Soplang, you can declare variables with dynamic typing using the door keyword. The type of the variable is determined by the value assigned to it.

The door keyword is short for doorsoome, which means "variable" in Somali. This abbreviation was chosen to make the code more concise while preserving its Somali roots.

dynamic_typing.sop
// Dynamic typing with door
door name = "John"     // String
door age = 25         // Number
door is_student = true  // Boolean
door grades = [85, 90, 78, 92]  // List/Array

Static Typing

For more type safety, Soplang also supports static typing where you explicitly declare the type of the variable.

Static variables are explicitly typed and use specific keywords for type clarity. some of them are:-

TypeKeywordStands forExample
1. Integerabnabyooneabn tirada = 10
2. Floatjajabjajabjajab qiime = 3.14
3. Stringqoraalqoraalqoraal magaca = "Soplang"
4. Booleanboolboolbool sax = run
5. Listteedteedteed liis = [1, 2, 3]
6. Objectwalaxwalaxwalax qof = {magac: "Ali"}
static_typing.sop
// Static typing with specific type keywords
abn count = 10           // Integer 
qoraal message = "Hello"  // String
bool active = true   // Boolean

// Type mismatch will cause an error
abn wrong = "text"  // Error: Cannot assign string to abn

Constants

Constants are variables whose values cannot be changed after initialization. In Soplang, you declare constants using the madoor keyword.

constants.sop
// Defining constants
madoor PI = 3.14159
madoor MAX_USERS = 100
madoor APP_VERSION = "1.0.0"


// Constants cannot be reassigned:
madoor luuqad = "Somali"
luuqad = "English"  // Error: cannot reassign constant

// Using constants
door radius = 5
door area = PI * radius * radius
qor("Area: " + area)  // Prints "Area: 78.53975"