Do pure functions solve the "return const" problems?

Bruno Medeiros brunodomedeiros+spam at com.gmail
Tue Apr 29 18:15:21 PDT 2008


Christopher Wright wrote:
> Janice Caron wrote:
>>> It'd take more effort to prevent out parameters for pure functions.
>>
>> That's clearly not true. Rule one is that a pure function "has
>> parameters that are all invariant or are implicitly convertible to
>> invariant". (See
>> http://www.digitalmars.com/d/2.0/function.html#pure-functions ). Out
>> parameters fail immediately on account of not being invariant.
> 
> Argh, where is my mind today. Or yesterday, rather.
> 
> You'd have to change something like:
> if (arg->storageClass & STCinvariant)
> 
> to:
> if (arg->storageClass & (STCinvariant | STCout))
> 
> And then you'd have to amend the spec to mention the exception.

Under the current pure rules, you simply cannot have out parameters.

But if you consider the "partial" pure function rules (see the new 
thread), you can have out parameters, and more, and all of it safely. So 
I would say partially pure is the solution for this problem, since you 
seem to love out parameters so damn much. :)

-- 
Bruno Medeiros - Software Developer, MSc. in CS/E graduate
http://www.prowiki.org/wiki4d/wiki.cgi?BrunoMedeiros#D



More information about the Digitalmars-d mailing list