Proposal: Package aliases

Steven Schveighoffer schveiguy at yahoo.com
Thu May 15 07:55:34 PDT 2008


"Ary Borenszweig" wrote
> I also find useless and confusing to alias imported symbols like "import 
> foo : bar = baz"... who actually uses that? What for?

The main reason is if you have two different modules that contain the same 
symbol names.

The main place I use it is for tango.text.convert.*  the Integer and Float 
modules both have toString functions defined.  If you import both, you need 
to fully qualify the name, however, if you do:

import Int = tango.text.convert.Integer;
import Float = tango.text.convert.Float;

Then you can easily specify which module's function you wanted:

Int.toString(5);
Float.toString(5);

I imagine you could do it similarly with the syntax you identified:

import tango.text.convert.Integer : toString = intToString;
import tango.text.convert.Float : toString = floatToString;

But that is only if you need the toString.  If you wanted to use other 
functions in those modules, then you would use the other method (scoping the 
entire import).

I admit, after writing all this, it does seem unlikely that you would ever 
need to use the import foo : bar = baz.

But I think it would be very useful to import multiple modules from the same 
package.

-Steve 





More information about the Digitalmars-d mailing list