We need to have a way to say "convert this nested function into a struct"
Jacob Carlborg via Digitalmars-d
digitalmars-d at puremagic.com
Sat Jun 6 06:44:50 PDT 2015
On 2015-06-06 08:59, Jonathan M Davis wrote:
> On Saturday, 6 June 2015 at 06:16:17 UTC, Andrei Alexandrescu wrote:
>> Nested functions that allocate their environment dynamically can be
>> quite useful. However, oftentimes the need is to convert the code plus
>> the data needed into an anonymous struct that copies the state inside,
>> similar to C++ lambdas that capture by value.
>>
>> I wonder how to integrate that within the language nicely.
>
> Some of us were discussing this at dconf. Essentially, we need a way to
> create a functor similar to how C++ lambdas do. The most straightforward
> way would involve string mixins, and you'd do something like
>
> auto f = makeFunctor!"function code here"(arguments);
Which could look like this with AST macros ;)
auto f = makeFunctor(args) {
function code goes here, no strings are needed
}
--
/Jacob Carlborg
More information about the Digitalmars-d
mailing list