Re: Multiple alias this is coming.

2018-10-25 Thread Michelle Long via Digitalmars-d-announce
On Thursday, 18 September 2014 at 11:20:49 UTC, IgorStepanov 
wrote:

I've created pull request, which introduces multiple alias this.
https://github.com/D-Programming-Language/dmd/pull/3998
Please see the additional tests and comment it.


Haha, that is funny!


Re: Multiple alias this is coming.

2014-09-19 Thread Nordlöw
On Thursday, 18 September 2014 at 22:13:14 UTC, IgorStepanov 
wrote:

Is Nullable!(T) with polymorphic type disallowed now?


Sorry, I meant

NotNull(T)

Here's a module

https://github.com/nordlow/justd/blob/master/notnull.d

a bit tweak from the original design by Adam D Ruppe.



Re: Multiple alias this is coming.

2014-09-19 Thread IgorStepanov via Digitalmars-d-announce

On Friday, 19 September 2014 at 11:25:03 UTC, Nordlöw wrote:
On Thursday, 18 September 2014 at 22:13:14 UTC, IgorStepanov 
wrote:

Is Nullable!(T) with polymorphic type disallowed now?


Sorry, I meant

NotNull(T)

Here's a module

https://github.com/nordlow/justd/blob/master/notnull.d

a bit tweak from the original design by Adam D Ruppe.


What does a troubles with your NotNull implementation you have 
with old alias this?
Do you want to implicit cast from NotNull!(T) to all other 
NotNull!(B) where B is basetype of T?


Re: Multiple alias this is coming.

2014-09-19 Thread Andrei Alexandrescu via Digitalmars-d-announce

On 9/19/14, 3:21 AM, Dicebot wrote:

On Friday, 19 September 2014 at 09:34:22 UTC, ponce wrote:

Call me unimaginative, but I'm struggling to see any use case for
multiple alias this, and I struggle even more for such constructors
aliasing.


Pretty much every single time you have ever wanted to do multiple
inheritance of implementation multiple `alias this` was the proper tool
for a job. I notice myself thinking this could have been done much
cleaner with multiple alias this at least once a month :)


Yah, multiple subtyping of structs is terrific to have. Thanks Igor for 
this work! -- Andrei




Re: Multiple alias this is coming.

2014-09-19 Thread Nordlöw

On Friday, 19 September 2014 at 13:24:53 UTC, IgorStepanov wrote:
What does a troubles with your NotNull implementation you have 
with old alias this?
Do you want to implicit cast from NotNull!(T) to all other 
NotNull!(B) where B is basetype of T?


Yes, that is what I want, but last time I checked DMD didn't 
allow me to.


Re: Multiple alias this is coming.

2014-09-19 Thread IgorStepanov via Digitalmars-d-announce

On Friday, 19 September 2014 at 17:59:44 UTC, Nordlöw wrote:
On Friday, 19 September 2014 at 13:24:53 UTC, IgorStepanov 
wrote:
What does a troubles with your NotNull implementation you have 
with old alias this?
Do you want to implicit cast from NotNull!(T) to all other 
NotNull!(B) where B is basetype of T?


Yes, that is what I want, but last time I checked DMD didn't 
allow me to.


This PR doesn't allow template alias this, however you can 
iterate all subtypes for you class T (D meta-programming features 
allow you to do it now) and mixin different alias this 
declaration for all of this types.


Re: Multiple alias this is coming.

2014-09-19 Thread Nordlöw
On Thursday, 18 September 2014 at 11:20:49 UTC, IgorStepanov 
wrote:

I've created pull request, which introduces multiple alias this.
https://github.com/D-Programming-Language/dmd/pull/3998
Please see the additional tests and comment it.


Further, could this also be used to somehow simplify 
hierarchically defined enumerators? Typically the enumerators and 
predicates related to the enumeration WordKind defined here


https://github.com/nordlow/justd/blob/master/languages.d#L485


Re: Multiple alias this is coming.

2014-09-19 Thread IgorStepanov via Digitalmars-d-announce

On Friday, 19 September 2014 at 17:19:09 UTC, Andrei Alexandrescu
wrote:

On 9/19/14, 3:21 AM, Dicebot wrote:

On Friday, 19 September 2014 at 09:34:22 UTC, ponce wrote:
Call me unimaginative, but I'm struggling to see any use case 
for
multiple alias this, and I struggle even more for such 
constructors

