www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - How to avoid multiple spelling `import`

reply "Dennis Ritchie" <dennis.ritchie mail.ru> writes:
Hi,

I can write this:

import std.range : chain, split;

But I can not write this:

import std.range : chain, split, std.algorithm : map, each;

We have several times to write the word `import`:

import std.range : chain, split;
import std.algorithm : map, each;

Does D something to solve this problem? Maybe there is something 
like:

import std.range{chain, split}, std.algorithm{map, each};

import std.range(chain, split), std.algorithm(map, each);

import {
     std.range : chain, split;
     std.algorithm : map, each;
}
Jun 16 2015
parent reply "Idan Arye" <GenericNPC gmail.com> writes:
On Tuesday, 16 June 2015 at 09:33:22 UTC, Dennis Ritchie wrote:
 Hi,

 I can write this:

 import std.range : chain, split;

 But I can not write this:

 import std.range : chain, split, std.algorithm : map, each;

 We have several times to write the word `import`:

 import std.range : chain, split;
 import std.algorithm : map, each;

 Does D something to solve this problem? Maybe there is 
 something like:

 import std.range{chain, split}, std.algorithm{map, each};

 import std.range(chain, split), std.algorithm(map, each);

 import {
     std.range : chain, split;
     std.algorithm : map, each;
 }
There is no problem to be solved here. Having to type `import` for each imported module is not big enough a burden to justify this additional syntax.
Jun 16 2015
parent reply "Dennis Ritchie" <dennis.ritchie mail.ru> writes:
On Tuesday, 16 June 2015 at 11:16:32 UTC, Idan Arye wrote:
 There is no problem to be solved here. Having to type `import` 
 for each imported module is not big enough a burden to justify 
 this additional syntax.
No, I think it is a holdover from C++-times — to write `import` for each new header file. For example, this feature is implemented Go: import ( "os" "bufio" "strings" "fmt" )
Jun 16 2015
parent reply "Dennis Ritchie" <dennis.ritchie mail.ru> writes:
Maybe not everyone needs these features. But, unfortunately, I 
often use a lot of imported modules. And use every time the word 
`import` very bad.

version (none) {
import std.math,
        std.conv,
        std.stdio,
        std.ascii,
        std.range,
        std.array,
        std.regex,
        std.format,
        std.bigint,
        std.traits,
        std.random,
        std.string,
        std.numeric,
        std.variant,
        std.typecons,
        std.container,
        std.algorithm,
        std.typetuple,
        std.exception,
        core.checkedint;
}

I just want to import individual features of these modules.
Jun 16 2015
parent reply Daniel =?UTF-8?B?S296w6Fr?= via Digitalmars-d-learn writes:
On Tue, 16 Jun 2015 11:45:22 +0000
Dennis Ritchie via Digitalmars-d-learn
<digitalmars-d-learn puremagic.com> wrote:

 Maybe not everyone needs these features. But, unfortunately, I 
 often use a lot of imported modules. And use every time the word 
 `import` very bad.
 
 version (none) {
 import std.math,
         std.conv,
         std.stdio,
         std.ascii,
         std.range,
         std.array,
         std.regex,
         std.format,
         std.bigint,
         std.traits,
         std.random,
         std.string,
         std.numeric,
         std.variant,
         std.typecons,
         std.container,
         std.algorithm,
         std.typetuple,
         std.exception,
         core.checkedint;
 }
 
 I just want to import individual features of these modules.
mixin template include(w...) { mixin _include!(w.length - 1, w); } mixin template _include(long N, i...) { mixin("import " ~ i[N] ~ ";"); mixin _include!(N - 1, i); } mixin template _include(long N : 0, i...) { mixin("import " ~ i[N] ~ ";"); } mixin include!( "std.stdio : writeln, write", "std.conv : to" ); void main() { writeln(to!string(7)); }
Jun 16 2015
next sibling parent reply "Dennis Ritchie" <dennis.ritchie mail.ru> writes:
On Tuesday, 16 June 2015 at 12:41:14 UTC, Daniel Kozák wrote:
 On Tue, 16 Jun 2015 11:45:22 +0000
 Dennis Ritchie via Digitalmars-d-learn
 <digitalmars-d-learn puremagic.com> wrote:
 I just want to import individual features of these modules.
