Soplang Documentation

website·Indexed 31 days ago

https://soplang.org

A programming language designed to be intuitive and powerful with a Somali-first approach. Documentation covers installation, syntax, data types, variables, operators, conditional statements, loops, functions, and built-in keywords.

Tokens
6.8K
Snippets
64
Records
68
Agent score
62%

What's inside Soplang

  1. Overview of Soplang

    Soplang is an open-source programming language released under the MIT License. It is designed for simplicity, readability, and power, specifically allowing developers to write code in the Somali language.
  2. Install Soplang via binary download

    To install Soplang on any platform, download the latest release from the downloads page, extract the package, and ensure the soplang binary is in your system's PATH. For UNIX-like systems, you may need to grant execute permissions to the binary using chmod +x.
    # Add binary directory to PATH (example for shell/zsh)
    echo 'export PATH="$HOME/bin:$PATH"' >> ~/.shellrc && source ~/.shellrc
    
    # Grant execute permissions if needed
    chmod +x /path/to/soplang
    
    # Verify installation
    soplang --version
  3. Define and call functions in Soplang

    Functions in Soplang (referred to as 'hawlo') are reusable blocks of code. A function is defined using the hawl keyword followed by the function name and parameters. Parameters do not require type annotations. To execute a function, call it by its name and pass the required arguments.
    // Defining a function
    hawl salaan(magac) {
      qor("Asalaamu calaykum, " + magac)
    }
    
    // Calling the function
    salaan("Aamina")
  4. Convert and Cast between abn and jajab

    When mixing abn (integers) and jajab (decimals) in operations, the result is typically a jajab. To force a specific type, use the abn() or jajab() casting functions. Using abn() on a decimal result performs truncation.
    abn a = 5
    jajab b = 2.0
    
    // Result is decimal
    door c = a + b
    qor(c)          // 7.0
    qor(nooc(c))    // "jajab"
    
    // Force integer (truncation)
    abn d = abn(a / b) // 10 / 3 becomes 3
    qor(d)          // 2
    
    // Force decimal
    jajab e = jajab(a * 2)
    qor(e)          // 10.0
  5. Implement control flow in Soplang

    Soplang provides keywords for conditional branching (haddii), pattern matching (dooro), for-loops (kuceli), and while-loops (intay).
    // If-Else
    haddii (da >= 18) {
        qor("Qof weyn")
    } ugudambeyn {
        qor("Ilmo")
    }
    
    // Switch/Match
    dooro (qora) {
        xaalad "Salaan" { qor("Hello!") }
        ugudambeyn { qor("Unknown") }
    }
    
    // For loop: (variable start to end :: step)
    kuceli (i 1 ilaa 5 :: 2) {
        qor(i)
    }
    
    // While loop
    abn x = 1
    intay (x < 3) {
        qor(x);
        x = x + 1
    }
  6. Implement conditional logic using if, else if, and else in Soplang

    Soplang uses Somali keywords for conditional execution. The haddii keyword functions as if, haddii_kale as else if, and ugudambeyn as else. Each block must be enclosed in curly braces {}. These statements can be nested as needed.
    abn da = 17
    
    haddii (da >= 18) {
      qor("Waad qaan gaadhay")
    } haddii_kale (da >= 13) {
      qor("Waxaad tahay dhallinyaro")
    } ugudambeyn {
      qor("Waad yar tahay")
    }