www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - UFCS - why only allow the first parameter?

reply dennis luehring <dl.soluz gmx.net> writes:
func(a,b,c)

can be written as a.func(b,c)

is there a good reason

for not allwing

(a,b).func(c)

or even

(a,b,c).func()?

for me it feels natural
Feb 22 2013
next sibling parent Jonathan M Davis <jmdavisProg gmx.com> writes:
On Saturday, February 23, 2013 08:26:57 dennis luehring wrote:
 func(a,b,c)
 
 can be written as a.func(b,c)
 
 is there a good reason
 
 for not allwing
 
 (a,b).func(c)
 
 or even
 
 (a,b,c).func()?
 
 for me it feels natural
Because that's not what member functions look like. The whole point is to make calling the free function look as if it were a member function on the type of its first argument. In general, it shouldn't matter whether a function is a free function or a member function, it can be called the same way. That then makes the call syntax for functions "universal." What you seem to be suggesting is to basically make it so that you can put the parens of the function call on either side of the function name, and that's not at all what UFCS is trying to do, and it doesn't help one whit with generic code, which is the primary benefit of UFCS. - Jonathan M Davis
Feb 22 2013
prev sibling parent Timon Gehr <timon.gehr gmx.ch> writes:
On 02/23/2013 08:26 AM, dennis luehring wrote:
 func(a,b,c)

 can be written as a.func(b,c)

 is there a good reason

 for not allwing

 (a,b).func(c)

 or even

 (a,b,c).func()?

 for me it feels natural
Syntactically, because that is the comma operator. The following shows an arbitrary limitation: auto seq(T...)(T args){ return args; } void func(int a,int b,int c){ } void main(){ seq(1,2).func(3); } But the following works: struct Q(T...){ T q; } auto q(T...)(T q){ return Q!T(q); } void func(int a,int b,int c){ } void main(){ q(1,2).q.func(3); }
Feb 23 2013