blocks with attributes vs inlined lambda
Timon Gehr
timon.gehr at gmx.ch
Sun Jun 30 13:29:07 PDT 2013
On 06/18/2013 09:57 AM, Kenji Hara wrote:
>
> # Purity
> Because a lambda needs to access the frame, any function using the
> lambda trick can't be made pure:
> void foo(T)(T a) @safe
> {
> (){
> ++a;
> }();
> }
> Error: pure function 'main.foo' cannot call impure function literal
> '__lambda1'
>
> The workaround is to explicitly pass the arguments, *preferably*,
> shadowing them for clarity:
> void foo(int a) pure
> {
> (ref int a){
> ++a;
> }(a);
> }
> This is already *much* less convenient. Imagine if the block needed
> to access 3, 5 or even more variabes ! Also, if one of those
> variables is declared as "auto", then you bring in the "ref
> typeof(a) a" ugliness. Just no.
>
>
> This is a compiler bug, and I recently fixed it in git master. Explicit
> argument passing does not need anymore.
Great. Does the fix also introduce the 'immutable' storage class for
function literals for the case where a strongly pure literal is wanted?
More information about the Digitalmars-d
mailing list