DIPX: Enum Literals / Implicit Selector Expression

ryuukk_ ryuukk.dev at gmail.com
Thu Jun 30 20:33:16 UTC 2022


On Thursday, 30 June 2022 at 16:25:35 UTC, The Zealot wrote:
> On Thursday, 30 June 2022 at 15:42:05 UTC, ryuukk_ wrote:
>> On Thursday, 30 June 2022 at 11:03:08 UTC, bauss wrote:
>>> On Thursday, 30 June 2022 at 10:58:37 UTC, Mike Parker wrote:
>>>> [...]
>>>
>>> What it seems like it's trying to solve is this:
>>>
>>> ```d
>>> SomeEnum.a | SomeEnum.b | SomeEnum.c
>>> ```
>>>
>>> So you could instead do:
>>>
>>> ```d
>>> .a | .b | .c
>>> ```
>>>
>>> But much like you I don't think that's at all clarified, 
>>> maybe I would settle for something like this:
>>>
>>> SomeEnum(a | b | c) as that clearly tells you it's SomeEnum 
>>> and then it's clear you're picking the values from that, so 
>>> a, b and c will __always__ be from SomeEnum.
>>>
>>> But personally I don't really like that syntax either as it 
>>> clashes too much with struct ctors and/or function calls.
>>>
>>> So I don't have an actual good solution, so I guess in the 
>>> end I'm not for any changes.
>>
>>
>>     SomeEnum flags = SomeEnum (a | b | c);
>>
>> Why do i have to be repetitive? the goal is to not be 
>> repetitive and be cleaner
>>
>>     SomeEnum flags = .a | .b | .c;
>>
>> The brain no longer have to read 2x the same stuff, it goes 
>> straight to the point, it is explicit and typechecked
>
> and if you later see a line like
> ```
> auto flags = .a | .b | .c;
> ```
> imho it's just much harder to figure out whats going on.
> i agree that a short syntax would be good. i'd prefer _with()_ 
> because it makes it easier to understand later.

I already explained in earlier replies

If you use auto, how can the compiler expect you to use an enum 
called MyEnum? it doesn't make sense, for that case, it falls 
back to the current behavior, it searches for the parent scope

If no variable found, then it is compile error, undefined symbols 
a, b, c


More information about the Digitalmars-d mailing list