UFCS idea
Alex_Dovhal
alex_dovhal at yahoo.com
Wed Jun 8 12:41:15 PDT 2011
There have been several topics discussing UFCS recently. So here is one
more)
One idea about UFCS - mark UFCS argument with @, @_, or _ symbol,
e.g. you have some function:
void func(Type1 p1, Type2 p2);
and later call it:
fucn(a, b); //or
a.func(@_, b); //or
b.func(a, @_);
This way Timon Gehr's example:
take(10,stride(2,cycle([3,2,5,3])));
[3,2,5,3].cycle().stride(2).take(10);
would be written as this:
[3,2,5,3].cycle(@_).stride(2, @_).take(10, @_);
Which is a little longer. On the other side this way benefits from:
* UFCS is directly seen by both the programmer and compiler;
* UFCS doesn't mix with member call syntax;
* UFCS can be used for any type and for any argument, e.g.
a.func(@, b) or b.func(a, @);
* UFCS can be used for more than one argument: a.func(@_, @_~[1]);
What do you think?
More information about the Digitalmars-d
mailing list