Named multi-imports
jmh530 via Digitalmars-d
digitalmars-d at puremagic.com
Tue Aug 15 14:12:24 PDT 2017
On Tuesday, 15 August 2017 at 20:33:18 UTC, Johnson wrote:
>>
>> Or instead of a new language feature, the gtk-d guys could
>> have package files ;)
>
> But then that only helps with one specific instance. D is full
> of language features, I do not see why everyone is so against
> them. Without them, D would be empty, nothing, and no one would
> use it. Adding language features should be see as something
> good, cause without them, we wouldn't get anywhere.
In the past, I've thought it would be convenient to have
something like
import io = std.stdio : writeln, write;
and allow someone to write
io.write("foo");
io.writeln("bar");
though I don't know if that causes any kinds of problems to
implement.
That being said, the code you refer to above probably could be
simplified quite a bit with mixins. I just did a simple version,
but I imagine it could be extended. It also might be even easier
to accomplish when static foreach is in the language, that would
you can just loop through the LowLevels to accomplish it. Some
kind of hierarchy to the HighLevels/MidLevels/LowLevels would
also need to be established.
import std.meta : AliasSeq;
alias LowLevels = AliasSeq!("writeln", "write");
template GenImport(string TopLevel, string MidLevel, string
LowLevel)
{
const char[] GenImport = "import " ~ TopLevel ~ "." ~ MidLevel
~ " : " ~
LowLevel ~ ";";
}
mixin(GenImport!("std", "stdio", LowLevels[0]));
mixin(GenImport!("std", "stdio", LowLevels[1]));
void main()
{
write("foo");
writeln("bar");
}
More information about the Digitalmars-d
mailing list