Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implementing Parent Enum Inference in the language (.MyValue instead of MyEnum.MyValue) #88

Open
ryuukk opened this issue Jun 29, 2022 · 6 comments

Comments

@ryuukk
Copy link

ryuukk commented Jun 29, 2022

Description

How many times have you been tired of repeating yourself when using enums?

set_my_flag( MySuperLongName.MyFlagA |  MySuperLongName.MyFlagB | MySuperLongName.MyFlagC | MySuperLongName.MyFlagD | MySuperLongName.MyFlagE | MySuperLongName.MyFlagF );

What if instead the compiler could be smarter and just accept this:

set_my_flag( .MyFlagA |  .MyFlagB | .MyFlagC | .MyFlagD | .MyFlagE | .MyFlagF );

The result already speaks for itself, no?

There is the with() we can use, but unfortunately, it doesn't really help with the repetition, and you can't use it everywhere, plus it leaks the the entire scope

Many other new languages went with that: (Swift, Zig, Odin, Jail, Styx)

What are rough milestones of this project?

A PoC that could help kickstart a proper DIP

How does this project help the D community?

It helps when using enums a lot and prevents us from choosing shorter names only because they are too long to use

Also it helps avoid repetition, wich doesn't help with visual clarity

Recommended skills

Basics of language/compiler development

Perfect for GSoC/SAoC

What can students expect to get out of doing this project?

They can learn about working and contributing to a big project (compiler)

And potentially adding a new feature to it!

Point of Contact

You can contact me if you have questions, leave a message here, or we can share emails if you prefer, just le me know!

References

https://forum.dlang.org/thread/[email protected]

How it was implemented in Styx, and how it could be done in DMD:

https://forum.dlang.org/post/[email protected]

@mdparker mdparker added the saoc label Jun 30, 2022
@mdparker
Copy link
Member

mdparker commented Jun 30, 2022

@ryuukk FYI, the "what can students expect to get..." isn't about money, but about the kind of practical experience they can expect to gain. E.g., in this case, learning about the compiler internals, how to contribute to the compiler, etc.

And the Point of Contact isn't about where to discuss this generally. It's who to contact for more information about the idea. This project is your idea, so in this case you're the obvious point of contact for anyone who has questions (and this is the obvious place to ask questions, so you don't need to list anything there at all). It's fine to list the forums rather than your email address, but please note anything they should add to the subject line of a forum post that would get your attention should they want to ask about it. This goes for your other project idea as well.

@ryuukk
Copy link
Author

ryuukk commented Jun 30, 2022

@ryuukk FYI, the "what can students expect to get..." isn't about money, but about the kind of practical experience they can expect to gain. E.g., in this case, learning about the compiler internals, how to contribute to the compiler, etc.

And the Point of Contact isn't about where to discuss this generally. It's who to contact for more information about the idea. This project is your idea, so in this case you're the obvious point of contact for anyone who has questions (and this is the obvious place to ask questions, so you don't need to list anything there at all). It's fine to list the forums rather than your email address, but please note anything they should add to the subject line of a forum post that would get your attention should they want to ask about it. This goes for your other project idea as well.

Thanks a lot for your reply, i applied your recommendations and edited the post, i will do that as well for the other one

@ichordev
Copy link

ichordev commented Aug 11, 2022

I've written a DIP for this since it's something I've wanted in the language for quite some time.
dlang/DIPs#230

@ryuukk
Copy link
Author

ryuukk commented Oct 20, 2022

@ichordev

Thanks a lot for the DIP!

I also wanted that feature for a very long time, hopefully we'll manage to make it happen!

@ichordev
Copy link

@ichordev

Thanks a lot for the DIP!

I also wanted that feature for a very long time, hopefully we'll manage to make it happen!

Not a problem! I’ve felt that it would be a really worthwhile shortcut ever since I started using lots of enums in some of my Dlang projects. :)

@ntrel
Copy link

ntrel commented Dec 24, 2022

Just to mention this feature is also useful with Walter's sum type proposal:

sumtype S { int val; string name; }
S s;
...
s = .val(5); // infer type

@RazvanN7 RazvanN7 removed the saoc label Jul 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants