Thoughts about modules
Derek Parnell
derek at psych.ward
Tue Jun 27 09:22:24 PDT 2006
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
More information about the Digitalmars-d
mailing list