Import proposals (Discuss)

Tyro Tyro_member at pathlink.com
Tue Jul 11 16:10:38 PDT 2006


In article <optcjo9wna23k2f5 at nrage>, Regan Heath says...
>
>On Tue, 11 Jul 2006 23:46:03 +0300, Jari-Matti MäkelE 
><jmjmak at utu.fi.invalid> wrote:
>> Regan Heath wrote:
>>> On Mon, 10 Jul 2006 05:37:41 +0000 (UTC), Tyro  
>>> <Tyro_member at pathlink.com> wrote:
>>>> In article <optcgh6iaa23k2f5 at nrage>, Regan Heath says...
>>>>>
>>>>> --[a.d]--
>>>>> import std.stdio;
>>>>> template foo { writefln("Hello World"); }
>>>>>
>>>>> --[b.d]--
>>>>> import std.stdio as bar;
>>>>> import a;
>>>>>
>>>>> void main() {
>>>>>   mixin foo;
>>>>> }
>>>>>
>>>>> I accidently called the template and import named scope the same  
>>>>> thing.
>>>>>
>>>>> Regan
>>>>
>>>> In this case I assume that you are concerned with conflicts that may be
>>>> generated between both imports of std.stdio in [a.d] and [b.d].
>>>
>>> Nope. In a.d you can call "writefln" but in b.d you must call
>>> "bar.writefln", plain old writefln will fail, right?
>>> So, what does this mean for mixins?
>>
>> Are you referring to the existing functionality (sans implementation
>> bugs) or some specific proposal here.
>
>The proposal to import a module into a namespace. In this case "std.stdio"  
>into "bar", meaning "writefln" does not exist but "bar.writefln" does.
>
>> IMO Tyro is right and plain old
>> writefln definitely shouldn't fail here. It should only fail when
>> std.stdio has been imported privately in file a.d. But if import were
>> private by default, then the compiler would say 'b.d(5): undefined
>> identifier writefln'.
>
>All I was really asking was...
>
>If module a.d imports "std.stdio" into the current namespace, then calls  
>"writefln" in a template which is then mixed into another source file b.d,  
>which imports "std.stdio" into a named namespace "bar", can that template  
>call "writefln"?
>
>I suspect the answer would have to be "no". After all the mixin is mixed  
>into the scope of b.d, it doesn't exist in the scope of a.d where  
>"writefln" is valid.
>
>All I was really trying to do was raise this as an issue which would occur  
>(and need a solution) if we had import into namespace 'x'.
>
>Regan
>

As I understand it, anything imported into the global scope (public import) of
[a.d] will be available in any other module that imports it. Unless of course,
Walter has finally decided to do the right thing and make imports private by
default! In the event he has, then the correct and desired result (for me
anyway) would be to get an error message stating: "writefln, mixed in on ln#, is
undefine".

Just in case that doesn't make any sense, let me try it a another way: By
importing [a.d] into [b.d] and by virtue of std.stdio being publicly imported
into [a.d], you have also imported std.stdio into [b.d]. If imports are made
private by default or if explicitly imported privately, then an error message
similar to the one suggested earlier is expected.

I hope that makes sense!

Andrew C. Edwards





More information about the Digitalmars-d mailing list