thoughts on immutability in D

Christophe travert at phare.normalesup.org
Fri Sep 23 04:49:15 PDT 2011


bearophile , dans le message (digitalmars.D:145005), a écrit :

> So with a lconst array you are allowed to change its contents, but not 
> reassign it or change its length. A lconst doesn't implicitly cast to 
> immutable.

A solution to your problems could be to use a headconst keyword or 
library tool, or, even more powerful but probably much harder to 
implement, a mutable keyword.

const(mutable(int)[])

mutable for an array or a pointer would mean you can change what is 
pointed, even if the array or pointer is const. It could be forbidden 
for fields.

This could be useful to lazily fill up fields of const objects.

However, if this has to break a fraction of the power of D's constness, 
it would not be desirable.

-- 
Christophe


More information about the Digitalmars-d mailing list