www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Re-named & Selective Imports

reply jmh530 <john.michael.hall gmail.com> writes:
I combined a re-named import with a selective import and was 
surprised to find that it didn't do what I would have expected. 
In the code below, I would have expected only the "test2" line to 
have compiled, but it turned out that all three of these do. I'm 
guessing the logic is that it imports all of std.stdio, re-names 
it as io, then puts just std.stdio.writeln in the namespace.

import io = std.stdio : writeln;

void main()
	io.write("test3", '\n');

It seems like it might be a bit more intuitive if they had 
disabled selective imports with re-named imports (like with 
static imports). Then you could do a separate selective import. 
This would probably be more clear.

As far as I can tell, if you do selective imports of a function 
with the same name from two different modules, then you have to 
give one a unique name without any module prefix. For instance, I 
tried to import with
import std.stdio : writeln, io.writeln = writeln;, but that 
doesn't work, but something like io_writeln would.
Sep 15 2015
parent Kagamin <spam here.lot> writes:
Well, arguably disjunctive combination doesn't make much sense 
here, because renamed import disambiguates it all enough, but 
makes it impossible to merge arbitrary namespaces ad hoc, a 
feature I missed several times.
Sep 16 2015