UFCS idea

Dmitry Olshansky dmitry.olsh at gmail.com
Wed Jun 8 13:22:30 PDT 2011


On 08.06.2011 23:41, Alex_Dovhal wrote:
> 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?
>
>

what was so bad about having 'this' inside parameters?
I thought it was rather compelling:

void func(Type1 this, Type2 p2);
which is legal only as a free function and inside structs/classes it's declaration syntax error.

[3,2,5,3].cycle.stride(2).take(10); //and no snails :)



-- 
Dmitry Olshansky



More information about the Digitalmars-d mailing list