Hello Steven,
I'm sorry, but have big trouble to understand what you want to say. So I
will comment to what I can, and try to rephrase my post.
On Mon, 07 Dec 2009 05:34:52 -0500, Michal Minich
<[email protected]> wrote:
Hello Tomek,
... don't make sense. So is there a reason why they aren't excluded
from the "everything in an immutable is immutable" rule?
Tomek
Immutable static member function could be useful...
marking struct or class as const or immutable is the same as marking
every its member so. The problem I see is in definition of what const
or immutable member function means:
from D specs: "Immutable member functions are guaranteed that the
object and anything referred to by the this reference is immutable."
Which applies both to instance and s static functions. I think the
above definition should apply only to instance functions. Static
const or immutable functions should be defined as:
Immutable static member functions are guaranteed that the static
variables of object and anything referred to by these variables is
immutable.
Let's say there was an immutable static member function which treated
the static data members as immutable. This means nobody else can
change them.
Couldn't they be changed from outside of the type?
This means that there cannot be any static member
functions that are not immutable. This means that the data members
cannot be marked as public unless they are also marked as immutable.
In this case, the equivalent thing is to mark all static data members
as immutable, and leave the static function as a normal function.
This is why the OP said they "don't make sense" Although his
statement really should be "immutable static functions don't make
sense", not "static functions in immutable types don't make sense,"
as they do make sense, they should just not be marked as immutable.
The bug filed is absolutely a bug, it should be possible to have a
normal static function inside an immutable type.
Currently everything is marked as immutable in immutable type. Do you think
it is good to have exception for static function?
-Steve
So to rephrase:
1. from D specs: " A struct declaration can have a storage class of const,
immutable or shared. It has an equivalent effect as declaring each member
of the struct as const, immutable or shared." -- I'm ok with this, it is
simple.
2. from D specs: "Immutable member functions are guaranteed that the object
and anything referred to by the this reference is immutable." -- this rule
is wrong, because it mentions *this* and at the same time it applies to static
member functions, which obviously doesn't have *this* reference.
3. I propose changing rule in point 2 to: "Immutable *non-static* member
functions are guaranteed that the object and anything referred to by the
this reference is immutable." and adding this one: "Immutable static member
functions are guaranteed that the static variables of object and anything
referred to by these variables is immutable"
And I'm asking if the change is reasonable - Or how should be defined semantics
of static immutable member function?