constant - pannous/warp GitHub Wiki

constant

A const name keeps its value for good: it can neither be assigned again nor changed inside. final and let mean the same, and var is the changeable one (see mutability):

# each marked line is refused
const xs = [1 2]
xs = [3 4]     // xs is const, cannot assign it again
xs#1 = 3       // changing inside is refused too
var xs = [1 2]
xs#1 = 3
xs             // [3 2]

Other languages split the two kinds of constance: a constant reference to a changeable object (Java's final, Dart's final xs=[1,2,3]; xs[0]=0 is ok) and a constant object in a changeable variable (Dart's var xs = const [1,2,3]). Angle has one deep const instead.