Just curious: who do know current purity rules?

Denis Shelomovskij via Digitalmars-d digitalmars-d at puremagic.com
Fri Jun 6 01:45:16 PDT 2014


As Kenji Hara just created purity fixing pull [1] we will probably soon 
have more intuitive rules so it's interesting who do understand current 
purity rules. The following code is proposed to check your understanding:
---
alias F = bool function(int) pure;
alias D = bool delegate(int) pure;

D foo1(immutable F  f) pure { return x => (*f)(x); } // ok or error?
D foo2(    const F  f) pure { return x => (*f)(x); } // ok or error?
D foo1(immutable F* f) pure { return x => (*f)(x); } // ok or error?
D foo2(    const F* f) pure { return x => (*f)(x); } // ok or error?
---

Who passes this test? By "pass" I mean completely understand what the 
compiler do and why.

By the way, personally I would fail the test. )


[1] [spoiler!] https://github.com/D-Programming-Language/dmd/pull/3626

-- 
Денис В. Шеломовский
Denis V. Shelomovskij


More information about the Digitalmars-d mailing list