Opt-out closures

Sean Eskapp eatingstaples at gmail.com
Sun Jan 23 06:50:25 PST 2011


== Quote from Jonathan M Davis (jmdavisProg at gmx.com)'s article
> 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

I want to be able to access the enclosing scope, but NOT after the function has
exited; I should have the option of accessing the enclosing scope, but at the cost
of making my delegate not a closure.


More information about the Digitalmars-d mailing list