As discussed in DConf2015: Python-like keyword arguments
Michel Fortin via Digitalmars-d
digitalmars-d at puremagic.com
Sun May 31 06:43:50 PDT 2015
On 2015-05-31 04:08:33 +0000, ketmar <ketmar at ketmar.no-ip.org> said:
> my work now allows this:
> string test (string a, string b=3D"wow", string c=3D"heh") {
> return a~b~c;
> }
>
> void main () {
> enum str =3D test(c: "cc", a: "aa");
> assert(str =3D=3D "aawowcc");
> }
How does it handle overloading?
string test(bool a, string b="wow", string c="heh") {}
string test(bool a, string c="heh", bool d=true) {}
test(a: true, c: "hi"); // ambiguous!
The irony of this example is that without argument names (or more
precisely without reordering), there'd be no ambiguity here.
> and this:
> void test(A...) (A a) {
> import std.stdio;
> foreach (auto t; a) writeln(t);
> }
>
> void main () {
> test(x: 33.3, z: 44.4, a: 9999, 7777, d:"Yehaw");
> }
For that to be really useful the argument names should be part of the
"A" type so you can forward them to another function and it still
works. For instance:
void test(string a, string b="wow", string c="heh") {}
void forward(A...)(A a) {
test(a);
}
void main() {
forward(c: "cc", a: "aa");
}
--
Michel Fortin
michel.fortin at michelf.ca
http://michelf.ca
More information about the Digitalmars-d
mailing list