Pretty please: Named arguments
Steven Schveighoffer
schveiguy at yahoo.com
Mon Feb 28 05:23:18 PST 2011
On Mon, 28 Feb 2011 08:15:02 -0500, Andrej Mitrovic
<andrej.mitrovich at gmail.com> wrote:
> On 2/28/11, Steven Schveighoffer <schveiguy at yahoo.com> wrote:
>> This syntax already means something in D:
>>
>> string action;
>> int times;
>> foo(action = "dofoo", times = 100); // set action to "dofoo" and times
>> to
>> 100 and pass those to the function.
>>
>> -Steve
>>
>
> Except that doesn't do what you'd expect it to do:
> void foo(ref int time) { }
> void main()
> {
> int times;
> foo(times = 100); // set times to 100 and pass to the function.
> }
When I said "pass those" I meant "pass those values". I was not assuming
ref arguments.
In any case, your syntax for named arguments is not possible. x = y is an
expression, and can be used anywhere an expression can be used.
-Steve
More information about the Digitalmars-d
mailing list