Library writing - delegates or fp's?
Derek Parnell
derek at nomail.afraid.org
Tue Jun 20 23:21:55 PDT 2006
On Wed, 21 Jun 2006 02:12:54 -0400, Chad J wrote:
> Pretty nice, but then I can't do something like this:
...
> writefln( increment(1) );
> writefln( incr(2) );
...
> I'm thinking incase someone wanted to say, have a mouse handling
> function be triggered by the GUI's delegate and also have it
> artificially triggered by some other code via a direct function call
> (maybe a tutorial, debug routine, or something like that).
Sure you can! How about this ...
import std.stdio;
int delegate(int) increment;
void main()
{
writefln( increment(1) );
writefln( incr(2) );
}
int incr( int a )
{
return a + 1;
}
static this()
{
increment = delegate int ( int a ) {return incr(a); };
}
Would that do?
> I suppose they should just call the delegate though. I like it. Thanks.
Yeah, I guess you could do that as well.
--
Derek
(skype: derek.j.parnell)
Melbourne, Australia
"Down with mediocrity!"
21/06/2006 4:20:09 PM
More information about the Digitalmars-d-learn
mailing list