aliasing.


Pretty much every single time you have ever wanted to do 
multiple
inheritance of implementation multiple `alias this` was the 
proper tool
for a job. I notice myself thinking this could have been done 
much

cleaner with multiple alias this at least once a month :)


Yah, multiple subtyping of structs is terrific to have. Thanks 
Igor for this work! -- Andrei


You are welcome :)
BTW. Please comment (approve or correct) semantic rules, which
used for conflict resolving.
I've written it early and reflected it in the PR tests.


Re: Multiple alias this is coming.

2014-09-19 Thread Jesse Phillips via Digitalmars-d-announce
On Thursday, 18 September 2014 at 20:11:12 UTC, IgorStepanov 
wrote:
Do you ask about alias this or about it multiple usage. 
Multiple usage is similar to single, but multiple:)


Just an FYI, bearophile is very knowledgeable about D and one of 
the oldest community members, he holds the record for most bugs 
opened.


This doesn't mean he knows everything, but it certainly makes it 
clear he was asking, why would you want to use multiple alias 
this. As others mention kind of like why would you want to use 
multiple inheritance.


Re: Multiple alias this is coming.

2014-09-19 Thread Dmitry Olshansky via Digitalmars-d-announce

19-Sep-2014 02:16, bearophile пишет:

IgorStepanov:


Do you ask about alias this or about it multiple usage. Multiple usage
is similar to single, but multiple:)


I meant the multiple usage. And none of your examples here are use cases
:-( I'd like to see one use case, or more.



For instance one could implement OOP and polymorphism on structs, all in 
library code.


struct Base {   }

struct Itnerface {  }

struct Derived{
Base _super;
Interface _iface;
alias this _super;
alias this _iface;
}

I recall trying something like that but stopping because I needed 
multiple alias this.



--
Dmitry Olshansky


Re: Multiple alias this is coming.

2014-09-19 Thread IgorStepanov via Digitalmars-d-announce

On Friday, 19 September 2014 at 18:46:14 UTC, IgorStepanov wrote:
On Friday, 19 September 2014 at 17:19:09 UTC, Andrei 
Alexandrescu

wrote:

On 9/19/14, 3:21 AM, Dicebot wrote:

On Friday, 19 September 2014 at 09:34:22 UTC, ponce wrote:
Call me unimaginative, but I'm struggling to see any use 
case for
multiple alias this, and I struggle even more for such 
constructors

aliasing.


Pretty much every single time you have ever wanted to do 
multiple
inheritance of implementation multiple `alias this` was the 
proper tool
for a job. I notice myself thinking this could have been 
done much

cleaner with multiple alias this at least once a month :)


Yah, multiple subtyping of structs is terrific to have. Thanks 
Igor for this work! -- Andrei


You are welcome :)
BTW. Please comment (approve or correct) semantic rules, which
used for conflict resolving.
I've written it early and reflected it in the PR tests.



Further, could this also be used to somehow simplify

hierarchically defined enumerators? Typically the enumerators and
predicates related to the enumeration WordKind defined here

enum can have a class as base type:

import std.stdio;

class Word
{
 this(string type)
 {
 this.type = type;
 }

 @property abstract string wordClass();

 override size_t toHash() @trusted
 {
 string s = toString();
 return typeid(string).getHash(s);
 }

 override string toString() @trusted nothrow
 {
 try
 {
 return wordClass() ~ : ~ type;
 }
 catch(Throwable th)
 {
 assert(0);
 }
 }

 string type;
}

class Noun : Word
{
 this (string type)
 {
 super(type);
 }

 @property override string wordClass()
 {
 return noun;
 }
}

class Verb : Word
{
 this (string type)
 {
 super(type);
 }

 @property override string wordClass()
 {
 return verb;
 }
}

enum WordKind : Word
{
 Unknown = null,
 Numeric = new Noun(Numeric),
 //...
 Present = new Verb(Present),
}

import std.stdio;
void main()
{
 string[][WordKind] dictionary;
 dictionary[WordKind.Numeric] ~= one;
 dictionary[WordKind.Numeric] ~= two;
 dictionary[WordKind.Present] ~= go;
 writeln(dictionary);
}

Does this code can help you?


Re: Multiple alias this is coming.

