Saturnus
Jump to navigation
Jump to search
Saturnus, while technically not an esolang, is a programming language that aims to have a simplified mix of Rust programming language and Lua.
The main target for Saturnus compiler is Lua, but multi-target compilation will arrive in the future, so stay tuned if you like the language.
The original purpose of this language was to provide an easy-to-learn syntax, and fast compilation times, to replace Lua scripts.
Examples
// Variables are easy stuff in Saturnus: let a = "be something"; // period.
Operators
// Addition is more idiomatic than in plain Lua syntax: count += 1; strcat ++= "foo'd"; // Basic operators include + - * / ** % and ++ (String concat) let a = b + c;
Classes
// Basic OOP class Foo { fn new() { return Foo {}; } fn greet(self) { print("Hello world!"); } } // Note the differences between dispatch types let instance = Foo.new(); instance->greet();
Collections
// Collection types: let this_is_a_table = { a, b: "foo", c: 30-30 }; let this_is_a_vector = [1, 2, 3, (), "potato"]; let this_is_a_tuple = ("foo", 10, "bar");
Loops
// The basic loop! // Will repeat as long as the expression between "while" and "do" words is // true-like (Can evaluate to "true"). while something() { print("Something is true!"); } // This one is a sugar syntax introduced by Saturnus! // Imagine you want to loop as long as you have a result that is not null, you // could use iterators, reserve your own local variables and such, but we // have a more idiomatic syntax sugar for you: while let some = thing() { // The "some" variable is only visible within the loop, and you know that // will be a true-ish value (Like 1, true or something not null). print("Some is " ++ some); } // Numeric for? Easy: for i in 1..10 { print("i = " ++ i) } // Now, the classical foreach: for entry in entries() { print(entry._0 ++ " = " ++ entry._1); } // Note: This is a raw iterator loop, and cannot be used in place of an // iterator! This means that is no replacement for pairs function (and also // it does NOT work well with it...) // This assumes that what you have between "in" and "do" returns an iterator // of a single entry value. // To transform collections to iterators, you will need some prelude functions. // And the final, the simplest and the dumbest: loop { print("I'm looping forever..."); if should_exit() { print("Or I am?"); return true; } } // Note: Has no exit condition, you will have to either "break" or "return"!