www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Thoughts about private aliases now working

reply Robert Clipsham <robert octarineparrot.com> writes:
Hi all,

I had to skip dmd 2.057 due to various bugs, so in the hopes that I'll 
be able to use my codebase with 2.058 I'm testing it early. Due to some 
fixes with private imports, some code I was previously using no longer 
works. It looks a little like this:

a.d
----
private alias string[string] SS;
mixin template Func()
{
     SS someFunc(SS s)
     {
         return s;
     }
}
----

b.d
----
import a;
mixin Func;
----

Now that private aliases work, this errors as expected (SS shouldn't be 
visible in b.d). What this does mean however is that I have to do one of:

  * Type out the type in full in Func (I'm not actually using 
string[string] in my code, it's a rather longer named type)
  * Make the alias public so it's available to all modules that import Func.

As it's an implementation detail, I'd rather not have it appear in user 
code, which rules out the latter, and typing out the full type makes a 
simple declaration use up several lines (or one obscenely long line!)

Are there any other options I'm missing? Is there some way to make the 
alias visible within the mixin but not elsewhere?

Thanks,

-- 
Robert
http://octarineparrot.com/
Feb 01 2012
next sibling parent reply "Vladimir Panteleev" <vladimir thecybershadow.net> writes:
On Wednesday, 1 February 2012 at 23:14:47 UTC, Robert Clipsham 
wrote:
 Are there any other options I'm missing?

How about this:
 a.d
 ----
 private alias string[string] SS;
 mixin template Func()
 {

private alias a.SS SS;
    SS someFunc(SS s)
    {
        return s;
    }
 }

( Amusing that the solution to a problem regarding private aliases would be more private aliases :) )
Feb 01 2012
parent Jacob Carlborg <doob me.com> writes:
On 2012-02-02 02:14, Martin Nowak wrote:
 On Thu, 02 Feb 2012 01:55:11 +0100, Vladimir Panteleev
 <vladimir thecybershadow.net> wrote:

 On Wednesday, 1 February 2012 at 23:14:47 UTC, Robert Clipsham wrote:
 Are there any other options I'm missing?


mixin template Func() { private alias string[string] SS; SS someFunc(SS s) { return s; } }

If you don't want to declare the alias in the mixin another idea would be to declare it in a new module and import that one in the mixin. -- /Jacob Carlborg
Feb 01 2012
prev sibling next sibling parent "Martin Nowak" <dawg dawgfoto.de> writes:
On Thu, 02 Feb 2012 01:55:11 +0100, Vladimir Panteleev  
<vladimir thecybershadow.net> wrote:

 On Wednesday, 1 February 2012 at 23:14:47 UTC, Robert Clipsham wrote:
 Are there any other options I'm missing?


mixin template Func() { private alias string[string] SS; SS someFunc(SS s) { return s; } }
 How about this:

 a.d
 ----
 private alias string[string] SS;
 mixin template Func()
 {

private alias a.SS SS;

bug and is fixed here https://github.com/D-Programming-Language/dmd/pull/669.
Feb 01 2012
prev sibling next sibling parent "Marco Leise" <Marco.Leise gmx.de> writes:
Am 02.02.2012, 02:14 Uhr, schrieb Martin Nowak <dawg dawgfoto.de>:

 On Thu, 02 Feb 2012 01:55:11 +0100, Vladimir Panteleev  
 <vladimir thecybershadow.net> wrote:

 On Wednesday, 1 February 2012 at 23:14:47 UTC, Robert Clipsham wrote:
 Are there any other options I'm missing?


mixin template Func() { private alias string[string] SS; SS someFunc(SS s) { return s; } }
 How about this:

 a.d
 ----
 private alias string[string] SS;
 mixin template Func()
 {

private alias a.SS SS;

bug and is fixed here https://github.com/D-Programming-Language/dmd/pull/669.

I thought mixin templates were _supposed_ to run in the scope of the call site. Doesn't this mixin with the mixin blur the line and make the language less consistent/more confusing?
Feb 01 2012
prev sibling parent "Martin Nowak" <dawg dawgfoto.de> writes:
 I thought mixin templates were _supposed_ to run in the scope of the  
 call site. Doesn't this mixin with the mixin blur the line and make the  
 language less consistent/more confusing?

They are. And the mixin body is valid in the scope of b.
Feb 02 2012