No way to selectively expose imported symbols using 163

Bruno Medeiros brunodomedeirosATgmail at SPAM.com
Sun Jul 30 11:58:44 PDT 2006


Sean Kelly wrote:
> Consider this code:
[...]
> 
> The simplest solution would be to change selective import to not bind 
> the symbols into the current namespace, thus keeping the symbols as 
> "second class citizens."  This would have the following effect:
> 
>     import std.stdio : writef;
> 
> Import one symbol, writef, as a second-class citizen for the current 
> module.
> 
[...]
> 
>     import std.stdio : writef = writef;
> 
> Import only writef from std.stdio and bind it into the current scope. 
> This would be equivalent to the current behavior of the non-renaming 
> selective import.  Thus, currently, these two lines are identical:
> 
>     static import std.stdio : writef;
>     import std.stdio : writef;
> 
> But under the new method, these two lines would be identical:
> 
>     static import std.stdio : writef = writef;
>     import std.stdio : writef = writef;
> 
> This should be obvious, as the "= writef" suggests binding the symbol 
> into the current scope using the name "writef".  Please note that:
> 
>     import std.stdio : writef = writef;
> 
> Should not create a "second class" lookup table for the symbol, 
> "writef", as the "= writef" is present.  If both the binding and 
> second-class lookup is desired, a two-line approach may be used:
> 
>     import std.stdio : writef;
>     alias std.stdio.writef writef;
> 
> I don't foresee anyone actually wanting to do this, but I thought it was 
> worth mentioning anyway.
> 
> Comments?
> 
> 
> Sean
> 
> 

Yes, I agree that selective import should import the names as "second 
class citizens" (or "to the secondary namespace" as Walter calls it (or 
even "background namespace")) :

   import std.stdio : writef;

A selective import with renaming, conversely, should then create a 
"first class citizen" (aka "primary namespace"?, "foreground namespace"):

   import std.stdio : writef = writef;

You initial code example shows quite well why this is important.

---

What I don't agree is about that static+selective import stuff:
   static import std.stdio : writef;

That is, the idea that static(FQN) and selective import should work 
together. I'm not fond the idea that std.stdio, a module, is "available" 
but is not complete. What is the use and sense of that? Why could it not 
be a regular(non-selective) FQN import?

That being, if a static(FQN) import is to not work together with a 
selective import, then such syntax should be a compiler error, instead 
of just working like a normal import:
   static import foo.bar : bar; // Error
Static(FQN) with renaming import should be an error too:
   static import foo.bar = baz; // Error

-- 
Bruno Medeiros - MSc in CS/E student
http://www.prowiki.org/wiki4d/wiki.cgi?BrunoMedeiros#D



More information about the Digitalmars-d mailing list