Immutability

Wikipedia: Immutable object
By default, arrays and maps are mutable. The built-in immutable() returns a deeply immutable copy of any value. Attempting to modify it causes a runtime error.

fmt := import("fmt")
nums := [1, 2, 3]
nums[0] = 99
fmt.println(nums)
frozen := immutable([10, 20, 30])
fmt.println(frozen)
fmt.println(frozen[1])
config := immutable({host: "localhost", port: 5432})
fmt.println(config["host"])
fmt.println(config["port"])
data := immutable({users: ["alice", "bob"], count: 2})
fmt.println(data["users"])

try it

[99, 2, 3]
[10, 20, 30]
20
localhost
5432
["alice", "bob"]
loading…