Flag proposal

Ary Manzana ary at esperanto.org.ar
Mon Jun 13 18:46:54 PDT 2011


On 6/14/11 8:36 AM, so wrote:
> On Mon, 13 Jun 2011 20:19:15 +0300, bearophile <
> <bearophileHUGS at lycos.com> wrote:
>
>> Andrei:
>>
>>> If we all get convinced that named parameters are worth it,
>>
>> I think this is not going to happen because some people (two?) don't
>> want this feature.
>
> I think they worth it and it is the right time to talk extensively why
> people think they don't.
> And reasoning should not be about its failure or success in another
> language, we better have our own rules.
>
> IMO named arguments in D at least should do:
>
> - Reordering (since we got default parameters, even better)
>
> - It is enabled only if we have access to the function declaration.
>
> - In a function call we either use named arguments for all the
> non-default arguments or call it with the usual syntax. No hybrid stuff,
> no confusion.

A different rule can be:
  - Named arguments come last.
  - Any previous arguments match the order.


>
> fun(int a, int b, int c=3)
>
> fun(1, 2, 3) // fine - current
> fun(1, 2) // fine - current
>
> fun(a:1, b:3, c:5) // fine
> fun(a:1, b:3) // fine
> fun(b:1, c:3, a:5) // fine
> fun(b:1, a:3) // fine
> fun(b:1) // error
// error: missing a

> fun(c:1) // error
// error: missing a and b
> fun(2, b:1) // error
// ok, a is 2, b is 1, c is 3

> fun(2, c:1) // error
// error: missing b

> fun(2, c:2, 3) // error
// error, 3 after named arguments


More information about the Digitalmars-d mailing list