www.digitalmars.com         C & C++   DMDScript  

digitalmars.dip.ideas - Grouped named import

reply ryuukk_ <ryuukk.dev gmail.com> writes:
Saw this somewhere, and to be honest, that's something i always 
wanted to be able to do

That may be something i could try to implement, sounds relatively 
easy

```D
import c = sqlite3, miniz;
```

It means, symbols from sqlite3 and miniz are isolated into the c 
name

Example:

```D
c.sqlite3_init();
c.miniz_init();
```

This is useful for ImportC, in case of symbol clashes with libc 
symbols from druntime for example

https://dlang.org/spec/module.html#renamed_imports
Jul 22
parent reply Walter Bright <newshound2 digitalmars.com> writes:
D already has namespaces:

https://dlang.org/spec/attribute.html#namespace

A struct can also be used as a namespace:

```
struct c
{
     import sqlite3, miniz;
}
```

I've been using field-less structs this way myself.
Jul 28
next sibling parent Quirin Schroll <qs.il.paperinik gmail.com> writes:
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.
Jul 29
prev sibling parent ryuukk_ <ryuukk.dev gmail.com> writes:
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:

 ```
 struct c
 {
     import sqlite3, miniz;
 }
 ```

 I've been using field-less structs this way myself.
Your example didn't work, i needed: ```D struct c { public import sqlite3, miniz; } ``` I never thought it would work, thanks for sharing
Aug 03