Unofficial wish list status.(Jul 2008)

Sean Kelly sean at invisibleduck.org
Tue Jul 22 15:36:29 PDT 2008


Walter Bright wrote:
> Sean Kelly wrote:
>> Walter Bright wrote:
>>> True, but it is not pure. Pure functions cannot change global state.
>>
>> The current definition of pure goes even farther than that.  Because 
>> arguments to pure functions must be invariant (as far as I know), pure 
>> functions may not accept parameters that could be changed by another 
>> thread.
> 
> That's right. One way to think about it (*) is that for pure functions,
> if you take a bit copy of its arguments on the stack, save them, and
> some arbitrary time in the future call the function again with those
> same bits, you must get back exactly the same result.
> 
>> So will D have some way to require that references passed between 
>> threads must be either invariant or represent a transferral of 
>> ownership?  I think that's the crux of the issue.  Using invariance 
>> for non-shared data is typically more for simplifying error recovery 
>> than anything else.
> 
> Consider (*). Pure functions do not "own" data, as they cannot have state.

I personally feel that requiring that parameters be const is sufficient 
for memoizing results.  Requiring invariance assumes a programming model 
that I simply don't endorse.  But I'll grant that it's certainly the 
safer approach.


Sean



More information about the Digitalmars-d mailing list