Should aliasing a lambda expression be allowed?

Steven Schveighoffer schveiguy at yahoo.com
Wed Nov 15 12:28:02 UTC 2017


On 11/14/17 8:56 PM, Michael V. Franklin wrote:
> On Tuesday, 14 November 2017 at 23:41:39 UTC, Steven Schveighoffer wrote:
>> In fact, I'm surprised you can alias to an expression like that. 
>> Usually you need a symbol. It's probably due to how this is lowered.
> 
> Boy did I "step in it" with my original post:  Started out with one 
> issue and ended up with 3.
> 
> I looked at what the compiler is doing, and it is generated a new symbol 
> (e.g. `__lambda4`).  I suspect this is not intended.
> 
> My question now is, should the compiler actually be treating the lambda 
> as an expression instead of a new symbol, thus disallowing it 
> altogether? (sigh! more breakage)?

I don't think we can prevent the aliasing in the first place, because if 
this is possible, I guarantee people use it, and it looks quite handy 
actually. Much less verbose than templates:

alias mul = (a, b) => a * b;

vs.

auto mul(A, B)(A a, B b) { return a * b; }

However, it would be good to prevent the second alias which effectively 
does nothing.

-Steve


More information about the Digitalmars-d mailing list