Re: As discussed in DConf2015: Python-like keyword arguments

2015-06-04 Thread ketmar via Digitalmars-d
here's the patch if someone want to play with it: http://ketmar.no-ip.org/dmd/namedargs000.patch git am -3 should apply it to HEAD without troubles. please note that this patch is in no way production ready, it's more a working PoC, with leftovers from earlier experiments. so code quality is

Re: As discussed in DConf2015: Python-like keyword arguments

2015-06-04 Thread ketmar via Digitalmars-d
On Sun, 31 May 2015 09:43:50 -0400, Michel Fortin wrote: 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

Re: As discussed in DConf2015: Python-like keyword arguments

2015-06-04 Thread Atila Neves via Digitalmars-d
Compile-time version for when crazy people like me pass in values as template parameters: import std.stdio; import std.array; import std.typetuple; import std.traits; struct Foo { int i; } struct Bar { int i; } struct Baz { int i; } void func(Foo foo = Foo(11), Bar bar = Bar(22), Baz baz =

Re: As discussed in DConf2015: Python-like keyword arguments

2015-06-04 Thread Atila Neves via Digitalmars-d
And if you add this, it gets even more interesting: void main() { alias myFunc = ctKwargify!func.wrap; myFunc!(Bar(2), Baz(3), Foo(1)); myFunc!(Baz(3), Foo(1)); } template ctKwargify(alias F) { template wrap(T...) { alias wrap = ctKwargs!(F, T); } } template

Re: As discussed in DConf2015: Python-like keyword arguments

2015-05-31 Thread ketmar via Digitalmars-d
On Sun, 31 May 2015 09:43:50 -0400, Michel Fortin wrote: 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! as for named calls argument order doesn't

Re: As discussed in DConf2015: Python-like keyword arguments

2015-05-31 Thread ketmar via Digitalmars-d
On Sun, 31 May 2015 11:56:47 +, Liran Zvibel wrote: Ketmar's work is very impressive (and I think it's better to have a nice syntax though the compiler), but since I've promised to work on it on the plane and actually did, I'm sending my implementation of a library function that

Re: As discussed in DConf2015: Python-like keyword arguments

2015-05-31 Thread Jacob Carlborg via Digitalmars-d
On 2015-05-31 03:59, Michel Fortin wrote: I didn't know you revived that thing too. Nice. Hehe, yeah. Not sure why I did that. I haven't even consider making it a pull request. Or what needs to be done to get it to that point. Make sure you take note of the related comments between Walter

Re: As discussed in DConf2015: Python-like keyword arguments

2015-05-31 Thread Idan Arye via Digitalmars-d
On Sunday, 31 May 2015 at 04:08:33 UTC, ketmar wrote: 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: , , d:Yehaw); } I like the idea of a template-variadic keyword arguments, but does

Re: As discussed in DConf2015: Python-like keyword arguments

2015-05-31 Thread Liran Zvibel via Digitalmars-d
On Friday, 29 May 2015 at 17:46:12 UTC, Liran Zvibel wrote: I think we should try to create a wrapper function taking the original function as (alias F) that leverages ParameterIdentifierTuple , ParameterTypeTuple and ParameterDefaultValueTuple to generate the namedArguments automatically.

Re: As discussed in DConf2015: Python-like keyword arguments

2015-05-31 Thread Michel Fortin via Digitalmars-d
On 2015-05-31 04:08:33 +, ketmar ket...@ketmar.no-ip.org said: my work now allows this: string test (string a, string b=3Dwow, string c=3Dheh) { return a~b~c; } void main () { enum str =3D test(c: cc, a: aa); assert(str =3D=3D aawowcc); } How does it handle

Re: As discussed in DConf2015: Python-like keyword arguments

2015-05-30 Thread Michel Fortin via Digitalmars-d
On 2015-05-29 12:27:02 +, Jacob Carlborg d...@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

Re: As discussed in DConf2015: Python-like keyword arguments

2015-05-30 Thread ketmar via Digitalmars-d
On Sat, 30 May 2015 21:59:53 -0400, Michel Fortin wrote: On 2015-05-29 12:27:02 +, Jacob Carlborg d...@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]

Re: As discussed in DConf2015: Python-like keyword arguments

2015-05-30 Thread ketmar via Digitalmars-d
ok, last sample now works too. ;-) signature.asc Description: PGP signature

Re: As discussed in DConf2015: Python-like keyword arguments

2015-05-29 Thread Michael Coulombe via Digitalmars-d
I know some people don't like abusing opDollar, but here's my implementation: import std.traits, std.algorithm, std.conv; private struct Named(string n, T) { enum name = n; T value; } private auto makeNameIndex(NamedList...)(string[] names) { auto indices = new

Re: As discussed in DConf2015: Python-like keyword arguments

2015-05-29 Thread Jacob Carlborg via Digitalmars-d
On 2015-05-29 00:35, Atila Neves wrote: I might do a blog post on this, but here's some POC code: import std.stdio; import std.range; import std.typetuple; import std.traits; import std.conv; struct Foo { int i; } struct Bar { int i; } struct Baz { int i; } void func(Foo foo, Bar bar, Baz

Re: As discussed in DConf2015: Python-like keyword arguments

2015-05-29 Thread Atila Neves via Digitalmars-d
On Thursday, 28 May 2015 at 22:35:14 UTC, Atila Neves wrote: I might do a blog post on this, but here's some POC code: Now with default values! import std.stdio; import std.range; import std.typetuple; import std.traits; import std.conv; struct Foo { int i; } struct Bar { int i; } struct

Re: As discussed in DConf2015: Python-like keyword arguments

2015-05-29 Thread Jonathan Crapuchettes via Digitalmars-d
Two other ways to implement the concept. The first works with optional arguments and the other requires all arguments. /** * Optional arguments and no default values; might not compile if all args * not passed. */ --- /**

Re: As discussed in DConf2015: Python-like keyword arguments

2015-05-29 Thread Liran Zvibel via Digitalmars-d
On Friday, 29 May 2015 at 15:16:56 UTC, Jonathan Crapuchettes wrote: Two other ways to implement the concept. The first works with optional arguments and the other requires all arguments. unittest { alias arg1 = namedArguments!(arg1, string); alias arg2 = namedArguments!(arg2, int);

Re: As discussed in DConf2015: Python-like keyword arguments

2015-05-29 Thread ketmar via Digitalmars-d
On Fri, 29 May 2015 14:27:02 +0200, Jacob Carlborg wrote: [2] https://github.com/jacob-carlborg/dmd/tree/named_parameters nice start. with some efforts i ported it as PoC to git HEAD, and added argument reordering, so void foo (string a, string b); ... foo(a:hello, b:world);

Re: As discussed in DConf2015: Python-like keyword arguments

2015-05-29 Thread ketmar via Digitalmars-d
On Fri, 29 May 2015 14:27:02 +0200, Jacob Carlborg wrote: i can do even more cool things like this now: void test (string a, string b=wow, string c=heh) { assert(b == wow); } test(c: cc, a: aa); the long-wanting feature of use defaults for some args. i like it. signature.asc

As discussed in DConf2015: Python-like keyword arguments

2015-05-28 Thread Atila Neves via Digitalmars-d
I might do a blog post on this, but here's some POC code: import std.stdio; import std.range; import std.typetuple; import std.traits; import std.conv; struct Foo { int i; } struct Bar { int i; } struct Baz { int i; } void func(Foo foo, Bar bar, Baz baz) { writeln(foo is , foo);