Struct Initialization syntax
rikki cattermole
rikki at cattermole.co.nz
Tue Jul 24 03:54:27 UTC 2018
On 24/07/2018 7:11 AM, Jacob Carlborg wrote:
> On 2018-07-23 18:26, Seb wrote:
>> tl;dr: the currently proposed syntax options are:
>>
>>
>> ---
>> struct S
>> {
>> int a = 2, b = 4, c = 6;
>> }
>> void foo()
>> {
>> bar(S({c: 10})); // Option 1
>> bar(S(c: 10)); // Option 2
>> bar(S{c: 10}); // Option 3
>> }
>> ---
>>
>> So the struct-initialization DIP has been stalled for too long and I
>> think it's time we finally get this story done.
>> I personally prefer option 2, but this might be in conflict to named
>> arguments which we hopefully see in the near future too. Hence, I'm
>> leaning forward to proposing Option 1 as the recommended Option for
>> the DIP (that's also what the PoC DMD PR implements). What's your take
>> on this?
>>
>> DIP: https://github.com/dlang/DIPs/pull/71
>> Rendered view:
>> https://github.com/wilzbach/DIPs/blob/struct-initialization/DIPs/DIP1xxx-sw.md
>
>
> Talking about future potential features, Option 1 could be in conflict
> with a tuple with named elements. Option 2 could be in conflict with
> named parameters, true, but named parameters could also have a different
> syntax, i.e. foo(a = 3, b = 4), this is what Scala is using.
We ugh can't use that syntax because of ambiguity to AssignExpression.
More information about the Digitalmars-d
mailing list