Let declarations

There are two types of let declarations:

A toplevel let is a statement:

let name = value;
// name is bound here

and binds the value x to the assigned value for the rest of the program.

Let statements can have a pub modifier that makes the value visible from other modules

pub let name = value;

Otherwise, if a let appears inside a block, it is considered an expression:

{
    let name = value;
    body // name is bound here
}
// name is unbound here

For instance, you can write:

// num is now equal to 2
let num = {
  let x = 1;
  x + x
}

If you want to nest let expressions, you can do that in the same block instead of creating nested blocks:

{
  let x = 42;
  let y = y + 1;
  x + y
}

A let declaration is always immutable, meaning that the value cannot be changed afterwards, and further re-declaration of the same value are allowed, but shadow the original value.