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 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:-
Type | Keyword | Stands for | Example |
---|---|---|---|
1. Integer | abn | abyoone | abn tirada = 10 |
2. Float | jajab | jajab | jajab qiime = 3.14 |
3. String | qoraal | qoraal | qoraal magaca = "Soplang" |
4. Boolean | bool | bool | bool sax = run |
5. List | teed | teed | teed liis = [1, 2, 3] |
6. Object | walax | walax | walax qof = {magac: "Ali"} |
// 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.
// 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"