January 25, 2016
On 2016-01-24 19:23, Chris Wright wrote:

> It shouldn't. However, it is another way to pass function arguments, so
> for thoroughness it would be better to mention it.

Added an example.

> Is this what you intended? If so, please document it so other reviewers
> don't have to wonder.

Added an example.

-- 
/Jacob Carlborg
January 25, 2016
On Monday, 25 January 2016 at 08:55:55 UTC, Jacob Carlborg wrote:
> On 2016-01-24 19:23, Chris Wright wrote:
>
>> It shouldn't. However, it is another way to pass function arguments, so
>> for thoroughness it would be better to mention it.
>
> Added an example.
>
>> Is this what you intended? If so, please document it so other reviewers
>> don't have to wonder.
>
> Added an example.

hi, named args is mainly a feature for the caller, is it really necessary to add a new syntax to the function definition?
besides making some args part of the api and some not.

and if you cant omit args with default initializer like in your example

void foo(int a: = 3, int b: = 4);
foo();
foo(a: 5, b: 6);
foo(b: 6); // this is not allowed since it's not legal to reorder the arguments

this feature is nothing more then a comment and the simplest way to implement this, is to add a single word comment type which might be usefull in more situations.

January 25, 2016
On Sunday, 24 January 2016 at 02:51:43 UTC, Jonathan M Davis wrote:
> On Saturday, 23 January 2016 at 14:19:03 UTC, Jacob Carlborg wrote:
>> This is mostly to prevent ugly hacks like Flag [1].
>>
>> http://wiki.dlang.org/DIP88
>>
>> [1] https://dlang.org/phobos/std_typecons.html#.Flag
>
> To be pedantic, this would be adding named arguments, not named parameters. The parameters are already named, but mixing up arguments and parameters is a common mistake to make, and folks do frequently talk about named parameters with regards to this sort of feature.

To be even more pedantic it is usually called formal and active parameters:

void f(int a) // formal parameter

f(3) // actual parameter

January 25, 2016
On Saturday, 23 January 2016 at 14:19:03 UTC, Jacob Carlborg wrote:
> This is mostly to prevent ugly hacks like Flag [1].
>
> http://wiki.dlang.org/DIP88
>
> [1] https://dlang.org/phobos/std_typecons.html#.Flag

Why not simply allow programmer to declare auto variable at function call side like in `foreach`?

E.g.

```d
void foo(int width, int height){...} //function definition

foo(width = 2, height = 3); // function call
```
January 25, 2016
On Monday, 25 January 2016 at 13:40:18 UTC, HaraldZealot wrote:
> On Saturday, 23 January 2016 at 14:19:03 UTC, Jacob Carlborg wrote:
>> This is mostly to prevent ugly hacks like Flag [1].
>>
>> http://wiki.dlang.org/DIP88
>>
>> [1] https://dlang.org/phobos/std_typecons.html#.Flag
>
> Why not simply allow programmer to declare auto variable at function call side like in `foreach`?
>
> E.g.
>
> ```d
> void foo(int width, int height){...} //function definition
>
> foo(width = 2, height = 3); // function call
> ```

the equal sign cant be used because D behaves like this

int width, height;

foo(width = 5, height = 10); // 5
                             // 10
width.writeln;  // 5
height.writeln; // 10

void foo(int width, int height)
{
    width.writeln;
    height.writeln;
}

and in python

def foo(width, height):
    print(width)
    print(height)

width = 0
height = 0
foo(width = 5, height = 10) # 5
                            # 10
print(width)  # 0
print(height) # 0

January 25, 2016
On Saturday, 23 January 2016 at 14:19:03 UTC, Jacob Carlborg wrote:
> This is mostly to prevent ugly hacks like Flag [1].
>
> http://wiki.dlang.org/DIP88
>
> [1] https://dlang.org/phobos/std_typecons.html#.Flag

I agree Flag is a bit ugly to use, but IIUC this proposal does not enforce the use of a named argument, it's optional. Flag does call site name enforcement.

Also, named template arguments is an interesting idea, but they don't seem to be so useful as named function arguments. Boolean function arguments are pretty common, but I'm not sure templates have an equivalent compelling example. They could be left out at first perhaps.
January 25, 2016
On Mon, 25 Jan 2016 12:56:01 +0000, arturg wrote:

> On Monday, 25 January 2016 at 08:55:55 UTC, Jacob Carlborg wrote:
>> On 2016-01-24 19:23, Chris Wright wrote:
>>
>>> It shouldn't. However, it is another way to pass function arguments, so for thoroughness it would be better to mention it.
>>
>> Added an example.
>>
>>> Is this what you intended? If so, please document it so other reviewers don't have to wonder.
>>
>> Added an example.
> 
> hi, named args is mainly a feature for the caller, is it really necessary to add a new syntax to the function definition? besides making some args part of the api and some not.

Python, C#, Scala, and Ada do not require any special annotations at the function definition to use named arguments. Dart and Ruby do.

Obviously it's not necessary, but there is precedent both ways.

> this feature is nothing more then a comment and the simplest way to implement this, is to add a single word comment type which might be usefull in more situations.

It's a comment that the compiler verifies. You could argue that the bulk of the type system is comments that the compiler verifies.
January 25, 2016
On Monday, 25 January 2016 at 16:17:27 UTC, Chris Wright wrote:

>
> It's a comment that the compiler verifies. You could argue that the bulk of the type system is comments that the compiler verifies.

named arguments solve this problem

void foo(int a = 4, int b = 10, int c = 3) {}

foo(c : 5);

beeing callside documentation is only a byproduct.
January 25, 2016
On Monday, 25 January 2016 at 14:35:09 UTC, arturg wrote:
> On Monday, 25 January 2016 at 13:40:18 UTC, HaraldZealot wrote:
> the equal sign cant be used because D behaves like this
>
> int width, height;
>
> foo(width = 5, height = 10); // 5
>                              // 10
> width.writeln;  // 5
> height.writeln; // 10
>
> void foo(int width, int height)
> {
>     width.writeln;
>     height.writeln;
> }
>

You didn't pay attention, that in my proposal `foo(width = 5, height = 10);` width and height were declared in place of use, and scope is only this call
January 25, 2016
On Monday, 25 January 2016 at 16:38:19 UTC, arturg wrote:
>
> named arguments solve this problem
>
> void foo(int a = 4, int b = 10, int c = 3) {}
>
> foo(c : 5);
>
> beeing callside documentation is only a byproduct.

I wouldn't classify that as a problem per se, more of an inconvenience. And a bigger inconvenience the longer the list of default arguments.