Argentum has no statements, only expressions

In Argentum, there is an operator {A; B; C}, which executes AB, and C sequentially, returning the result of C.

Blocks can group multiple expressions:

{
    log("hello from the inner block");
    log("hello from the inner block again");
};
log("hello from the outer block");

Blocks allow local variables:

{
    a = "Hello";
    log(a);
}
// `a` is not available here anymore

Blocks can appear in any expressions, for example in a variable initializer.

x = {
    a = 3;
    a += myFn(a);
    a / 5           // this expression will become the value of `x`
};

Note the absence of a semicolon ";" after a/5. If it were present, it would indicate that at the end of the entire {} block, there is another empty operator, and its result (void) would become the result of the entire {} block.

(Furthermore, a block can serve as a target for the break/return operators, but that is a topic for a separate post).

The combined use of blocks and the "?" ":" operators enables the creation of conditional expressions similar to the if..else operators, which, by the way, are also absent in Argentum:

a < 0 ? {
    log("negative");
    handleNegative(a);
};

// or
a < 0 ? {
    handleNegative(a);
} : {
    handleOtherValues(a);
}

TLDR; Argentum eliminated the difference between statements and expressions, and thus removed lots of duplications and limitations existing in the languages with C-like syntax.

Leave a Reply

Your email address will not be published. Required fields are marked *