Skip to content

solus 0.4

Pre-release
Pre-release

Choose a tag to compare

@septumfunk septumfunk released this 22 Jan 09:14
· 131 commits to dev since this release

This release brings some cool features like trailing returns and scopes as values. This also allows you to do some cool things like using the language as a config file. This is shown in the config.sol example!

Scopes as Values

Scopes can now return a value by writing an expression at the very end of the scope without a semicolon following it. This is called a trailing return and applies to all scopes in solus (including functions). The return keyword will return the function rather than evaluating the scope as a value, so be wary about when you return and when you trailing return.

let x = do {
    let y = 4;
    y + 2 // Trailing return
    // Any code here will be unreachable
};
// This file simply returns the object
{
    lol = 2
}

There is also a new obj.stringify() function for this purpose.

If/Else as an Expression

You may now use if/else pairs as an expression, which will evaluate similarly to a ternary in another language. The syntax of the if/else statements has also been refined to include a colon due to dangerous ambiguity. You are required to follow if with else when attempting to use it as an expression.

let x = if true: 1 else: 2;

"Self" Reserved Identifier

There is a new reserved identifier called self that is only available when constructing objects. This identifier will evaluate to the future storage location of the object being constructed, meaning it can be captured as an upvalue during construction.

{
    new = [](){{
        lols = 0
        lol = [self]() { self.lols += 1; }
    }}
}

This allows for what is essentially a basic form of oop, lacking inheritance.