mixin template include(w...) { mixin _include!(w.length - 1, w); } mixin template _include(long N, i...) { mixin("import " ~ i[N] ~ ";"); mixin _include!(N - 1, i); } mixin template _include(long N : 0, i...) { mixin("import " ~ i[N] ~ ";"); } mixin include!( "std.stdio : writeln, write", "std.conv : to" ); void main() { writeln(to!string(7)); }
Thanks. Maybe I'll use this code in your own programs. I still believe that this design deserves existence in D: https://issues.dlang.org/show_bug.cgi?id=14704
Jun 16 2015
parent reply "tired_eyes" <pastuhov85 gmail.com> writes:
On Tuesday, 16 June 2015 at 15:42:02 UTC, Dennis Ritchie wrote:
 On Tuesday, 16 June 2015 at 12:41:14 UTC, Daniel Kozák wrote:
 On Tue, 16 Jun 2015 11:45:22 +0000
 Dennis Ritchie via Digitalmars-d-learn
 <digitalmars-d-learn puremagic.com> wrote:
 I just want to import individual features of these modules.
mixin template include(w...) { mixin _include!(w.length - 1, w); } mixin template _include(long N, i...) { mixin("import " ~ i[N] ~ ";"); mixin _include!(N - 1, i); } mixin template _include(long N : 0, i...) { mixin("import " ~ i[N] ~ ";"); } mixin include!( "std.stdio : writeln, write", "std.conv : to" ); void main() { writeln(to!string(7)); }
Thanks. Maybe I'll use this code in your own programs. I still believe that this design deserves existence in D: https://issues.dlang.org/show_bug.cgi?id=14704
I also think this might be useful, and, more important, consistent. If we have shorthand syntax for full imports, why there is no option for shorthand partial imports? This is expected behavior.
Jun 16 2015
parent reply "flamencofantasy" <flamencofantasy gmail.com> writes:
On Tuesday, 16 June 2015 at 16:40:39 UTC, tired_eyes wrote:
 On Tuesday, 16 June 2015 at 15:42:02 UTC, Dennis Ritchie wrote:
 On Tuesday, 16 June 2015 at 12:41:14 UTC, Daniel Kozák wrote:
 [...]
Thanks. Maybe I'll use this code in your own programs. I still believe that this design deserves existence in D: https://issues.dlang.org/show_bug.cgi?id=14704
I also think this might be useful, and, more important, consistent. If we have shorthand syntax for full imports, why there is no option for shorthand partial imports? This is expected behavior.
No
Jun 16 2015
parent "tired_eyes" <pastuhov85 gmail.com> writes:
On Wednesday, 17 June 2015 at 01:56:45 UTC, flamencofantasy wrote:
 On Tuesday, 16 June 2015 at 16:40:39 UTC, tired_eyes wrote:
 On Tuesday, 16 June 2015 at 15:42:02 UTC, Dennis Ritchie wrote:
 On Tuesday, 16 June 2015 at 12:41:14 UTC, Daniel Kozák wrote:
 [...]
Thanks. Maybe I'll use this code in your own programs. I still believe that this design deserves existence in D: https://issues.dlang.org/show_bug.cgi?id=14704
I also think this might be useful, and, more important, consistent. If we have shorthand syntax for full imports, why there is no option for shorthand partial imports? This is expected behavior.
No
Can I have some more serious argumentation than just plain "no"?
Jun 16 2015
prev sibling parent "Joy-Killer" <jklp nowhere.fr> writes:
On Tuesday, 16 June 2015 at 12:41:14 UTC, Daniel Kozák wrote:
 mixin template include(w...)
 {
     mixin _include!(w.length - 1, w);
 }

 mixin template _include(long N, i...)
 {

     mixin("import " ~ i[N] ~ ";");
     mixin _include!(N - 1, i);
 }

 mixin template _include(long N : 0, i...)
 {

     mixin("import " ~ i[N] ~ ";");
 }

 mixin include!(
     "std.stdio : writeln, write",
     "std.conv : to"
 );

 void main() {
     writeln(to!string(7));
 }
just a word to say that while it's working, anyone who uses this shouldn't expect the tools, i particularly think to DCD, to work anymore with this. e.g jump to definition...show ddoc...completion won't work.
Jun 16 2015