mutable keyword

Jonathan M Davis via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon May 23 08:30:40 PDT 2016


On Monday, May 23, 2016 14:08:43 Jack Applegame via Digitalmars-d-learn wrote:
> On Monday, 23 May 2016 at 11:05:34 UTC, Jonathan M Davis wrote:
> > I don't know why you think that D violates its own rules
> > frequently though. It's not perfect, but it usually does follow
> > its own rules - and when it doesn't, we fix it (though not
> > always as quickly as would be ideal).
>
> The most PITA for me is lacking mutable references for immutable
> classes. I like immutability and hate Rebindable.

Well, Rebindable is kind of ugly, but honestly, a built in modifier probably
wouldn't look much better. e.g.

tail_const(MyClass) obj;

vs

Rebindable!MyClass obj;

The fact that you don't have a * to separate what the const applies to seems
to kill any chance of making it short, and since it's fundamentally part of
the design of D classes that they can't be used separately from their
reference, I don't see that changing even if we get some kind of tail const
built-in to the language for classes.

> Also, how to embed reference counter into immutable class without
> violating immutability?

You can't. It's fundamentally impossible as long as immutable is transitive.
I believe that the proposed solution is to put the ref-count in the memory
next to the object, or at least somewhere else where the memory-management
stuff can find it. In the case of GC-allocated memory, that should be fairly
straightforword, though I don't know how feasible it is to deal with it with
non-GC-allocated memory without losing out on pure. Really, it's going to
come down to how the ref-counting scheme that Walter is working on works.

- Jonathan M Davis



More information about the Digitalmars-d-learn mailing list