2014-09-19 Thread IgorStepanov via Digitalmars-d-announce
On Friday, 19 September 2014 at 18:49:57 UTC, Jesse Phillips 
wrote:
On Thursday, 18 September 2014 at 20:11:12 UTC, IgorStepanov 
wrote:
Do you ask about alias this or about it multiple usage. 
Multiple usage is similar to single, but multiple:)


Just an FYI, bearophile is very knowledgeable about D and one 
of the oldest community members, he holds the record for most 
bugs opened.


This doesn't mean he knows everything, but it certainly makes 
it clear he was asking, why would you want to use multiple 
alias this. As others mention kind of like why would you want 
to use multiple inheritance.



Sorry, I'll note it.:)


why would you want to use multiple inheritance.


I've written example with interface inherinatce.
Structs can be preferable then classes, when I want to manage 
them allocating manually. When you use D as better C, powerfull 
struct's can be a you choise.


Multiple alias this (and therefore multiply inheritance) makes 
structs almost as powerful as classes.


Another my motivation of doing this work is a implementing alias 
this inheritance (from base class).
Situation when B can be casted to C and D, A can be casted to B 
and C but cannot be casted to D is wrong:


class B : C
{
   alias d this;
   D d;
}

class A : B
{
}

A a = new A;
D d = a; //NG - OK


Multiple alias this is coming.

2014-09-18 Thread IgorStepanov via Digitalmars-d-announce

I've created pull request, which introduces multiple alias this.
https://github.com/D-Programming-Language/dmd/pull/3998
Please see the additional tests and comment it.


Re: Multiple alias this is coming.

2014-09-18 Thread Rikki Cattermole via Digitalmars-d-announce

On 18/09/2014 11:20 p.m., IgorStepanov wrote:

I've created pull request, which introduces multiple alias this.
https://github.com/D-Programming-Language/dmd/pull/3998
Please see the additional tests and comment it.


Awesome was waiting for something like this!

Also did we ever consider alias this = ...; syntax?


Re: Multiple alias this is coming.

2014-09-18 Thread via Digitalmars-d-announce
On Thursday, 18 September 2014 at 12:51:48 UTC, Rikki Cattermole 
wrote:

On 18/09/2014 11:20 p.m., IgorStepanov wrote:
I've created pull request, which introduces multiple alias 
this.

https://github.com/D-Programming-Language/dmd/pull/3998
Please see the additional tests and comment it.


Awesome was waiting for something like this!

Also did we ever consider alias this = ...; syntax?


It clashes with (not yet supported) aliasing of constructors.


Re: Multiple alias this is coming.

2014-09-18 Thread Foo via Digitalmars-d-announce

On Thursday, 18 September 2014 at 18:38:57 UTC, Ali Çehreli wrote:

On 09/18/2014 04:20 AM, IgorStepanov wrote:
I've created pull request, which introduces multiple alias 
this.

https://github.com/D-Programming-Language/dmd/pull/3998
Please see the additional tests and comment it.


Awesome!

This is the feature that I thought would never get implemented. 
:)


Ali


No, these are rvalue references. ;)


Re: Multiple alias this is coming.

2014-09-18 Thread bearophile via Digitalmars-d-announce

IgorStepanov:

I've created pull request, which introduces multiple alias this.


Can someone show one or more usage cases?

Thank you,
bye,
bearophile


Re: Multiple alias this is coming.

2014-09-18 Thread IgorStepanov via Digitalmars-d-announce

On Thursday, 18 September 2014 at 19:52:42 UTC, bearophile wrote:

IgorStepanov:
I've created pull request, which introduces multiple alias 
this.


Can someone show one or more usage cases?

Thank you,
bye,
bearophile


Do you ask about alias this or about it multiple usage. Multiple 
usage is similar to single, but multiple:)


struct Foo
{
string s;
int i;

alias s this;
alias i this;
}

Foo f = {foo, 42};
string s = f; //s == foo
int i = f; //i == 42

If there are many different ways to resolve alias this then error 
is raised:


struct Bar
{
double d;
int i;

alias d this;
alias i this;
}

Foo f = {1.0, 42};
double d = f; //Error: compiler doesn't know, f.d or f.i do you 
want.


In the next expamle, compiler can resolve conflict:

struct Base1
{
int i;

alias i this;
}

struct Base2
{
int i;

alias i this;
}

struct Derived
{
Base1 b1;
Base2 b2;
int i;

alias b1 this;
alias b2 this;
alias i this;
}

