DIP 1030--Named Arguments--Community Review Round 1 Feedback

Timon Gehr timon.gehr at gmx.ch
Fri Feb 7 23:44:31 UTC 2020


On 07.02.20 21:02, Walter Bright wrote:
> On 2/6/2020 7:49 PM, Timon Gehr wrote:
>>
>> import std.typecons;
>> alias t=AliasSeq!(c:1, a:2, b:3); // valid according to DIP
>> void foo(int a,int b,int c){
>>      writeln(a," ",b," ",c);
>> }
>>
>> void main(){
>>      foo(t);
>> }
>>
>> I'd expect this to print "2 3 1".
>>
>> I think this is important for forwarding applications, so deserves 
>> explicit treatment. There should also be a way to access the argument 
>> names in a given sequence.
>>
>> This is also the reason why I think this part of the DIP is probably 
>> not ideal: "If there are more NamedArguments than Parameters, the 
>> remainder match the trailing ... of variadic parameter lists, and 
>> Identifiers are not allowed."
>>
>> IMHO, any leftover named arguments should be collected into the 
>> variadic parameters.
> 
> So,
> 
>      void foo(int a, ...);
> 
> called with:
> 
>      foo(b:1, 2)
> 
> should be the equivalent of:
> 
>      foo(2, 1)
> 
> ?

I was thinking about template variadics, not sure about the C-style 
ones. I think your example would not match in any case, because unnamed 
arguments after a named argument match the next parameter, so actually 
you don't provide a value for 'a'. Also, the name would have to be 
preserved through the template instantiation.

void foo(T...)(int a, T args){ ... }

foo(b: 1, a: 2)
<=>
foo!(b: int)(2, 1);

Constructs like https://dlang.org/library/std/typecons/proxy.html should 
ideally not break.


More information about the Digitalmars-d mailing list