let (Immutable Bindings)
The let keyword is used to create immutable bindings, associating a name with a value. Once bound, that name cannot point to a new value. This immutability is the default choice in Cangjie, helping you write safer and more predictable code.
In Cangjie, the basic form of variable definition is: modifier variable_name: variable_type = initial_value. The let modifier indicates that the variable is immutable, and the modifier is mandatory (cannot be omitted). Variables modified with let can only be assigned once, during initialization.
The code on the right defines three immutable bindings: name bound to a string, year bound to an integer, and pi bound to a floating-point number. The type of each variable is automatically inferred from its initial value. If you try to uncomment line 10, the compiler will report an error—let bound values cannot be reassigned.
Try adding a new let binding and printing its value, or try to modify an existing binding and observe the compiler's error message.