Just why... why does this generate an error?
Is it because it reallocates the map to allow the extension or just because the compiler parser is not meant to handle these cases?
const (
paths = &map[string]*map[string]string {
Smith: {
"theFather": "John",
},
}
paths["Smith"]["theSon"] = paths["Smith"]["theFather"] + " Junior"
)
Constants are called constants for a reason: you expect them to be just that: constant.
The type defines what operations you may perform on a value of that type. The map type in Go is not constant, you can change its key-value pairs after its creation, so you cannot have map
constants.
Your "palette" to choose constants from is defined in the Spec: Constants:
There are boolean constants, rune constants, integer constants, floating-point constants, complex constants, and string constants.
See related question: Declare a constant array
Workaround is simple: declare it to be a variable instead of a constant.