> But on the other hand there is a common expectation that it is
> possible to write a loop over all enumeration values, which is easy in
> C but is not clearly supported by your suggested syntax

Yeah, I had this in mind but forgot to add it. I thought we could just use 
`range` like below:
```
type Foo string (
  A
  B
  C
)

for val := range Foo {} 
// or
for i, val := range Foo {}
```

> The problem I see is that people want different things from
> enumeration types, and what they want in Go tends to depend on what is
> provided by other languages with which they are familiar.
> I think it's necessary to first discuss the desired set of features.
> Until that is done, syntax can be a distraction.

Yup, agreed. I suggested a syntax that would keep enums simple without 
doing too much like some other languages. But again, many people would like 
those features and there are valid use cases for them. Thanks for reviewing 
it nonetheless!

On Saturday, November 13, 2021 at 3:25:58 AM UTC+5:30 Ian Lance Taylor 
wrote:

> On Fri, Nov 12, 2021 at 9:20 AM Shreyas Sreenivas
> <shreyas.s...@gmail.com> wrote:
> >
> > Note, I've already looked at https://golang.org/issue/28987, 
> https://golang.org/issue/19814, and https://golang.org/issue/28438. All 
> of them require them to make a change that breaks the compatibility 
> promise. I want to explore another way of defining enums that is backward 
> compatible.
> >
> > Enums as types with constrained values
>
> ...
>
> > ```go
> > type Operation string (
> > Sum = "+"
> > Product = "*"
> > Difference = "-"
> > Quotient = "%"
> > )
> > ```
>
> The problem I see is that people want different things from
> enumeration types, and what they want in Go tends to depend on what is
> provided by other languages with which they are familiar. For
> example, in C there is no notion of a string associated with an enum.
> But on the other hand there is a common expectation that it is
> possible to write a loop over all enumeration values, which is easy in
> C but is not clearly supported by your suggested syntax.
>
> I think it's necessary to first discuss the desired set of features.
> Until that is done, syntax can be a distraction.
>
> Ian
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/161e0f1c-24f0-4680-bc20-e8b66e0b35fdn%40googlegroups.com.

Reply via email to