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

A Way to Export Only Specific Symbols At Compile Time #5304

Open
p6rt opened this issue May 7, 2016 · 6 comments
Open

A Way to Export Only Specific Symbols At Compile Time #5304

p6rt opened this issue May 7, 2016 · 6 comments
Labels
RFC

Comments

@p6rt
Copy link

@p6rt p6rt commented May 7, 2016

Migrated from rt.perl.org#128090 (status was 'open')

Searchable as RT128090$

@p6rt

This comment has been minimized.

Copy link
Author

@p6rt p6rt commented May 7, 2016

From @zoffixznet

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​:

need Test;
my &is := &Test​::EXPORT​::DEFAULT​::is;

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

@p6rt

This comment has been minimized.

Copy link
Author

@p6rt p6rt commented May 7, 2016

From @zoffixznet

To add​:

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
<camelia> rakudo-moar ac36d2​: OUTPUT«===SORRY!=== Error while compiling /tmp/zm89zGOGgu␤Error while importing from 'Test'​:␤no EXPORT sub, but you provided positional argument in the 'use' statement␤at /tmp/zm89zGOGgu​:1␤------> 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.

@p6rt

This comment has been minimized.

Copy link
Author

@p6rt p6rt commented May 8, 2016

From @LLFourn

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
to be better and more backwards-compy because with current rakudo use Test
:ALL<&is &ok> will still work (it will just do a normal :ALL import).

Zoffix++ for bringing this up.

also, I think that require could be adapted to work like this. Right now
require can only import from DEFAULT which seems like a needless
restriction (the design docs seem a little confused on this point).

require Test <&is &ok>, :SOME-TAG<&foo &bar>;

I think it's a good feature and importing would be much more consistent.

LL

On Sat, May 7, 2016 at 11​:12 AM Zoffix Znet <perl6-bugs-followup@​perl.org>
wrote​:

# New Ticket Created by Zoffix Znet
# Please include the string​: [perl #​128090]
# in the subject line of all future correspondence about this issue.
# <URL​: https://rt-archive.perl.org/perl6/Ticket/Display.html?id=128090 >

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​:

need Test;
my &is := &Test​::EXPORT​::DEFAULT​::is;

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

@p6rt

This comment has been minimized.

Copy link
Author

@p6rt p6rt commented May 8, 2016

The RT System itself - Status changed from 'new' to 'open'

@p6rt

This comment has been minimized.

Copy link
Author

@p6rt p6rt commented Jun 30, 2016

From @zoffixznet

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

@p6rt

This comment has been minimized.

Copy link
Author

@p6rt p6rt commented Nov 27, 2017

From @zoffixznet

On Thu, 30 Jun 2016 05​:12​:09 -0700, cpan@​zoffix.com wrote​:

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

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.

@p6rt p6rt added the RFC label Jan 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
1 participant
You can’t perform that action at this time.