Proposal: Relax rules for 'pure'

Steven Schveighoffer schveiguy at yahoo.com
Wed Sep 22 13:02:20 PDT 2010


On Wed, 22 Sep 2010 15:52:03 -0400, Don <nospam at nospam.com> wrote:

> Steven Schveighoffer wrote:
>> On Wed, 22 Sep 2010 15:21:57 -0400, klickverbot <see at klickverbot.at>  
>> wrote:
>>
>>> On 9/22/10 9:14 PM, Steven Schveighoffer wrote:
>>>> Hypothetical counter-case
>>>>
>>>> struct S
>>>> {
>>>> version(stronglypure)
>>>> string s;
>>>> else
>>>> char[] s;
>>>> }
>>>>
>>>> pure foo(S s); // changes strength depending on S' contents
>>>>
>>>> -Steve
>>>
>>> This is a change to the signature of foo – S with the stronglypure  
>>> version defined and S without it are two completely distinct types.
>>  Wait, I didn't change foo's signature at all.  This is what the OP  
>> meant by long-range changes.  S can be defined far away from foo, and  
>> out of the author of foo's control.
>>  -Steve
>
> Is that really what he meant?
> Note that foo() would need to be recompiled, and the silent change in  
> strength would occur only if it still compiles despite a significant  
> change in the definition of one of types.

This isn't hard to come up with:

struct S
{
    string s;
    version(stronglypure)
    {
    }
    else
      char[] notused;
}

>
> If you change the definition of a type, you're always going to have  
> influences everywhere it's used in a function definition. I'd hardly  
> call that a 'long-range' change.

I think the OP's request is to be able to tell the compiler "I want you to  
make *sure* this function is strongly pure."  Not that I think it's  
terribly important, I'm just trying to convey what has been said.

Adding another member to a struct is a much better example than my first,  
and I don't think it's an uncommon thing.  Whether its extremely important  
to have this ability, I'm not sure about.  It's sort of akin to having an  
inline directive.

-Steve


More information about the Digitalmars-d mailing list