16 let statement
let statement allows limited form of pattern matching, with
terser syntax, for example patterns can be used to decomposite tuples,
like this:
*[int, int] t = [1, 2];
...
switch t {
case [i1, i2]: return i1 + i2;
}
This can be abbreviated to:
*[int, int] t = [1, 2];
...
let [i1, i2] = t in { return i1 + i2; }
There can be more then one assignment, like this:
let [t1, t1] = t,
[s1, s2] = s {
// ...
}
The let assignment and binding names with case just creates new name for
an object. Specificly it means that assigning values to names bound
with let/case changes object itself. Example:
*[int, string] t = [1, "one"];
switch t {
case [i, _]: i = 2;
}
let [_, s] = t in { s = "two"; }
// here t == [2, "two"]
One can note that you can also decomposite t with:
string s;
int i;
[i, s] = t;
// here i = 2, s = "two"
// however:
i = 3; s = "three";
// here i = 3, s = "three", but t == [2, "two"]