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
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
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 =
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
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
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
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
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
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.
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
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
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]
ok, last sample now works too. ;-)
signature.asc
Description: PGP signature
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
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
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
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.
*/
---
/**
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);
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);
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
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);
21 matches
Mail list logo