[Issue 2832] pure function too pure

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Oct 13 06:06:15 PDT 2009


http://d.puremagic.com/issues/show_bug.cgi?id=2832



--- Comment #3 from Don <clugdbug at yahoo.com.au> 2009-10-13 06:06:14 PDT ---
(In reply to comment #2)
> Instead of introducing another inconsistency into the language for the
> not-so-common case, you could take the opposite route:
> 
> pure int fun(int d, int divisor)
> {
>    immutable c = d;
>    int gun() pure { return c + 1; }
> 
>    return gun() + d / divisor;
> }

I think the existing behaviour -- that you cannot change any of the parameters
in a pure function -- is simple and intuitive: pure functions can only modify
variables which they created themselves. A rule that pure nested functions can
use indirectly-referenced data, but cannot use parameters which are passed by
value, just seems complicated. 
Especially, in the case where a parameter contains a reference to other data,
it seems folly to be allowed to change part of the parameter, but not all of
it.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list