How to break const
Don Clugston
dac at nospam.com
Wed Jun 20 02:06:22 PDT 2012
On 19/06/12 11:02, Iain Buclaw wrote:
> On 19 June 2012 09:18, Don Clugston<dac at nospam.com> wrote:
>> So would I. Can you think of one?
>> It was the best name I could come up with, given that the 'pure' was the
>> keyword.
>> We want a word that means 'no hidden state'.
>
> I thought that was what pure was for. :~)
This page is interesting.
http://en.wikipedia.org/wiki/Pure_function
There's never any hidden state, even in a weakly pure function.
So it satisfies rule 1.
A weakly pure function may modify anything it can reach through the
parameters, though. Does this violate rule 2?
I guess that if you define all mutable arguments of a weakly pure
function as being 'pass by reference', then even 'weakly pure' is pure
according to that definition.
The page states that according to that definition, the expressions which
call the pure function are not pure.
But again in the terms of that page, D has an "Effect System" which
allow us to prove that a function is pure even though it has impure
expressions in it.
Wikipedia isn't very authoritative though.
So I don't know -- although D 'pure' is very different to what FP people
call 'pure', I'm no longer certain that we're abusing the term.
After all, even this function isn't pure in the traditional FP view:
int foo(int n) pure
{
int r = n*n;
r += n;
return r;
}
More information about the Digitalmars-d
mailing list