[Issue 17645] `pure` is transitively applied to all delegates inside a pure function

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Sat Jul 15 13:39:29 PDT 2017


https://issues.dlang.org/show_bug.cgi?id=17645

--- Comment #3 from Tomer Filiba (weka) <tomer at weka.io> ---
(In reply to Steven Schveighoffer from comment #1)
> Do you have a better use case? 

the use case may sound odd, but it's surprisingly common. suppose you have

struct Foo {
    private int x;
    @property int someTrivialProperty() const pure @nogc {
        assert(x > 8, "oh no x=%s".format(x));
        return x;
    }
}

`format` does GC and isn't pure. the property itself is perfectly pure and
@nogc and whatnot, but by adding an assert i have to remove these attributes
from it. so we have ASSERT which hides away the impurity and GC-ness, since it
it blows up we really don't care about the GC or purity.

ASSERT!"oh no x=%s"(x > 8, x);

we practically use it everywhere.

> i.e. you don't need access to the pure function's stack frame, so you can
> have a function instead of a delegate.

maybe, but it means i can't write it in the same statement, i.e. this won't
work

    assumePure({x++});

and i'll have to use 

    void function() fn = {x++};
    assumePure(x);

which defeats the purpose of easy-to-spell-out lambdas

--


More information about the Digitalmars-d-bugs mailing list