Unofficial wish list status.(Jul 2008)

Steven Schveighoffer schveiguy at yahoo.com
Wed Jul 23 12:33:59 PDT 2008


"Jason House" wrote
> Steven Schveighoffer Wrote:
>
>> "Jason House" wrote
>> > Walter Bright Wrote:
>> >> The missing ingredient here is what the 'pure' modifier for functions
>> >> provides. That is the ability to diagnose attempts to alter global 
>> >> state
>> >> from within a function that is not supposed to do that. Invariant does
>> >> not imply pure.
>> >
>> >
>> > That's actually a very key part to my whole point.  There is very 
>> > little
>> > difference between pure and invariant functions.  Why do we need a 
>> > concept
>> > for both?  Under the assumption that we're adding const to support
>> > functional programming, I don't understand the motivation for this
>> > difference.
>>
>> You are misunderstanding what an 'invariant' member function is.  The
>> function itself is not invariant.  It's a function whose 'this' pointer 
>> is
>> marked as invariant.
>
>
> It's not that I misunderstand but that I question.  Given the goals of the 
> const system, invariant functions, as defined, don't make a lot of sense. 
> They make some sense, but not a lot of sense :)

They don't make any less sense than declaring invariant variables.  Or 
declaring invariant parameters.

Can you see use in the following function signature:

void f(invariant(somestruct) *x) {...}

If so, an invariant member function is no different.

While I agree that having invariant functions is probably not going to be 
extremely useful, to not allow invariant methods is to make an inconsistency 
in the type system.  If I can declare a variable is invariant, then I should 
be able to pass that variable to a function as invariant.  If there is a 
special case that you can't pass it to it's own member function, then it is 
not only inconsistent, but probably makes the compiler more complex for no 
good reason.  If you don't like invariant functions, don't use them.  I 
probably won't.

-Steve 





More information about the Digitalmars-d mailing list