Derived d = Derived(Base1(1), Base2(2), 3);
int i = d; //i == 3;
This done because Derived author know, how to cast his struct to 
int, and if he say alias i this; this alias hide aliases in base 
types.


However, if base type contains alias this to another acceptable 
type, and derived typ hasn't exactly castable alias this then 
error will be raised:


struct Base1
{
short s;

alias s this;
}

struct Base2
{
int i;

alias i this;
}

struct Derived
{
Base1 b1;
Base2 b2;
int i;

alias b1 this;
alias b2 this;
alias i this;
}

Derived d = Derived(Base1(1), Base2(2), 3);
int i = d; //Ok i == 3;
long l = d; //Error: what do you want? d.i or d.b1.s?

For additional info you can see examples in my pull request.


Re: Multiple alias this is coming.

2014-09-18 Thread Nordlöw
On Thursday, 18 September 2014 at 11:20:49 UTC, IgorStepanov 
wrote:

I've created pull request, which introduces multiple alias this.
https://github.com/D-Programming-Language/dmd/pull/3998
Please see the additional tests and comment it.


Exciting!

What more good things than a better behaving Nullable(T) with T 
being a polymorphic class will this enable?


Re: Multiple alias this is coming.

2014-09-18 Thread bearophile via Digitalmars-d-announce

IgorStepanov:

Do you ask about alias this or about it multiple usage. 
Multiple usage is similar to single, but multiple:)


I meant the multiple usage. And none of your examples here are 
use cases :-( I'd like to see one use case, or more.


Bye,
bearophile


Re: Multiple alias this is coming.

2014-09-18 Thread Ali Çehreli via Digitalmars-d-announce

On 09/18/2014 12:52 PM, bearophile wrote:

 Can someone show one or more usage cases?

I can't claim that I have experience with multiple alias this ;) but I 
like the following example that I had come up with:


class TeachingAssistant
{
Student studentIdentity;
Teacher teacherIdentity;

this(string name, string subject)
{
this.studentIdentity = new Student(name);
this.teacherIdentity = new Teacher(name, subject);
}

/* The following two 'alias this' declarations will enable
 * this type to be used both as a Student and as a Teacher. */
alias teacherIdentity this;
alias studentIdentity this;
}

Ali

[1] http://ddili.org/ders/d.en/alias_this.html



Re: Multiple alias this is coming.

2014-09-18 Thread ketmar via Digitalmars-d-announce
On Thu, 18 Sep 2014 15:20:04 -0700
Ali Çehreli via Digitalmars-d-announce
digitalmars-d-announce@puremagic.com wrote:

 [1] http://ddili.org/ders/d.en/alias_this.html
heh, i just wanted to point at your book. ;-)


signature.asc
Description: PGP signature


Re: Multiple alias this is coming.

2014-09-18 Thread IgorStepanov via Digitalmars-d-announce

On Thursday, 18 September 2014 at 22:16:23 UTC, bearophile wrote:

IgorStepanov:

Do you ask about alias this or about it multiple usage. 
Multiple usage is similar to single, but multiple:)


I meant the multiple usage. And none of your examples here are 
use cases :-( I'd like to see one use case, or more.


Bye,
bearophile


For example, you can define struct (value-type with automatic
storage class) which implements interfaces:

intarface InputStream
{
...
}

intarface OutputStream
{
...
}
struct File
{
this(string name, string options)
{
impl = new FileImpl(name, options);
}

~this()
{
impl.close();
}

@property InputStream inputStream()
{
   return new class(impl) InputStream
   {
   //InputStream implementation
   ...
   }
}

@property OutputStream outputStream()
{
   return new class(impl) OutputStream
   {
   //OutputStream implementation
   ...
   }
}

alias inputStream this;
alias seekable this;
FileImpl* impl;
}


Record[] readData(InputStream);
void storeData(OutputStream, Record[]);

Record[] extractRecords()
{
File f = File(records.bin, rw);
auto data = readData(f);
///split to extracted and remaining
f.truncate();
writeData(f, remaining);
return extracted;
}


Re: Multiple alias this is coming.

2014-09-18 Thread deadalnix via Digitalmars-d-announce
On Thursday, 18 September 2014 at 11:20:49 UTC, IgorStepanov 
wrote:

I've created pull request, which introduces multiple alias this.
https://github.com/D-Programming-Language/dmd/pull/3998
Please see the additional tests and comment it.


What is the policy to resolve conflict ?

BTW, SDC already have multiple alias this :)