Tuple DIP

Timon Gehr timon.gehr at gmx.ch
Thu Mar 15 16:14:59 UTC 2018


On 15.03.2018 14:42, Nick Treleaven wrote:
> On Wednesday, 17 January 2018 at 06:44:21 UTC, Timon Gehr wrote:
>> It uses tuples because it uses zip. The code does not compile today, 
>> because the lambda I'm passing to "map" has two parameters:
>>
>> auto a = [1, 2, 4, 7, 2];
>> auto b = [3, 5, 3, 2, 4];
>>
>> // auto c = zip(a, b).map!((x, y) => x + y); // error
>>
>> auto c = zip(a, b).map!(t => t[0] + t[1]); // ok
> 
> We could make lambdas consistent with proposal 5:
> ...

Good point. That's indeed the intention, but I didn't get around to 
updating the grammar section.

> ...
> // lambda takes one tuple of two elements
> alias f = ((x, y)) => x + y;
> auto c = zip(a, b).map!f; // ok
> 
> Is there a better example as to why a tuple decaying to function 
> arguments is worth having vs the language complication?

Yes, but I don't think a better example is even needed. If you think 
((x, y)) => x + y is tolerable, you are unlikely to be convinced by a 
better example.

There's also the point that it is not unreasonable to expect that it 
already works when reading https://dlang.org/spec/class.html#alias-this.


More information about the Digitalmars-d mailing list