On Thu, 03 Feb 2011 13:42:30 -0500, Jonathan M Davis <jmdavisp...@gmx.com> wrote:

On Thursday, February 03, 2011 09:54:44 Michel Fortin wrote:
On 2011-02-03 12:43:12 -0500, Daniel Gibson <metalcae...@gmail.com> said:
> Am 03.02.2011 15:57, schrieb Michel Fortin:
>> On 2011-02-02 23:48:15 -0500, %u <dfl...@sgjds.com> said:
>>> When implemented, will uniform call syntax work for the "this"
>>> object even if not specified?
>>>
>>> For example, will foo() get called in the following example?
>>>
>>> void foo(A a, int b) {}
>>>
>>> class A {
>>> void test() {
>>> this.foo(10);
>>> foo(10);
>>> }
>>> }
>>
>> I think it should work.
>
> I think foo(10) should *not* be equivalent to foo(this, 10).

Personally, I'm not sure whether the uniform call syntax will be this
much useful or not, but if it gets implemented I think foo(10) should
be equivalent to foo(this, 10) in the case above. That said, it should
not be ambiguous: if there is a member function foo and a global
function foo and both matches the call, it's ambiguous and it should be
an error.

Can this work in practice? We probably won't know until we have an
implementation to play with.

Except that if you have both a member function foo and a free function foo, how
can you tell the compiler which to use?

*sigh* The same way you do it today, but using the outer-scope operator '.'. So foo(10) would call the member function, while .foo(10) would call the outer function, which would be re-written as .foo(this,10).

An example of this today in D:
import std.conv;
class Foo {
    string text;
    string toString() {return .text("My text is: "text);}
}

Reply via email to