I have a question about defining enum. I noticed that enum member’s name cannot be reused in different enum, example as shown below:
julia> @enum FRUIT apple orange
julia> @enum COLOR red blue yellow orange
ERROR: invalid redefinition of constant orange
Stacktrace:
[1] top-level scope at none:0
seems that all enum members will be registered as a constant in same scope, so that member cannot be repeated across all enum, is it an expected behaviour?
Actually, I think orange::COLOR and orange::FRUIT should be both valid.
I rather wish we’d not shipped @enum in its current form in Julia 1.0—it’s really not great. Oh well. Better enum design is on my personal Julia 2.0 list.
The thing is that you want MyEnum.name to be the enum value named name and you want MyEnum to be the type as well. There’s also the tension between using symbols for this kind of thing versus enums. It rather seems that one wants an enum to be a limited kind of Symbol type with automatic domain checking and conversion to and from integer values for C interop.