Opt-out closures

Jonathan M Davis jmdavisProg at gmx.com
Sun Jan 23 06:39:16 PST 2011


On Sunday 23 January 2011 06:36:27 Sean Eskapp wrote:
> I get errors when working with nested functions and structs or scoped
> classes, because closures can't be used with anything with scoped
> destruction. This makes complete sense, but I don't even want the closure
> functionality of these nested functions. Personally, I would like to be
> able to opt-out of the closure functionality of nested functions: if the
> enclosing function exits, and a nested function thereof is called, then a
> segfault would occur when it tried to access the stack of its enclosing
> function; however, access of scoped-destruction variables from an
> enclosing-scope function would be fine.
> 
> Thoughts? The not-being-able-to-access-scoped-destruction-variables thing
> is really getting to me, since one of the main driving features I like
> about D is the ability to use anonymous and nested functions.

If a nested function is marked as static, then it results in a function rather 
than a delegate. Of course, that means that you can't access the enclosing 
scope, but if you don't care about that, then just use static.

- Jonathan M Davis


More information about the Digitalmars-d mailing list