keywords "objconst" and "objimmutable" vs. const(Object) ref

Steven Schveighoffer schveiguy at yahoo.com
Wed May 18 04:51:24 PDT 2011


On Tue, 17 May 2011 21:26:38 -0400, Jesse Phillips  
<jessekphillips+D at gmail.com> wrote:


> Syntax has definitely been a major problem for this feature. Walter's  
> stance has been that he has tried many times to get the semantics and  
> syntax to work and has given up. michelf (Sorry don't know his real  
> name) has created a branch which implements the syntax you are against.  
> As this is a change Walter is skeptical of it will take time to review.

Michel Fortin

> Now as for your distaste, I believe the intent is to make a valid  
> declaration:
>
> Object ref foobar;
>
> Meaning that you are exposing the reference or address itself. However I  
> think there might be more to it when considering generic code which  
> would suggest these should also be valid forms:
>
> void function(T)(const(T) ref thing);
>
> const(int) ref foo;
> const(myStruct) ref bar;
> const(int*) ref bared;

This doesn't really work, Objects are unique in that they are references  
under the hood, but they are also rebindable.  With an integer reference  
(i.e. ref int), you cannot rebind the reference.  This is as it is in C++  
as well.  I don't even know how it would work.  For instance:
int i, j;
int ref x = i; // bind the reference to i
int ref y = j;
x = y; // does this assign to i the value of j, or does it rebind x to be  
the same as y?

I don't think the generic form is really possible.

What Michel's proposal does is extract the reference from the data, so you  
can apply const to just the data and not the reference.  It is the single  
most difficult thing to do in an intuitive way for this problem.  This  
proposal is not the prettiest, and there have been a multitude of attempts  
to do it (including several by me, I think this is a really important  
problem to solve).  However, his proposal has the distinct advantage that  
is is *actually implemented* :)  So we can try it out and see how it  
works.  I think with the distaste that Walter has towards this problem,  
this is likely the only way to get him to consider it.

So to Christopher, you will likely have to implement any proposal you have  
in order to get it considered, there is a lot of bad blood between this  
problem and Walter Bright.

-Steve


More information about the Digitalmars-d mailing list