[phobos] phobos commit, revision 1837

Don Clugston dclugston at googlemail.com
Thu Aug 12 05:55:50 PDT 2010


On 12 August 2010 13:04, Michel Fortin <michel.fortin at michelf.com> wrote:
> Is it reasonable to have to import publicly everything you need for every mixin in every module? Won't this pollute the global namespace? And won't this break a selective import like this one?
>
> ---
> import std.signal : Signal;
> ---

Yes.

> Perhaps import could be added directly in the template instead:
> ---
> template Signal(T1...)
> {
>        import std.c.stdlib : calloc, realloc, free;
>        import core.exception : onOutOfMemoryError;
>        ...
> }
> ---
>
> This is a working but undocumented feature (perhaps it's an accident that it works), see:
> <http://d.puremagic.com/issues/show_bug.cgi?id=2179>

That's a great idea! I forgot about that.

>
> From my limited testing however, it seems that this import always import the symbols publicly. :-(

Not exactly. It only imports it into the scope where the mixin is.
It's exactly as if you'd aliased the symbol
(alias std.c.stdlib.calloc calloc;) as a member of that scope.

class Input
{
    mixin Signal!(int, int) click;
    mixin Signal!(char) keyDown;
    void buzz() {
         auto zzz = calloc(int.sizeof, 6); // This is OK
    }
}

void fuzz()
{
         auto zzz = calloc(int.sizeof, 6); // Fails: calloc was not
imported into this scope.
}

But I think that's still too much namespace pollution. A static import
is much cleaner, though unfortunately it imports into the whole
module, not just the local scope. I'll check in a fix.


More information about the phobos mailing list