January 25, 2016
On Monday, 25 January 2016 at 16:50:49 UTC, HaraldZealot wrote:
> 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

this code compiles right now which would make it a breaking change if you use the = and change the current behavior

module foo;

int width;
int height;

module app;
import foo;

void bar(int width, int height) {}

void main()
{
    bar(width = 5, height = 10);
}

January 26, 2016
On Sunday, 24 January 2016 at 13:33:50 UTC, Jacob Carlborg wrote:
> On 2016-01-24 14:24, Michel Fortin wrote:
>
>> On further thought, how do you make templates with specialization take
>> named arguments?
>>
>>      template TFoo(T)        { ... } // #1
>>      template TFoo(T : T[])  { ... } // #2
>>      template TFoo(T : char) { ... } // #3
>>
>> My guess would be this:
>>
>>      template TFoo(T:)        { ... } // #1
>>      template TFoo(T: : T[])  { ... } // #2
>>      template TFoo(T: : char) { ... } // #3
>>
>> ... but it makes the declaration a bit strange.
>
> Yes. Rule 7 covers that. There's also an example showing the syntax, search for "Template specialization with named parameter". Yes, it does look a bit strange.

Just like C++98 used to require space between two `>` in templates ? ;)
I see no way Walter would accept that.

Why not just:
```
@namedParams
template TFoo(T : char)
```

Other thoughts:
1. How often would one need to mix named and unnamed parameters ?
2. And how often would one need named params at all, so dlang should provide super-easy syntax with inline `:` ?
3. `:` is not very visible, nor searchable. (OTOH, with a lot of a)
January 26, 2016
On Tuesday, 26 January 2016 at 07:05:53 UTC, xenon325 wrote:
> 3. `:` is not very visible, nor searchable. (OTOH, with a lot of a)

(has lost part of the message)

OTOH, with a lots of annotations `@namedParams` could be not very visible as well


January 28, 2016
On 01/26/2016 08:05 AM, xenon325 wrote:
>> Yes. Rule 7 covers that. There's also an example showing the syntax,
>> search for "Template specialization with named parameter". Yes, it
>> does look a bit strange.
>
> Just like C++98 used to require space

:: is not a token, so no space is required.

> between two `>` in templates ? ;)
> I see no way Walter would accept that.

https://issues.dlang.org/show_bug.cgi?id=6589
January 28, 2016
On Thursday, 28 January 2016 at 03:00:35 UTC, Timon Gehr wrote:
>> Just like C++98 used to require space
>
> :: is not a token, so no space is required.
>
>> between two `>` in templates ? ;)
>> I see no way Walter would accept that.
>
> https://issues.dlang.org/show_bug.cgi?id=6589

Hm, you are right. That was incorrect analogy.
May 27, 2016
On Sunday, 24 January 2016 at 02:51:43 UTC, Jonathan M Davis wrote:
> Regardless, I for one, hope that we never have named arguments.

Whooooops.

https://github.com/CyberShadow/ae/blob/master/utils/meta/args.d

:D
October 25, 2017
On Friday, 27 May 2016 at 18:26:07 UTC, Vladimir Panteleev wrote:
> https://github.com/CyberShadow/ae/blob/master/utils/meta/args.d
>
> :D

Nice work! Is it intentional to require default parameters? I think you can change lines 34-36:

>		foreach (i, arg; ParameterDefaults!fun)
> 			static if (i >= posArgs.length)
>				args[i] = ParameterDefaults!fun[i];

into

>		foreach (i, arg; ParameterDefaults!fun)
>			static if (i >= posArgs.length) {
>				static if (is(arg==void))
>					args[i] = Parameters!fun[i].init;
>				else
>					args[i] = arg;
>			}

That makes this work:

> import ae.utils.meta.args;
> 
> void fun(int one, int two, double three, string four)
> {
>     import std.stdio;
>     writeln("one=", one, "; two=", two, "; three=", three, "; four=", four);
> }
> 
> void main(string[] a)
> {
>     args!(fun, four=>"4", two=>2, one=>a.length, three=>3.0);
> }

By the way your unit tests don't really test that named arguments can be given in arbitrary order (although they can) as summation is communitative.

Bastiaan.
1 2 3 4 5
Next ›   Last »