5. Bindings
5.1 let and var#
let limit = 10
var count = 0
count += 1
let point: Point = Point(x = 1.0, y = 2.0)let binds once and cannot be assigned again. var may be assigned again with a value of the same type. Every binding has an initialiser; there is no uninitialised variable and no zero value. A binding's type may be written after :, and must be when the initialiser is none, [] or {}.
A let of a class or collection prevents rebinding, not mutation: the object is shared and its var fields and its elements change through any binding. A let of a struct is immutable through and through.
5.2 Tuples and destructuring#
let (quotient, remainder) = divide(17, 5)
let (name, _) = pairA tuple destructures into as many bindings as it has members; _ discards one.
5.3 Assignment#
= assigns a var, a var field through any path, an element of a list or map, or a tuple of those from a tuple. +=, -=, *=, /=, //=, %= read then write once. The place is evaluated before the value.