Thoughts about modules

Bruno Medeiros brunodomedeirosATgmail at SPAM.com
Tue Jun 27 10:28:19 PDT 2006


Derek Parnell wrote:
> On Wed, 28 Jun 2006 01:18:31 +1000, Andrei Khropov 
> <andkhropov at nospam_mtu-net.ru> wrote:
> 
>>
>> Hi all,
>>
>> I just want to share some thoughts about modules and their import.
>>
>> When we want to import a module we should decide on 2 things:
>>
>> 1) do we want to import names from the module to the local namespace?
>>
>> 2) do we want this import to be propagated to the files that include 
>> the module
>> we import in?
>>
>> In D the second question can be answered "no" by adding "private" 
>> modifier to
>> the import statement, but the first question is always answered "Yes".
> 
> 
> I'm trying to make sure that I understand your terminology here.
> 
> By the phrase "import names from the module to the local namespace", I 
> read that as saying that if names from an imported module come into the 
> importing module's namespace, it would mean that the importing module 
> cannot declare a name that is contained in the imported module - because 
> that would be a duplicated name in the same namespace.
> 
> But that's not what happens with D so therefore I'm not sure what you 
> mean by "import names from the module to the local namespace".
> 
> To access a name from an imported module that has the same name as a 
> member in the importing module, you must qualify the imported name with 
> the module name.
> 
> -----------EXAMPLE ---------
> module mod1;
> public int AA = 2;
> ----------------------------
> module sample;
> import std.stdio;
> import mod1;
> public real AA = 3.21;
> void main()
> {
>     writefln("%s %s", AA, mod1.AA);
> }
> -----------------
> 
> 
> Am I misunderstanding you?
> 
> --Derek Parnell
> Melbourne, Australia

I'm betting he means being able to import a module in a way that it's 
names (entities) are available only as fully-qualified names, and so the 
base names are not "imported" to the importing module namespace/scope. 
It's the FQN import.

Andrei, (and others) if you want to check out some previous discussion 
on this matter:
http://www.digitalmars.com/d/archives/digitalmars/D/28423.html

-- 
Bruno Medeiros - CS/E student
http://www.prowiki.org/wiki4d/wiki.cgi?BrunoMedeiros#D



More information about the Digitalmars-d mailing list