Thread overview
proporty syntax dosn't work for static memebers (under some cases)
May 17, 2007
BCS
May 17, 2007
Frits van Bommel
May 17, 2007
BCS
May 24, 2007
BCS
May 17, 2007
struct S
{
	static void F(ref S* s){}
}

void main()
{
	S* s;
	s.F();	// fails
	s.F(s);	// works
}

This would be nice for some cases like where the struct has some extra data allocated on at the end and the function might have to reallocate.


May 17, 2007
BCS wrote:
> struct S
> {
>     static void F(ref S* s){}
> }
> 
> void main()
> {
>     S* s;
>     s.F();    // fails

Of course it fails. You forgot to specify an argument.

>     s.F(s);    // works

Correct, since you specified the argument this time.

> }
> 
> This would be nice for some cases like where the struct has some extra data allocated on at the end and the function might have to reallocate.

I'm not sure what you're trying to do here and what it has to do with property syntax.
However, you seem to think that calling a static method from an instance (or pointer) should pass what it's called on as a parameter? The only thing that works anything like that is arrays and functions that take them as the first parameter...

(Also, please note that what's more commonly referred to as "property syntax" in relation to D is leaving off the parameter brackets from a no-argument function or "assigning" something to a single-parameter function)
May 17, 2007
Reply to Frits,

> BCS wrote:
> 
>> struct S
>> {
>> static void F(ref S* s){}
>> }
>> void main()
>> {
>> S* s;
>> s.F();    // fails
>
> Of course it fails. You forgot to specify an argument.

Ok, I didn't /forget/, I was trying to use the array property syntax on a struct pointer. As you point out, it doesn't work in any case (their be my error).

> I'm not sure what you're trying to do here and what it has to do with
> property syntax.
> However, you seem to think that calling a static method from an
> instance
> (or pointer) should pass what it's called on as a parameter? The only
> thing that works anything like that is arrays and functions that take
> them as the first parameter...

I would consider the fact that this /only/ works with arrays a bug or missed feature.

this works:

struct S {}
void F(S[] s){}
void main()
{
	S[] s;
	s.F();
}

so why shouldn't this

struct S {}
void F(S s){}
void main()
{
	S s;
	s.F();
}

then the logical next step is what I was trying.


> (Also, please note that what's more commonly referred to as "property
> syntax" in relation to D is leaving off the parameter brackets from a
> no-argument function or "assigning" something to a single-parameter
> function)

Semantically there is little difference between the two, both allow a function to be used with some of the parameter list defined differently. It's not exactly the same, but I think the connection should be easy to see.


May 24, 2007
Reply to BCS,
> 
> this works:
> 
> struct S {}
> void F(S[] s){}
> void main()
> {
> S[] s;
> s.F();
> }
> so why shouldn't this
> 
> struct S {}
> void F(S s){}
> void main()
> {
> S s;
> s.F();
> }


Even C# is going to make this work!

http://feeds.haacked.com/~r/haacked/~3/119423736/ruby-like-syntax-in-c-3.0.aspx

I'd realy like to see this