Most basic nothrow, pure, @safe functions?

monarch_dodra monarchdodra at gmail.com
Fri Mar 21 00:59:32 PDT 2014


On Friday, 21 March 2014 at 07:14:47 UTC, Walter Bright wrote:
> On 3/21/2014 12:03 AM, monarch_dodra wrote:
>> On Friday, 21 March 2014 at 03:04:36 UTC, Steven Schveighoffer 
>> wrote:
>>> Thinking about it some more, I see what you mean -- an 
>>> unshared mutex is useless.
>>>
>>> But at the same time, some "logically" pure functions cannot 
>>> be so without
>>> mutexes. E.g. memory allocation.
>>
>> Since when does "shared" => "impure" ?
>>
>> If the function takes a pointer to shared data, then you are 
>> explicitly saying
>> "this function depends on this shared data". But as long is it 
>> isn't referencing
>> some *other* global directly, it is perfectly pure.
>
> We've been using 'shared' here to mean shared with another 
> piece of code that looks at the state, not 'shared' as in data 
> shared amongst multiple threads.

Ok. That's a fair point. So in that case, our function is 
pointing at "data", and is allowed to mutate it, and observe its 
state.

Now, if *another* piece of code is doing the same thing at the 
same time (potentially mutating "data", does that still violate 
purity?

As long a the function doesn't access/mutate something via direct 
global state, it's pure, isn't it?

I think... it's tough to wrap your head around the issue.


More information about the Digitalmars-d mailing list