www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Const question

reply Graham St Jack <grahams acres.com.au> writes:
I have finally taken the plunge and moved over to D 2.x.

The experience is good so far except for a few problems with const (I 
want const btw), the biggest of which is the tail-const issue for 
classes, which is still an active area of discussion.

My question is more mundane - are there plans to fix the const-
correctness of things in the language and phobos, specifically things 
like opCmp, opAdd, etc? I find I am having to cast away const in order to 
use overloaded operators, which is very annoying.
Mar 23 2008
next sibling parent reply "Craig Black" <craigblack2 cox.net> writes:
"Graham St Jack" <grahams acres.com.au> wrote in message 
news:fs6mtj$1muc$1 digitalmars.com...
I have finally taken the plunge and moved over to D 2.x.

 The experience is good so far except for a few problems with const (I
 want const btw), the biggest of which is the tail-const issue for
 classes, which is still an active area of discussion.

This is still being discussed? Is Walter considering a fix for it? -Craig
Mar 23 2008
next sibling parent reply Graham St Jack <grahams acres.com.au> writes:
On Sun, 23 Mar 2008 20:46:43 -0500, Craig Black wrote:

 "Graham St Jack" <grahams acres.com.au> wrote in message
 news:fs6mtj$1muc$1 digitalmars.com...
I have finally taken the plunge and moved over to D 2.x.

 The experience is good so far except for a few problems with const (I
 want const btw), the biggest of which is the tail-const issue for
 classes, which is still an active area of discussion.

This is still being discussed? Is Walter considering a fix for it? -Craig

The discussion is under "const debacle", posted on 19th March. It looks like plenty more thinking is needed to sort it out.
Mar 23 2008
parent reply Walter Bright <newshound1 digitalmars.com> writes:
Graham St Jack wrote:
 The discussion is under "const debacle", posted on 19th March. It looks 
 like plenty more thinking is needed to sort it out.

The const debacle thing is something else.
Mar 23 2008
parent Walter Bright <newshound1 digitalmars.com> writes:
Graham St Jack wrote:
 While I have your attention, what is the plan for expressing that an 
 object is const or immutable and to have a mutable reference to it? 
 Arrays are fine (like "string"), but what is the deal for classes?

There is no plan to have a mutable reference to const class contents. It just doesn't work in the type system.
Mar 27 2008
prev sibling next sibling parent "Janice Caron" <caron800 googlemail.com> writes:
On 24/03/2008, Craig Black <craigblack2 cox.net> wrote:
 This is still being discussed?  Is Walter considering a fix for it?

Not Walter, Andrei. Andrei has a template solution, Rebindable!(). Unfortunately, right now it's undocumented and shouldn't be used because it will likely change as D2 changes. I think Andrei is waiting for D to support opImplicitCast. I think, once we have that, his template will work as you'd expect. This is discussed in the thread "Idea to ease tail-const class reference woes".
Mar 24 2008
prev sibling next sibling parent Graham St Jack <grahams acres.com.au> writes:
On Sun, 23 Mar 2008 22:36:08 -0700, Walter Bright wrote:

 Graham St Jack wrote:
 The discussion is under "const debacle", posted on 19th March. It looks
 like plenty more thinking is needed to sort it out.

The const debacle thing is something else.

Oops. While I have your attention, what is the plan for expressing that an object is const or immutable and to have a mutable reference to it? Arrays are fine (like "string"), but what is the deal for classes?
Mar 24 2008
prev sibling parent Graham St Jack <Graham.StJack internode.on.net> writes:
On Thu, 27 Mar 2008 23:05:03 -0700, Walter Bright wrote:

 Graham St Jack wrote:
 While I have your attention, what is the plan for expressing that an
 object is const or immutable and to have a mutable reference to it?
 Arrays are fine (like "string"), but what is the deal for classes?

There is no plan to have a mutable reference to const class contents. It just doesn't work in the type system.

Ok, I can live with that. Thanks for the clarification.
Mar 31 2008
prev sibling parent "Simen Kjaeraas" <simen.kjaras gmail.com> writes:
On Sun, 23 Mar 2008 23:51:31 +0100, Graham St Jack <grahams acres.com.au>  
wrote:

 I have finally taken the plunge and moved over to D 2.x.

 The experience is good so far except for a few problems with const (I
 want const btw), the biggest of which is the tail-const issue for
 classes, which is still an active area of discussion.

 My question is more mundane - are there plans to fix the const-
 correctness of things in the language and phobos, specifically things
 like opCmp, opAdd, etc? I find I am having to cast away const in order to
 use overloaded operators, which is very annoying.

opAdd and friends are easy to fix in most situations: const Foo opAdd(const Foo rhs) Of course, if this pattern is not used in the std lib, that is Walter's (and others') job. -- Simen
Mar 24 2008