Attributes
Alaric B. Williams
alaric@abwillms.demon.co.uk
Mon, 15 Sep 1997 21:16:01 +0000
> To confirm my understanding of purity, a function is pure if it only
> performs actions necessary to its purpose. For example if a function is to
> calculate a result, it doesn't also create a persistent variable somewhere
> that remains when the function exits.
Hmmm... I think that skirts the crucial point somewhat. Purity is
sometimes the topic of flamewars, but the general idea is that this
is not a pure function:
int LastSum = 0;
int running_sum(int x) {
return (LastSum += x);
}
since it matters what order the calls occur in:
running_sum(1) => 1
running_sum(10) => 11
but
running_sum(10) => 10
running_sum(1) => 11
IE, with impure functions, you have to be careful what is called
where. Impure functions compute [some aspect of] their return value
from a mutable value that is not local to the function - for example,
this function is really pure, although it does dirty stuff inside, it
hides that away:
int sum(int x,int y) {
int temp = 0;
temp += x;
temp += y;
return temp;
}
I know that's what you're getting at, but you said it in a very
strange way IMHO :-)
> You seem to be speaking of Attributes as the same thing as Annotations. Is
> it true that you use the two terms synonymously in all cases?
I'd say that annotation is a subset of attribute... annotation is
one particular function.
> David E. Manifold
> dem@pacificrim.net
ABW
--
Alaric B. Williams Internet : alaric@abwillms.demon.co.uk
http://www.abwillms.demon.co.uk/