Value closures (no GC allocation)

Adam D. Ruppe via Digitalmars-d digitalmars-d at puremagic.com
Wed May 24 20:10:04 PDT 2017


On Wednesday, 24 May 2017 at 20:15:37 UTC, Vittorio Romeo wrote:
> If you're interested in contributing, please let me know and 
> I'll add you as a collaborator.

can i just edit it on the site?

but a few comments:

"Currently FunctionLiterals that capture their outer context 
(i.e. closures/delegates) require an allocation and the garbage 
collector. "


Not necessarily true, make sure you actually mention `scope 
delegate` and `alias` params that do not return it. Those capture 
but do not allocate.


"We will be proposing a syntax redundant w.r.t. current behavior 
(i.e. capture by reference), so maybe we should consider 
proposing deprecation?"

Don't do that.

"    // or simply, using existing syntax:
     //auto l = () => writeln("hello!");"

That existing one will actually make a function, not a delegate, 
since it doesn't access any locals.

"    struct anonymous_l"

That should be `static struct`.

"Capture by reference"

I'm against that, no need adding it and it complicates the whole 
thing. For example, "ref int _i;" as a struct member; there's no 
such thing in D. (the compiler could do it but still). And you'd 
have to explain the lifetime. Just no point doing this, the 
current behavior is completely fine for this.


More information about the Digitalmars-d mailing list