www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - private alias for module

reply Myron Alexander <someone somewhere.com> writes:
Hello.

I would like to declare an alias private to the module. As of D1.020, 
this is not the case and the specification seems to agree with the 
implementation.

By private alias, I mean (eg):

 ----- somemodule ----
 module somemodule;
 import std.string.toString;
 private alias std.string.toString str;
 ... code that uses str ...
 
 --- main ----
 import somemodule;
 void main () {
    str (50); // should fail
 }
Is there a way to do this? At the moment, I understand my only options as: 1. Selective import with function rename 2. Create another module for the alias and import into "somemodule" Problem with option 1 is that I then have to declare each function I use. Problem with option 2 is that I have an additional file. If this is by design, then what is the reasoning behind forbidding private aliases? Thanks ahead, Myron Alexander.
Aug 13 2007
parent reply Chris Nicholson-Sauls <ibisbasenji gmail.com> writes:
Myron Alexander wrote:
 Hello.
 
 I would like to declare an alias private to the module. As of D1.020, 
 this is not the case and the specification seems to agree with the 
 implementation.
 
 By private alias, I mean (eg):
 
 ----- somemodule ----
 module somemodule;
 import std.string.toString;
 private alias std.string.toString str;
 ... code that uses str ...

 --- main ----
 import somemodule;
 void main () {
    str (50); // should fail
 }
Is there a way to do this? At the moment, I understand my only options as: 1. Selective import with function rename 2. Create another module for the alias and import into "somemodule" Problem with option 1 is that I then have to declare each function I use. Problem with option 2 is that I have an additional file. If this is by design, then what is the reasoning behind forbidding private aliases? Thanks ahead, Myron Alexander.
I'm not sure what the reasoning is, and would just assume have private aliases as well. But I can add another option. Assuming you just want std.string.* to have a shorter name, you could try a static+renaming import. static import str = std.string; // ... str.toString(50); If its something else you're after... then I don't know. -- Chris Nicholson-Sauls
Aug 14 2007
parent reply Myron Alexander <someone somewhere.com> writes:
Chris Nicholson-Sauls wrote:
 I'm not sure what the reasoning is, and would just assume have private 
 aliases as well. But I can add another option.  Assuming you just want 
 std.string.* to have a shorter name, you could try a static+renaming 
 import.
 
 static import str = std.string;
 // ...
 str.toString(50);
 
 If its something else you're after... then I don't know.
 
 -- Chris Nicholson-Sauls
Chris, I do not want to rename the module, I want to use "str" instead of "toString". The alias is a natural solution but I do not want it imported into the caller name space. Regards, Myron.
Aug 14 2007
parent Extrawurst <spam extrawurst.org> writes:
what abot that ?

import std.string:toString;
alias toString str;


Myron Alexander schrieb:
 Chris Nicholson-Sauls wrote:
 I'm not sure what the reasoning is, and would just assume have 
 private aliases as well. But I can add another option.  Assuming you 
 just want std.string.* to have a shorter name, you could try a 
 static+renaming import.

 static import str = std.string;
 // ...
 str.toString(50);

 If its something else you're after... then I don't know.

 -- Chris Nicholson-Sauls
Chris, I do not want to rename the module, I want to use "str" instead of "toString". The alias is a natural solution but I do not want it imported into the caller name space. Regards, Myron.
Aug 14 2007