Import proposals (Discuss)

Regan Heath regan at netwin.co.nz
Tue Jul 11 15:11:46 PDT 2006


On Tue, 11 Jul 2006 23:46:03 +0300, Jari-Matti Mäkelä  
<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




More information about the Digitalmars-d mailing list