Nested public imports - bug or feature?

Timon Gehr via Digitalmars-d digitalmars-d at puremagic.com
Thu Aug 13 14:14:58 PDT 2015


On 08/13/2015 06:36 PM, Dicebot wrote:
> On Thursday, 13 August 2015 at 16:24:56 UTC, Timon Gehr wrote:
>>>> static import greetings=phrases.english.greetings;
>>>>
>>>> ?
>>>
>>> http://forum.dlang.org/post/szaaakmavraxatkrfpnx@forum.dlang.org
>>>
>>
>> How is this relevant? Does Rust support it?
>
> Relevant as explanation why I don't consider aliased imports a solution.
>
> Rust does exactly that and I feel that "bottom-qualification" is
> inferior approach to "top-qualification" in general for deeply nested
> package hierarchies. Of course, both are much more hygienic than
> semantics D uses by default

I am unable to understand your concerns precisely, because you are 
making up words without giving definitions or examples.

https://www.google.ch/search?q=module+system+bottom-qualification
https://www.google.ch/search?q=module+system+top-qualification
https://www.google.ch/search?q=define+hygienic+module+system

> - yet if I am forced to resort to idioms, I want to get most out of it :)

This was the example given in that post:

> import mypkg = mypkg.mysubpkg.mod1;
> import mypkg = mypkg.mysubpkg.mod2; // error, can't redefine aliased import!
>
> struct mypkg
> {
>     import mypkg.mysubpkg.mod1;
>     import mypkg.mysubpkg.mod2; // fine
> }

FWIW:

---
use mypkg::mysubpkg::mod1 as myuse;
use mypkg::mysubpkg::mod2 as myuse;
---

error: a module named `myuse` has already been imported in this module 
[E0252]
use mypkg::mysubpkg::mod2 as myuse;
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

You have to resort to the following idiom:

mod myuse{
     pub use mypkg::mysubpkg::mod1::*;
     pub use mypkg::mysubpkg::mod2::*;
}

Now, note: if there is any identifier `foo' which is exported by both 
`mod1' and `mod2', then the Rust compiler will error out eagerly here, 
even if `myuse::foo' never occurs in the code.

How is this superior?

AFAICS, the only other major semantic difference which would make Rust's 
system vastly superior is given by the situation that DMD comically 
thinks private symbols have a reason to cause conflicts in other 
modules. Was this your "hygiene" point?


More information about the Digitalmars-d mailing list