It's worse than I thought

gide at nwawudu.com gide at nwawudu.com
Fri Nov 30 07:48:48 PST 2007


On Fri, 30 Nov 2007 11:06:53 +0000, "Janice Caron"
<caron800 at googlemail.com> wrote:

>On Nov 30, 2007 10:52 AM, Walter Bright <newshound1 at digitalmars.com> wrote:
>> It turns out that making a variable that is typed const (rather than
>> storage class const) immutable makes it impossible to use const references:
>> So, variables that are typed const are rebindable.
>
>Yes, there is another thread on that somewhere. It's got some long
>arguments in it, which it would be silly to repeat here, but in the
>end I proposed the syntaxes:
>
>    const(C) c;
>    const(C) ref c;
>
>The first makes both the reference and the data const; the second
>makes only the data const, but the reference rebindable. (Other people
>have suggested alternative syntaxes through the ages, so don't think
>I'm particularly hung up on mine, it's just that it seems very clear
>what's being said).
>
>
>> Note that this
>> doesn't break const
>
>Nobody's saying anything is broken. What I'm saying is that it's TOO
>CONFUSING. This can break D. I mean, on other threads, you told us
>that "const X x" was the same thing as "const(X) x". Now it turns out
>that's not true.
>
>The only, and I mean *ONLY*, thing that makes intuitive sense, is that
>when I write const(...), it must mean that everything inside the
>brackets, and nothing else, is const. Nothing else makes sense.

</lurk>
I agree with Janice on this, I was under the (wrong) impression that
'const(C)' and 'const C'  were synonymous.

Maybe the following syntax will work?
const (C) c = new C;
c = new C; // Error;
c.set(...); // Error

const (ref C) c = new C;
c = new C; // Error;
c.set(...); // Ok

const (C.) c = new C;
c = new C; // Ok;
c.set(...); // Error

Gide



More information about the Digitalmars-d mailing list