DIP 1020--Named Parameters--Community Review Round 1

Meta jared771 at gmail.com
Tue Apr 2 01:13:49 UTC 2019


On Tuesday, 2 April 2019 at 00:49:08 UTC, rikki cattermole wrote:
> On 02/04/2019 12:22 PM, sarn wrote:
>> On Monday, 1 April 2019 at 14:41:20 UTC, rikki cattermole 
>> wrote:
>>> On 02/04/2019 3:09 AM, Atila Neves wrote:
>>>> There are known reasons why using angle brackets complicates 
>>>> lexing (cough! C++! cough!), so the syntax choice is odd. Is 
>>>> there a particular reason why the usage suggested here 
>>>> avoids the issues?
>>>
>>> As far as I'm aware, we should have no problems with adapting 
>>> dmd-fe to support it.
>>>
>>> Of course I could have missed something (either in dmd or 
>>> outside). So it would be good to have somebody else double 
>>> check that statement.
>> 
>> You already have to deal with the case of variadic function 
>> definitions, so why not just extend the syntax?
>> 
>> I.e., in this declaration
>> 
>> void foo(int a, int b, ..., int c);
>> 
>> c must be a named argument, even without any special 
>> decorators. In that case the ... argument acts as a 
>> delimiter.  So all you need is rules for separating positional 
>> arguments from named arguments for non-variadic functions.
>
> Looks like a good idea, although a poor choice for this DIP.
> It could only work for function parameters, it won't work for 
> templates.
>
> I don't think I've seen this idea come up before, so please do 
> explore it if we don't get another solution in before hand!

Is it possible to lex the "public" keyword unambiguously when 
applied to parameters?

long foo(int v, int w, int x, public int y, public int z)

foo(1, 2, 3, y: 4, z:5);

Many named args proposals for Rust propose this syntax. Another 
alternative is `export` on parameters.

Or, something a little more interesting, but with unknown 
ramifications and possibly insane:

//z is a named parameter with a default value
long foo(int v, int w, int x, struct optargs { int y, int z = 3 })

foo(1, 2, 3, { y: 4 });
foo(1, 2, 3, { y: 4, z: 5 });
foo(1, 2, 3, optargs { y: 4, z: 5 });
foo(1, 2, 3, optargs { 4, 5 });
foo(1, 2, 3, { z: 5 }); //Error: cannot call function foo(int, 
int, int, struct optargs { int y, int z = 3 }) with arguments (1, 
2, 3, { z: 5 }). Missing non-optional parameter y in optargs

Just channeling the old struct DIP. I have no idea if this can 
even be lexed unambiguously.




More information about the Digitalmars-d mailing list