Skip to content

proposal: permit iota, omission of init expressions in var declarations #21473

Open
@griesemer

Description

@griesemer

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions