Uniform call syntax for implicit this.

spir denis.spir at gmail.com
Thu Feb 3 13:05:01 PST 2011


On 02/03/2011 08:43 PM, Steven Schveighoffer wrote:
> The more I think about it (and read discussions like this), the more I think
> that uniform call syntax should only be allowed for types which cannot declare
> member functions (arrays, primitives, enums, etc.).  Otherwise, we introduce
> new ambiguities that serve little purpose except annoyance.

More precisely, it should work with all types in position of first parameter, 
but using implicit this like with member functions. This is ok:
     void f (C c, I i) {...}
     auto c = new C();
     I i;
     c.f(i);
Don't you think so?

The case of member functions using implicit this requires a double rewrite:
     f(i) --> this.f(i) --> f(this,i)
The second one corresponds to universal func call; but the first one is the 
automagic implicit this which, strictly speaking, should only work for members 
of the given type. f not beeing a member, the magic should not apply here. 
Note: if g is a member functon, then g(i) already works.
No ambiguity, no complication of the language, no headache for Walter et all, 
no unreadable code, no recurring issue on D-learn ;-)

> If I have a function foo(A) and A has a member foo(), then foo(myA) should call
> the free function, myA.foo() should call the member.  If this doesn't continue
> to be correct, we have taken a step backwards.

Agreed.

Denis
-- 
_________________
vita es estrany
spir.wikidot.com



More information about the Digitalmars-d mailing list