Thread overview
How to avoid multiple spelling `import`
Jun 16, 2015
Dennis Ritchie
Jun 16, 2015
Idan Arye
Jun 16, 2015
Dennis Ritchie
Jun 16, 2015
Dennis Ritchie
Jun 16, 2015
Daniel Kozák
Jun 16, 2015
Dennis Ritchie
Jun 16, 2015
tired_eyes
Jun 17, 2015
flamencofantasy
Jun 17, 2015
tired_eyes
Jun 17, 2015
Joy-Killer
June 16, 2015
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;
}
June 16, 2015
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.
June 16, 2015
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"
)
June 16, 2015
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.
June 16, 2015
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));
}
June 16, 2015
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
June 16, 2015
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.
June 17, 2015
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
June 17, 2015
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"?
June 17, 2015
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.