Grouped named import

Quirin Schroll qs.il.paperinik at gmail.com
Mon Jul 29 14:51:53 UTC 2024


On Sunday, 28 July 2024 at 18:01:43 UTC, Walter Bright wrote:
> D already has namespaces:
>
> https://dlang.org/spec/attribute.html#namespace
>
> A struct can also be used as a namespace:
>
> ```d
> struct c
> {
>     import sqlite3, miniz;
> }
> ```
>
> I've been using field-less structs this way myself.

Yeah, nice.

For run.dlang.io, command-line args: `-i -run main.d`:

```d
--- x.d

import std.stdio;
void f() { writeln("x.f()"); }


--- y.d

import std.stdio;
void f() { writeln("y.f()"); }


--- main.d

extern(C++, c)
{
     import x, y;
}

void main()
{
     c.x.f();
     c.y.f();
}
```

For that reason, I think, `import Identifer { Imports... }` 
wouldn’t even need a DIP, it would just be an enhancement that 
lowers to `extern(C++, Identifier) { import Imports...; }`. Using 
`extern(C++, Identifier)` is kind of a hack.


More information about the dip.ideas mailing list