Re:Apple Watch is encoding each frame as PNG
by Someone on Saturday December 05, 2015 @03:51PM
(#10683236)
It also is one of the only languages where collections are value types.
And it has to, to make 'let' create truly immutable objects. Without them, this:
var a = [1,2,3]
let b = a
a += [4,5,6]
would change b.
Re:Apple Watch is encoding each frame as PNG
by lionet on Saturday December 05, 2015 @11:28PM
(#10684408)
You are correct. But in FP, we understand immutability differently, so it becomes very painful to watch structural equivalence of the following variables:
class Foo { var x = 0 }
let a = [Foo(), Foo(), Foo()]
var b = a
a[0].x = 1
var c = b // [0].x == 1 ;(
let d = a // [0].x == 1 ;(
That is at best misleading, as it is not true for collections. From the Swift docs:
> If you create an array, a set, or a dictionary, and assign it to a variable, the collection that is created will be mutable. This means that you can change (or mutate) the collection after it is created by adding, removing, or changing items in the collection. If you assign an array, a set, or a dictionary to a constant, that collection is immutable, and its size and contents cannot be changed.
Swift is the only language that I've seen that actually does make a distinction depending on the keyword used.