Pretty please: Named arguments

Nick Sabalausky a at a.a
Mon Feb 28 19:42:50 PST 2011


"Bekenn" <leaveme at alone.com> wrote in message 
news:ikgs96$9in$3 at digitalmars.com...
> On 2/28/11 5:05 AM, Jacob Carlborg wrote:
>> It's possible to implement this as a library:
>> http://dsource.org/projects/orange/browser/orange/util/Reflection.d#L135
>>
>> Not a complete solution but it works.
>>
>
> That has scary syntax; no thanks.

It is a pretty gnarly syntax. And it doesn't support return values, and the 
arg values are mixed into the wrong context. But it's a hell of a lot better 
than nothing: calling certain functions without using named arguments scares 
the shit out of me. I think I'll probably use it (or something like it) on 
funcs that really need it.

One thing that could help is if it was modified slightly to work like this:

----------------------
int foo(int a, int b) {...}

// We need better string-mixin syntax!!!!
auto x = mixin( namedArgs(q{ foo(a=10,b=27) }) );
// Turns into -->
auto x = foo(10,27);
----------------------

If we could ever manage to get string-producing CTFEs that are implicitly 
mixed-in, which we desparately need anyway, then that would be:

----------------------
auto x = namedArgs(q{ foo(a=10,b=27) });
----------------------

Which I think would be a perfectly acceptable stop-gap solution until we can 
get *real* named arguments.




More information about the Digitalmars-d mailing list