Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
A Way to Export Only Specific Symbols At Compile Time #5304
Currently, there seems to be no easy way to import only specific symbols from a module *at compile time*.
For example, if I want to use a module that exports a whole ton of functions but I only one just one, I have to write something complicated like this:
This difficulty will result in many programmers trashing their namespaces out of convenience, resulting in hard-to-find bugs, especially when newer version of `use`d module introduces new subs.
I propose we create another reserved import tag :SYM that will take a list of SYMbols we want to import, eg:
use Test :SYM<&is &ok>;
Although I'm ignorant of the implementation of the :ALL tag, I'd think implementing :SYM would be similar (you'd just grep for wanted symbols).
Relevant IRC conversation: http://irclog.perlgeek.de/perl6/2016-05-07#i_12446098
pmichaud pointed out on IRC that S11 already defines a way to export symbols: https://rt-archive.perl.org/perl6//Public/Bug/Display.html?id=128090
However, that doesn't seem to work unless the module *author* defines extra EXPORT sub, which puts the feature out of the module user's control:
<ZoffixWin> m: use Test <&is>; say is 2, 2
So now, I don't know if a proposed :SYM is needed or something needs to be improved with the `is export` trait.
Something like this has also passed through my head.
What about use Test :ALL<&is &ok> or use Test :SOME-TAG<&foo &bar>.
so you can filter out what you want with arguments to the tag. This seems
Zoffix++ for bringing this up.
also, I think that require could be adapted to work like this. Right now
require Test <&is &ok>, :SOME-TAG<&foo &bar>;
I think it's a good feature and importing would be much more consistent.
On Sat, May 7, 2016 at 11:12 AM Zoffix Znet <email@example.com>
There was a comment on IRC from someone who doesn't have an account (http://irclog.perlgeek.de/perl6/2016-06-30#i_12762654 ):
use Module :ONLY<foo bar baz>;
I do like :ONLY more than my original :SYM
On Thu, 30 Jun 2016 05:12:09 -0700, firstname.lastname@example.org wrote:
Just got bitten by this in real-life code: zostay/raku-DOM-Tiny#5
A module was overly lavish with its exports, exporting symbol `Text` (something I've no use for), which conflicted with `Text` namespace from another module I was trying to load.
Not having a way to prevent those exports, I had to wrap the module into another module of my own making.