As discussed in DConf2015: Python-like keyword arguments
ketmar via Digitalmars-d
digitalmars-d at puremagic.com
Sat May 30 21:08:33 PDT 2015
On Sat, 30 May 2015 21:59:53 -0400, Michel Fortin wrote:
> On 2015-05-29 12:27:02 +0000, Jacob Carlborg <doob at me.com> said:
>
>> And here's an implementation with language support which allows named
>> arguments but not reordering the arguments [2]. Originally implemented
>> by Michel Fortin.
>>
>> [2] https://github.com/jacob-carlborg/dmd/tree/named_parameters
>
> I didn't know you revived that thing too. Nice.
>
> Make sure you take note of the related comments between Walter and me
> here:
> https://github.com/michelf/dmd/
commit/673bae4982ff18a3d216bc1578f50d40f4d26d7a
>
> At some point my plans about this changed and I wanted to implement
> named arguments differently so it'd work for template arguments too.
> But I never go to it.
my work now allows this:
string test (string a, string b="wow", string c="heh") {
return a~b~c;
}
void main () {
enum str = test(c: "cc", a: "aa");
assert(str == "aawowcc");
}
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");
}
but still not this:
string test(T) (T a, string b="wow", string c="heh") {
import std.conv : to;
return to!string(a)~b~c;
}
void main () {
enum str = test(c: "cc", a: 42); // can't
//enum str = test(a: 42, c: "cc"); // WORKS
assert(str == "42wowcc");
}
i have to add reorder checks to template resoultion code yet.
also, no support for named "!" args.
the patch is fairly simple and almost non-intrusive (one big function in
mtype.c and processing of NamedArgExp at different visitors). .di
generation is supported too.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: not available
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20150531/71322cb8/attachment.sig>
More information about the Digitalmars-d
mailing list