Library writing - delegates or fp's?

Carlos Santander csantander619 at gmail.com
Wed Jun 21 07:34:20 PDT 2006


Derek Parnell escribió:
> 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 thought the frame pointer would get lost and cause a segfault later on (see 
DFL events handling for an example.) Did that change with 0.161?

>> I suppose they should just call the delegate though.  I like it.  Thanks.
> 
> Yeah, I guess you could do that as well.
> 


-- 
Carlos Santander Bernal



More information about the Digitalmars-d-learn mailing list