Dream Feature Regarding Default Arguments
Colden Cullen
ColdenCullen at gmail.com
Mon Apr 7 14:41:09 PDT 2014
On Monday, 7 April 2014 at 20:00:39 UTC, Meta wrote:
> On Monday, 7 April 2014 at 19:47:24 UTC, Frustrated wrote:
>> it would be relatively easy.
>>
>> void myfunc(name = int x) { }
>>
>> instead of
>>
>> void myfunc(int x) { }
>>
>> then
>>
>> myfunc(name = 4);
>>
>> or one could simply use the variable name
>>
>> void myfunc(int x) { }
>>
>> myfunc(x = 3);
>>
>>
>> Of course assignments may not be valid, one could use :=
>> instead.
>>
>> myfunc(x := 3);
>>
>>
>>
>> One could build a template to do it how were but it would
>> require calling the function as a string,
>>
>> e.g., template is passed the call as a string. The template
>> gets the name of the function, looks up the parameter names,
>> parses the arguments and generates the proper call string
>> which is then mixed in.
>>
>> e.g., Named(q{myfunc(x := 3)}); => myfunc(3);
>
> C# uses <name>:, like the follow.
>
> void TestFun(int i, string s = "", bool b)
> {
> //...
> }
>
> TestFun(i: 1, b: false);
>
> Is there any reason not to use this syntax? It doesn't *seem*
> to conflict with anything else.
I like this a lot more. It looks similar to the associative array
literal syntax, which is fitting.
More information about the Digitalmars-d
mailing list