Blocks
blocks are a syntax that allow to have locally scoped let
expressions or multiple expressions.
You can explicitly create a block using the bracket syntax:
{
let name = f();
g(); // the result of this expression is discared
h()
}
// the block is evaluated as `h()`
Functions and if
expressions implicitly create blocks:
fn {
let x = expr;
value
}
if b {
let x = expr;
value
} else {
nil
}
Blocks can be used anywhere, such as function call, if expressions, or other blocks:
let id = fn x { x }
id({ let x = 1; x + x }) // => 2