Proposal: Relax rules for 'pure'

Michel Fortin michel.fortin at michelf.com
Wed Sep 22 04:44:51 PDT 2010


On 2010-09-21 22:21:39 -0400, Don <nospam at nospam.com> said:

> PROPOSAL:
> Drop the first requirement. Only one requirement is necessary:
> 
> A pure function does not read or write any global mutable state.
> 
> If a pure function has parameters that are all immutable or are 
> implicitly convertible to immutable, then the compiler is permitted to 
> cache the results.

This is what I was advocating a long time ago when pure came out.

The current rule prevent you from doing any serious work from inside a 
pure function. Inside a pure function you can only call a pure 
function, you can't even call functions that take mutable references to 
local variables. This makes it impossible to use generic algorithms, 
such as sort, to manipulate local mutable data, even when those 
algorithms have no need for a global state.

So I certainly support this change.

-- 
Michel Fortin
michel.fortin at michelf.com
http://michelf.com/



More information about the Digitalmars-d mailing list