www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - OpIn

reply "dominik" <aha aha.com> writes:
I can't seem to find any docs about this, and I'm too thick to understand 
it.

for example:

use(context) in (GL gl) {    draw(gl);}what the hell is this? How does it 
work? Why would one wan't it? etc...Explain it to me like I'm a retard, 
because I am. As far as I understand, "context" in this case is a delegate, 
which has gl as "in" and.. now what?thanks 
Feb 04 2008
parent reply downs <default_357-line yahoo.de> writes:
dominik wrote:
 I can't seem to find any docs about this, and I'm too thick to understand 
 it.
 
 for example:
 
 use(context) in (GL gl) {    draw(gl);}what the hell is this? How does it 
 work? Why would one wan't it? etc...Explain it to me like I'm a retard, 
 because I am. As far as I understand, "context" in this case is a delegate, 
 which has gl as "in" and.. now what?thanks 
 
 

use is presumably a function that returns a temporary struct. The temporary struct defines opIn. The (GL gl) { } is a delegate literal that takes a GL parameter. So this code calls the temporary struct's opIn with a (void?) delegate(GL). Hope it helps. --downs
Feb 05 2008
parent reply dominik <dominik |VGA|.hr> writes:
On Tue, 05 Feb 2008 13:23:24 +0100, downs wrote:
 use is presumably a function that returns a temporary struct.
 
 The temporary struct defines opIn.
 
 The (GL gl) { } is a delegate literal that takes a GL parameter.
 
 So this code calls the temporary struct's opIn with a (void?)
 delegate(GL).

so basically all of this "in" and delegate literal is something like a fancy callback?
Feb 05 2008
parent downs <default_357-line yahoo.de> writes:
dominik wrote:
 On Tue, 05 Feb 2008 13:23:24 +0100, downs wrote:
 use is presumably a function that returns a temporary struct.

 The temporary struct defines opIn.

 The (GL gl) { } is a delegate literal that takes a GL parameter.

 So this code calls the temporary struct's opIn with a (void?)
 delegate(GL).

so basically all of this "in" and delegate literal is something like a fancy callback?

I love D, among other things, for its ability to easily declare and pass around small snippets of behavior, i.e. delegate literals :) --downs
Feb 05 2008