-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Add module sigil #9640
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
Add module sigil #9640
Conversation
|
||
expand({'module_sigil', Meta, [Module, String, Modifiers]}, E) -> | ||
Alias = {'__aliases__', [{alias, false}], [Module]}, | ||
RE = E#{requires := ordsets:add_element(Module, ?key(E, requires))}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the consequence of this is:
iex(1)> __ENV__.requires
[Application, IEx.Helpers, Kernel, Kernel.Typespec]
iex(2)> ~URI[https://elixir-lang.org]
iex(3)> __ENV__.requires
[Application, IEx.Helpers, Kernel, Kernel.Typespec, URI]
which might be surprising, e.g. we now don't need to explicitly require the module to use it's macros, we just need to use the sigil. At the same time, without automatically requiring the module, the feature feels much less ergonomic to use. (But fwiw it would match the behaviour of "regular" sigils, if it's a macro that module needs to be required.)
expand({'<<>>', Meta, Args}, E) -> | ||
elixir_bitstring:expand(Meta, Args, E, false); | ||
|
||
expand({'module_sigil', Meta, [Module, String, Modifiers]}, E) -> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should call the special form __sigil__
and it would have to be documented as such.
check_module_availability(Line, File, Module) -> | ||
Reserved = ['Elixir.Any', 'Elixir.BitString', 'Elixir.PID', | ||
Reserved = ['Elixir.Any', 'Elixir.BitString', | ||
'Elixir.Reference', 'Elixir.Elixir', 'Elixir'], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We would have to implement it for refs too.
Thank you @wojtekmach for the proof of concept. Unfortunately, we are not fully convinced on the usefulness of the feature. It has the following limitations:
So given the pitfalls and the fact it does not address all cases, I am not convinced we should move forward. Although it is indeed the best proposal we have received so far and the implementation looks quite solid so far! |
Currently
I think that is actually a feature, that is regular sigils and module sigils always accept a binary and a modifier charlist, so they have the same features and limitations (not actual values, no interpolation). My only concern would be that if today we allow to do All that being said, I think the criticism is fair and if you'd ever want to move forward with this or something similar, let me know. Thanks for looking into it! |
This is a proof-of-concept for adding module-based sigils to Elixir. Before improving implementation and writing docs and tests I'd like to see if this could be added to Elixir. Hope the PR is helpful to test different possible implementations of this idea.
This topic was mentioned a few times over the years, most recently on: https://groups.google.com/forum/#!topic/elixir-lang-core/C7-QgKKu1Mw. In that topic I mentioned a few possible use cases for the sigil that are perhaps worth repeating:
Looking forward to feedback about proposal as well as the implementation.