Samora Lang is a simple and expressive programming language designed just for fun, mostly for learning purposes.
To get started with Samora Lang, follow these steps:
- Install the Samora Lang compiler and interpreter from the binary corresponding to your OS Architecture.
Using the Arch User Repository
$ yay -S samora-lang
- Write your Samora Lang code in a text editor or an integrated development environment (IDE).
- Save your Samora Lang code with a
.sml
extension.
To familiarize yourself with Samora Lang, here's a "Hello, World!" example:
print("Hello, World!");
let content = readFile("file.txt")
println(content)
let data = "This is some content"
writeFile("file.txt", data)
deleteFile("file.txt")
makeDir("path")
Samora Lang boasts the following key features:
Samora Lang supports recursion, allowing functions to call themselves. This enables the solution of problems that can be divided into smaller, similar subproblems. Recursive algorithms and data structures can be implemented efficiently in Samora Lang.
Samora Lang allows for nested if statements, providing the ability to have conditional statements within other conditional statements. This grants developers more control over the flow of their programs by allowing multiple conditions to be evaluated in a structured and hierarchical manner.
Closures in Samora Lang enable functions to access and manipulate variables defined outside their own scope. They capture the environment in which they are created, retaining access to variables and their values. This feature allows for the creation of functions that can "remember" and operate on specific data, even after exiting their original scope.
Here are some examples to illustrate the usage of Samora Lang's features:
let factorial = fn(n) {
if (n == 0) {
1;
} else {
n * factorial(n - 1);
}
};
let result = factorial(5);
print("The factorial of 5 is: ", result);
In this example, the factorial
function calculates the factorial of a given number using recursion.
let adder = fn(x) {
fn(y) {
x + y;
};
};
let addTwo = adder(2);
let result = addTwo(3);
print("2 + 3 = ", result);
In this example, the adder
function returns a closure that adds the provided value x
to any value y
passed to it. The closure addTwo
adds 2 to its argument 3
and returns the result 5
.
// This is a single-line comment.
# This is also a single-line comment.