> only: :macros give a good enough approximation If you're cozy with the current situation, I am too. I reached for this proposal when I typed it out, convinced it already existed—thought I'd give it the rounds and see if it resonated!
On Tue, Oct 31, 2023 at 11:33 AM José Valim <jose.va...@gmail.com> wrote: > Unfortunately we should not rely on the Docs chunk, because it is not > expected to be available. We could add infrastructure to this but I would > say only: :macros give a good enough approximation (and they'd cover > patterns and guards). > > On Sunday, October 22, 2023 at 7:31:27 AM UTC+2 christ...@gmail.com wrote: > >> Sent early, oops. >> >> I leave it for debate if a mixed atoms/keywords should be supported in *the >> additional proposal*: namely, how something like *import <module>, only: >> [:guards, sigil_URL: 2]* would behave, and warn on overlap, for example >> if *[:sigils, sigil_URL: 2]* was provided as a selector. >> >> On Sunday, October 22, 2023 at 12:27:21 AM UTC-5 Christopher Keele wrote: >> >>> Currently, *import <module>, only: <selector>* accepts as a selector >>> either: >>> >>> - a keyword list of functions/arities >>> - *:functions* to import only all functions >>> - *:macros* to import only all macros >>> >>> Additionally, the selector can be *:sigils*, which only imports a >>> specific subset macros: those known to be sigils (based on the naming >>> convention of *defmacro sigil_...*). >>> >>> *I propose* extending the selector to allow *:guards*, which would only >>> import macros from the *<module>* labelled as *@doc guard: true* >>> (including, automatically, macros defined via *defguard* >>> <https://github.com/elixir-lang/elixir/blob/927b10df80ee1c1c7396e68efe00d06bc3e80420/lib/elixir/lib/kernel.ex#L5684> >>> ). >>> >>> Similar to the *__using__* and *sigil__...* macros, guards are a >>> commonly-desirable-to-import subset of a module's macros. Additionally, >>> this would reduce the cognitive dissonance between the fact that a macro >>> defined as a *defguard* is not transparently a *defmacro* under the >>> covers. >>> >>> In programming, the hardest problems involve going from the 0 to 1 case, >>> and the 1 to 2 case, after which hopefully you've solved for N + 1 cases. >>> *As >>> an additional proposal*, I propose supporting atom lists as a selector >>> in *import <module>, only: <selector>*. This would elegantly allow for >>> the common case of only importing high-value unqualified macros; namely: >>> *import >>> <module>, only: [:sigils, :guards]* without conflicting with the >>> functions/arities keyword selector format. Mixing a *:macro* selector >>> with either *:sigils* or *:guards* in an atom selector list would issue >>> a compiler warning about the redundancy. >>> >>> As former proposal handles my use-case, and the latter is a natural but >>> not-required extension to the feature, I leave it for debate if a mixed >>> atoms/keywords should be supported in the additional proposal: namely, >>> something like *import <module>, only: [:guards, sigil_URL]* >>> >> -- > You received this message because you are subscribed to a topic in the > Google Groups "elixir-lang-core" group. > To unsubscribe from this topic, visit > https://groups.google.com/d/topic/elixir-lang-core/Q_HBkDFwdHw/unsubscribe > . > To unsubscribe from this group and all its topics, send an email to > elixir-lang-core+unsubscr...@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/elixir-lang-core/623c24aa-6201-4f86-b5f3-993fbe576fb7n%40googlegroups.com > <https://groups.google.com/d/msgid/elixir-lang-core/623c24aa-6201-4f86-b5f3-993fbe576fb7n%40googlegroups.com?utm_medium=email&utm_source=footer> > . > -- You received this message because you are subscribed to the Google Groups "elixir-lang-core" group. To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-core+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/CAD9kT2RtBeHniF6-dMSK7WxgzjOvedeqbApwS%3DhMmJ5xVQL_og%40mail.gmail.com.