Do pure functions solve the "return const" problems?
guslay
guslay at gmail.com
Wed Apr 2 14:28:04 PDT 2008
Steven Schveighoffer Wrote:
> "Janice Caron" wrote
> >
> > Pure functions also happen to be thread-safe, but not all thread-safe
> > functions are pure.
>
> That was my impression too, but read Bill's post closely. What he is saying
> is that pure functions do not need invariant parameters, which means they
> are subject to thread issues.
>
> If pure functions are not required to take invariant parameters, then they
> cannot be guaranteed to be thread safe.
>
> -Steve
>
Just to complement:
If f is pure, and a is invariant. f(a)+f(a) is equivalent to 2 * f(a).
If a is not invariant, a can be modified by f(). However, that is not a side effect: a is considered as an output of f(). f can still called be pure.
There is a dependency between the two f(a) that prevents reordering or caching or threading
first call : f(a) produces a1.
second call : f(a1) produces a2.
The thing with pure function is that just by looking at the nature of the parameters, you know how coupled they are.
More information about the Digitalmars-d
mailing list