Named multi-imports
jmh530 via Digitalmars-d
digitalmars-d at puremagic.com
Wed Aug 16 13:11:02 PDT 2017
On Wednesday, 16 August 2017 at 18:38:23 UTC, Johnson Jones wrote:
>
> Not really, I'm not doing selective imports.
> [snip]
I'll preface this by saying that I think Jesse Phillips' point is
a good one. The fact that you can already do it with the language
(as you note about having a separate file full of imports)
suggests that it doesn't have much chance of being part of the
language.
Moving on to your point about wildcards, isn't that what
package.d is for? I agree with the others that a lot of the pain
would be reduced gtkd had package.d files set up.
Nevertheless, you also seem to want to be able to import a
limited number of modules of a package and rename them one thing.
Here's an example that I think illustrates your point with phobos:
import foo = std.algorithm.searching, std.algorithm.comparison;
void main()
{
int[] a = [ 1, 2, 4, 3, 2, 5, 3, 2, 4 ];
auto val = foo.count(a, 2);
auto result = cmp("abc", "abc");
}
In this, you can have count named with foo, but you can't name
cmp with foo. Of course, this isn't a problem with selective
imports if there is a package.d file.
I found some interesting stuff on bugzilla related to this stuff
https://issues.dlang.org/show_bug.cgi?id=3603
https://issues.dlang.org/show_bug.cgi?id=12359
The first one has a recommendation to allow something like (and
actually the initial suggestion has a version quite similar to
yours):
import std.algorithm : searching, comparison;
which is currently not allowed, and would require some changes to
how imports work to get it included in the language. However, it
is very similar to what you are looking for (why I was so focused
on selective imports), except that it does not have renaming, so
you'd prefer something like
import foo = std.algorithm : searching, comparison;
The most significant difference between this and what you are
suggesting is that your approach is probably more general. You
could put anything between the { }, whereas this approach is a
bit more limited.
It might the things a little easier to distinguish between a
module import and a symbol import (like import std.algorithm ::
searching, comparison : count, cmp; instead).
More information about the Digitalmars-d
mailing list