Expression statements

Expression

The expression statement is an expression terminated with a ; to ignore its result. The most common use is the assignment to a mutable variable:

let mut a = 0;
a = 42; // an expression statement ignoring the '()' result of the assignment

For more information on expressions, check this chapter.

Semicolons

In contrast with Rust, expression statements in Zinc must be always terminated with ; to get rid of some ambiguities regarding block and conditional expressions. Let us compare the examples of Rust and Zinc to illustrate the problem.

fn blocks() -> i32 {
    {
        get_unit()
    } // a statement, but only because the block result is ()
    {
        get_integer()
    } // a return expression, only because the block result is an integer
}

In the Rust example above, the blocks are completely identical, but their semantic meaning depends on the block return type. Zinc solves this problem by enforcing all expression statements to be explicitly terminated with a semicolon, like in the following Zinc example:

fn blocks() -> i32 {
    {
        get_unit()
    }; // a statement, because it is explicitly terminated with a semicolon
    {
        get_integer()
    } // a return expression, because it goes the last in the function block
}

Conditional and match expressions follow the same rules as simple blocks.