Library writing - delegates or fp's?
Chad J
gamerChad at _spamIsBad_gmail.com
Tue Jun 20 23:58:22 PDT 2006
Derek Parnell wrote:
>
>>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?
>
Indeed. That kicks ass.
I still have to completely wrap my head around that function literal
syntax. All of the sudden it is very useful to me. :)
More information about the Digitalmars-d-learn
mailing list