Import proposals (Discuss)

Regan Heath regan at netwin.co.nz
Mon Jul 10 15:28:08 PDT 2006


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...
>>
>> On Mon, 10 Jul 2006 03:43:07 +0000 (UTC), Tyro  
>> <Tyro_member at pathlink.com>
>> wrote:
>>> In article <optcgd2ruo23k2f5 at nrage>, Regan Heath says...
>>>>
>>>> More random musings.. if we have a syntax that reads:
>>>>
>>>> import std.stdio as foo;
>>>>
>>>> which imports the symbols in std.stdio into a namespace called 'foo',
>>>> preventing access as just "writefln" requiring "foo.writefln" then  
>>>> what
>>>> happens in a case like this:
>>>>
>>>> --[a.d]--
>>>> import std.stdio;
>>>> template foo { writefln("Hello World"); }
>>>>
>>>> --[b.d]--
>>>> import std.stdio as foo;
>>>>
>>>> void main() {
>>>>   mixin foo;
>>>> }
>>>>
>>>> ?
>>>>
>>>> Regan
>>>
>>>
>>> Well, as far as I can see you should get an error telling you that foo
>>> is not a
>>> template. Now if you meant for the first line in [b.d] to read:
>>>
>>> import a as foo;
>>>
>>> Then I think we have a different issue. But since the programmer when
>>> through
>>> the trouble of importing into a named scope, this should be a no  
>>> braner.
>>> In
>>> order to access the foo template , he needs to code explicitly.
>>>
>>> :--[b.d]--
>>> :import a as foo;
>>> :
>>> :void main() {
>>> :   mixin foo;     // Error, foo is not a template
>>> :   mixin foo.foo; // Ok
>>> :}
>>
>> Ooops, my bad example, what I meant was:
>>
>> --[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?

Regan



More information about the Digitalmars-d mailing list