1. Installation
Swalang is distributed as a lightweight, pre-compiled binary. To install it on your local machine, download the package tailored for your operating system.
1. Download the Binary
Visit the official releases page on GitHub and download the appropriate zip or tarball for your platform (Windows, macOS, or Linux):
2. Configure Your Environment
Swalang includes an environment setup utility called set-swalang inside the package to automatically configure your PATH variables.
Linux & macOS
Extract the tarball, navigate to the directory, and run the configuration script:
tar -xf swalang-linux-x86_64.tar.xz
cd swalang-linux-x86_64
./bin/set-swalangWindows
Extract the zip archive, open the folder, and run the setup utility:
Double-click "set-swalang.exe"3. Verify Installation
Open a new terminal window and verify that Swalang is accessible by launching the interactive REPL shell:
$ swalang
Welcome to Swalang REPL!
Enter code to evaluate, or press Ctrl+D to exit.
swalang>>> 2. Your First Program
Swalang uses an elegant, indentation-based syntax. Create a new file named main.swa and open it in your editor.
Add the following code to print a welcome message:
# main.swa
print("Habari, Dunia!")
Run the program from your terminal using the interpreter:
$ swalang main.swa
Habari, Dunia!You have successfully written and executed your first Swalang program.
3. Learning the Basics
Swalang syntax is designed to be highly readable. Here are a few core concepts to get you started.
Variables & Assignment
Assign values directly to variables. Variables are dynamically typed and mutable by default.
name = "Swalang"
version = 1.0
version = 1.1 # Re-assignmentF-Strings (Formatted Strings)
Evaluate expressions dynamically inside string literals by prefixing the string with f:
greeting = f"Welcome to {name} version {version}!"
print(greeting)Functions
Define reusable blocks of code using the def keyword. Blocks are defined by indents (4 spaces recommended).
def greet(username):
return f"Habari, {username}!"
print(greet("Msanidi"))Control Flow
Use if, elif, and else for conditional logic:
score = 85
if score >= 90:
print("Daraja A")
elif score >= 80:
print("Daraja B")
else:
print("Jaribu tena")Object-Oriented Programming
Create blueprints for objects using classes:
class Mshiriki:
def __init__(self, jina):
self.jina = jina
def sema(self):
return f"Mimi ni {self.jina}"
mteja = Mshiriki("Amani")
print(mteja.sema())To explore the language further, head over to our comprehensive Documentation.
4. What's Next?
With the basics down, you can explore more advanced capabilities:
- Manage Packages: Install third-party modules from our repository using the built-in package manager:
swalang get <repository-url>. - Async/Await Engine: Learn how to build highly concurrent network routines using the built-in
asynciopackage. - Foreign Function Interface (FFI): Connect seamlessly to shared C libraries (like SQLite, MbedTLS, or SDL2) using the
ffimodule. - Join the Community: Contribute to Swalang's core development on GitHub.