Yet another programming language!
Everything is in constant movement and subject to change, but since I'm mainly working on the interpreter now, the syntax should not change all so much.
To run a program:
python3 ns2c.py <file.ns>
fn main() -> int {
printf("Hello, world!\n");
return 0;
}
Hello, world!
To run a program:
python3 ns2sml.py <file.ns>
// Basic hello world
print("Hello, world!");
Hello, world!
// Variables are declared with `let`
let x = 1;
if (x == 1) {
print("Wow!");
}
// Curly braces are optionnal for if bodies
else
print("What?");
Wow!
// Code blocks return the last value that was evaluated inside of them
print({
print("Hello,");
"world!";
});
Hello,
world!
// Which also means that `return` is optionnal when at the end of a function body
fn hello() {
// same as `return "Hello, world!";`
"Hello, world!";
}
print(hello());
Hello, world!
let a = [];
a:push(42); // Methods are called with a ':'
// For now there only is a for ... in ... scheme
// the `i` is optionnal
for i, item in a {
print(i,item);
}
let i = 0;
while (i < 10) {
print(i);
i++;
}
let x = 1;
print(
x
=> y (y +2) // Allows to reference a value inside an expression
=> (it *4) // The name defaults to `it`
);
12
let x = 1;
print(
x
=> &y (y +1) // Adding an `&` allows to run the expression while returning the base value
=> &(it *2) // It could be useful for initialization, or fluent patterns where they're not supported
);
1
let a = and();
// Creates a logic gate and connects it to the previous one
let b = and() -> {
:connect(a);
};
// The language also allows to reference / dereference values
let x = 1;
let y = &x;
*y = 2;
print(x);
2
// A "fun" way to use references
let a = [];
a:push(42);
print(a);
*&[]::push = fn (value) {
print("Array:push got replaced!");
};
a:push(12);
print(a);
[42]
Array:push got replaced!
[42]