Thread overview
UFCS for classes with opCall( ... )
Jun 01, 2013
ParticlePeter
Jun 02, 2013
Ali Çehreli
Jun 02, 2013
ParticlePeter
Jun 02, 2013
Timon Gehr
Jun 03, 2013
ParticlePeter
Jun 03, 2013
Timon Gehr
Jun 05, 2013
ParticlePeter
Jun 05, 2013
Timon Gehr
June 01, 2013
Hello,

after watching Walters Talk about Component Programming ( link Bellow ) I was quite fond of his pipelining approach.
I tried the following and had to realize that this way using UFCS isn't working ( or I do something wrong ).

// I want to write On Canvas1 | draw Shape1 | draw Shape2 | ... in code ( not working ):
canvas1.shape1.shape2.draw()

// Which in essence would be ( working ):
shape2( shape1( canvas1 ) ).draw()

// With these Classes

class Canvas  {
public:
	drawTarget()  {
		// activate as Draw Target
	}
}

class Shape  {
public:
	Shape opCall( Canvas canvas ) {
		canvas.drawTarget() ;
		return this ;
	}

	Shape opCall( Shape otherShape ) {
		otherShape.draw()
		return this ;
	}

	void draw() {
		// Draw yourself Draw calls
	}
}

FYI: Its OpenGL stuff, Canvas would be the Frambuffer or FBOs, and Shape abstrcted draw calls. I have some more building blocks which would nicely fit into this pipelining.

1. Is there any way that I could make my wish syntax work with D's current features ?
2. Is there a reason that this does not work with UFCS, besides "not implemented yet" ?
3. If not 1. Would this be a valid feature requst ?

Thanks for any insights,

Cheers, ParticlePeter !


Walters Talk:
https://www.youtube.com/watch?v=cQkBOCo8UrE
June 02, 2013
On 06/01/2013 05:22 AM, ParticlePeter wrote:

> 3. If not 1. Would this be a valid feature requst ?

Looks like this request:

  http://d.puremagic.com/issues/show_bug.cgi?id=9857

Ali

June 02, 2013
On Sunday, 2 June 2013 at 06:07:25 UTC, Ali Çehreli wrote:
> On 06/01/2013 05:22 AM, ParticlePeter wrote:
>
> > 3. If not 1. Would this be a valid feature requst ?
>
> Looks like this request:
>
>   http://d.puremagic.com/issues/show_bug.cgi?id=9857
>
> Ali

Uuups, how could I have missed that when searching dlang for UFCS ? Sorry, dear Forum, and thanks, Ali, pointing out.
I read through the follow up discussion: http://forum.dlang.org/thread/mxsipaadpufujicmerjn@forum.dlang.org?page=1

Unfortunatelly Walter didn't comment till now, which would be interestingm, regarding his Component Programming talk.

June 02, 2013
On 06/01/2013 02:22 PM, ParticlePeter wrote:
> Hello,
>
> after watching Walters Talk about Component Programming ( link Bellow )
> I was quite fond of his pipelining approach.
> I tried the following and had to realize that this way using UFCS isn't
> working ( or I do something wrong ).
>
> // I want to write On Canvas1 | draw Shape1 | draw Shape2 | ... in code
> ( not working ):
> canvas1.shape1.shape2.draw()
>
> // Which in essence would be ( working ):
> shape2( shape1( canvas1 ) ).draw()
> ...

UFCS is working with opCall already.

The reason your code does not work is that UFCS only works with module-level symbols (and with the latest release also for locally imported symbols IIRC.)


June 03, 2013
> UFCS is working with opCall already.
>
> The reason your code does not work is that UFCS only works with module-level symbols (and with the latest release also for locally imported symbols IIRC.)

What do you mean with locally import symbols, isn't that the normal import statement ? Could you show me a working example ?

Thx.
June 03, 2013
On 06/03/2013 06:25 PM, ParticlePeter wrote:
>
>> UFCS is working with opCall already.
>>
>> The reason your code does not work is that UFCS only works with
>> module-level symbols (and with the latest release also for locally
>> imported symbols IIRC.)
>
> What do you mean with locally import symbols, isn't that the normal
> import statement ? Could you show me a working example ?
>
> Thx.

http://dpaste.dzfl.pl/79c29c19

(What you want to do does not work, but the issue is not that UFCS does not work with opCall. It does.)
June 05, 2013
> http://dpaste.dzfl.pl/79c29c19
>
> (What you want to do does not work, but the issue is not that UFCS does not work with opCall. It does.)

Thanks for the insights, undfortunatelly you're right. Is this behaviour on purpose, or considered a bug ?
Couldn't read that much out of the original discussion.
June 05, 2013
On 06/05/2013 05:11 PM, ParticlePeter wrote:
>
>> http://dpaste.dzfl.pl/79c29c19
>>
>> (What you want to do does not work, but the issue is not that UFCS
>> does not work with opCall. It does.)
>
> Thanks for the insights, undfortunatelly you're right. Is this behaviour
> on purpose, or considered a bug ?
> Couldn't read that much out of the original discussion.

It is on purpose.