logical const is a subset of transitive const
Bruce Adams
tortoise_74 at yeah.who.co.uk
Sun Sep 16 17:10:08 PDT 2007
Steven Schveighoffer Wrote:
> "Janice Caron" wrote
> > What I /don't/ understand is why D lets you declare a member function
> > (as opposed to an object) as being invariant. To my brain, that ought
> > to mean the function sees "this" as having the type invariant(T) - but
> > that's clearly an invalid assumption, because "this" /can/ be
> > modified. You have a read-only view, that's all.
> >
>
> Yeah, I totally agree that invariant declared on a function doesn't seem to
> be right. I'm guessing the only reason they did that is because it makes no
> sense to return an invariant type, so you could put invariant before the
> function name and not be ambiguous.
>
> i.e.
>
> const int* f(); // is f const, or is it returning a const int*?
> invariant int* f(); // can't have a pointer to invariant (at least in
> current spec), so invariant must refer to f
>
> If that is the reason, then I say use const, and put it after the func
> declaration, like in C++. May look weird, but it's unambiguous.
>
> > "Pure" on the other hand, only makes sense for functions. So far as I
> > know, there's no such thing as a pure object.
>
> pure implies that:
> 1. you can only call pure functions
> 2. you can only access invariant data (data that cannot be changed anywhere
> else).
>
> so I think you are right, pure is more for functions.
>
> BTW, if we get rid of invariant for functions meaning the same thing as
> const functions, I think pure should be replaced with invariant. It makes
> more sense to me as an intuitive keyword. An invariant function cannot
> change anything and can only access invariant data, and call other invariant
> functions. Makes a lot of sense to me...
>
> -Steve
>
Pure is a good intuitive name to use for several reasons.
For a start it has exactly the same meaning as its counterpart in Fortran-90. If it exists in any functional languages out there most likely they use the same terminology.
More information about the Digitalmars-d
mailing list