Import proposals (Discuss)

Tyro Tyro_member at pathlink.com
Sun Jul 9 22:37:41 PDT 2006


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]. I don't see much
of a problem with this either.

Since [a.b] imports std.stdio publicly and into a global scope (or is that file
level scope?) anything that imports [a.b] will be able to access std.stdio
methods directly.

[b.d] however, imports std.stdio into a named scope. Thus all access to methods
identified in that particular scope should be prefexed accordinly. There should
be no conflicts.

:--[b.d]--
:import std.stdio as bar;
:import a;
:
:void main() {
:   mixin foo;
:   writefln("something"); // Accesses method imported in [a.d]
:   bar.writefln("somethingElse"); // Accesses method imported in [b.d]
:}

Unless of course I have completely missed the intent of importing into named
scopes.

Andrew





More information about the Digitalmars-d mailing list