View mode: basic / threaded / horizontal-split · Log in · Help
August 13, 2007
private alias for module
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.
August 14, 2007
Re: private alias for module
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
August 14, 2007
Re: private alias for module
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.
August 14, 2007
Re: private alias for module
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.
Top | Discussion index | About this forum | D home