Proposal: Relax rules for 'pure'

Michel Fortin michel.fortin at michelf.com
Wed Sep 22 04:54:26 PDT 2010


On 2010-09-22 01:26:01 -0400, "Robert Jacques" <sandford at jhu.edu> said:

> So removing the concurrency safety from pure would greatly  expand the 
> number of pure functions, however, automatic parallelism would  be lost.

Don clearly mentioned that this is not lost. Basically, for safe 
parallelism what you need is a function that has a) pure and b) no 
mutable reference parameter. Both are easily checkable at compile time, 
you'd just need to change your test for pure for a test that also 
checks the arguments.

The interesting thing with this change is that you can now call 
mutators functions on the local variables inside the pure function, 
because those can be made pure. You can't even iterate over a range 
inside a pure function without this!

	pure int test() {
		int result;
		auto r = iota(0, 10);
		while (!r.empty) {
			result += r;
			r.popFront(); // can't be pure by current rules!
		}
		return result;
	}

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



More information about the Digitalmars-d mailing list