Expanding the horizons of D purity

Timon Gehr timon.gehr at gmx.ch
Fri Nov 1 06:53:18 PDT 2013


On 11/01/2013 02:36 PM, Kenji Hara wrote:
> I think this is a good discovery. Currently a pure function can have
> lazy parameters and it is treated as a weakly pure function.
>
> pure int foo(lazy int x) { return x; }  // OK
>
> We can think the lazy parameter is a limited case of scope delegate
> parameter.
>...

They are. I think it would be quite strange to treat them differently.

> And more, I discovered that the purity may be stronger depends on the
> given delegate purity.
>
> void func(scope void delegate(int) dg) pure;
>
> void main() {
>      int num;
>
>      // the function call has weak purity
>      func((x){ num = x;});
>
>      // the function call has strong purity
>      func((x){ ; });
> }
>
> Kenji Hara
>

Yes. Furthermore, the first delegate should have inferred type 'void 
delegate(int x)pure nothrow @safe' and the second delegate should have 
inferred type 'void delegate(int x)pure immutable nothrow @safe'.


More information about the Digitalmars-d mailing list