Open
Description
This was discussed very early in the language design, at the same time when we also introduced iota for constant declarations: Permit iota and the omission of initialization expressions not only in constant but also variable declarations. For instance, this would permit code like:
var (
mercury = NewPlanet(iota + 1)
venus
earth
mars
...
)
If my memory serves me right, we didn't pursue it at the time because there was no compelling or urgent argument in favor of it.
Such a mechanism could simplify the construction of related named objects and open the door to "enum" values that are not restricted to constant values and their respective types.
As such it may be a more elementary building block towards more complex "enums" in Go (see also the discussion in #19814).
Implementation:
- Straight-forward changes would be required in the front-end of the compiler.
Language:
- This would be a fully backward-compatible language change.
- The change is fully orthogonal to existing features and would make variable and constant declarations more symmetric (and thus the language simpler).
- No new concepts are introduced as this is essentially syntactic sugar.