however on a different note, going back to your suggestion, actually:
void foo(string firstname="", string initial="", string lastname="");
is not needed at all to get named parameters, they are already named: you really only need this:
void foo(string firstname, string initial, string lastname); foo(firstname = "David", lastname = "Hedbor")
as a generally acceptable syntax to assign the values. i don't see a need to define the variables in a different way to make assigning them like this work.
Well, I used = "" only to illustrate the use of default values as well. It is not needed but I do think either that or 'void|' would be needed. Otherwise you could sudddenly call methods in incorrect ways.
void foo(string firstname="", string initial="", string lastname=""); would still be usefull, but for a different unrelated purpose, namely asigning default values, which was discussed in another thread.
Of course. But I don't think
foo(string a, string b) should be enoug to use foo(b="value") but rather at least foo(string|void a, string b) or foo(string a ="", string b);
That said the:
ret = foo(var=value) syntax is probably not optimal. Rather a new construct would have to be used (and yes, it pretty much does look like a mapping without the ([ ]))., such as foo(var: value, var2: value)
/ David Hedbor
Previous text:
2003-03-07 01:46: Subject: Re: syntax dreams (was: negative indices in array ranges)
On Fri, Mar 07, 2003 at 01:35:02AM +0100, David Hedbor @ Pike developers forum wrote:
Using a mapping with some construct that enforces entry names might work but I don't see the benefit.
the benefit would be that this type checking would be usefull in other situations too.
what I like about named parameters is that you keep the simplicity (in the method) of normal parameters - there's no difference.
well the difference is that they are named, vs. unnamed.
however on a different note, going back to your suggestion, actually:
void foo(string firstname="", string initial="", string lastname="");
is not needed at all to get named parameters, they are already named: you really only need this:
void foo(string firstname, string initial, string lastname); foo(firstname = "David", lastname = "Hedbor")
as a generally acceptable syntax to assign the values. i don't see a need to define the variables in a different way to make assigning them like this work.
void foo(string firstname="", string initial="", string lastname=""); would still be usefull, but for a different unrelated purpose, namely asigning default values, which was discussed in another thread.
greetings, martin.
/ Brevbäraren