Suggestion: "new delegate" - delegates useable outside of the nesting function scope

Walter Bright newshound at digitalmars.com
Fri Jun 2 17:34:19 PDT 2006


Burton Radons wrote:
> I use delegates a lot but the fact that they can only live until the end 
> of the nesting function scope means I need to use classes in many cases, 
> which is a lot more typing (and fluff telling the autodoc that it's not 
> part of the public API, and other problems) when it could be easily 
> fixed. The syntax change would be very simple:
> 
>     dispatcher.add (new delegate void (Event event) { ... });
> 
> And the effect would be simple as well: duplicate the calling context's 
> stack to the extent that the delegate can see it and use the duplicated 
> pointer as the "this" pointer; otherwise it's a regular nested delegate. 
> Five minutes work max, very topical changes, explicit allocation, big 
> benefits. Is good!

Unfortunately, it's quite a bit more work than that. You have to copy 
all the frames of the lexically enclosing functions, too. Then you have 
the issue of updates to the framed variable copies not being reflected 
in the stack variables. Then there's the problem of things like:

   int x;
   int* px = &x;




More information about the Digitalmars-d mailing list