head const (again), but for free?

Ola Fosheim Grøstad ola.fosheim.grostad at gmail.com
Wed Jan 13 15:17:52 UTC 2021


On Wednesday, 13 January 2021 at 15:14:29 UTC, sighoya wrote:
> On Monday, 11 January 2021 at 17:15:39 UTC, Ola Fosheim Grøstad 
> wrote:
>> Introduce "readonly" as head-immutable. That means that all 
>> values in an immutable array are immutable, including the 
>> address of reference, but not the objects being pointed to.
>
> This is an idiomatic break to the meaning of immutability which 
> is global const, while readonly serves the purpose of being 
> locally const.
> You can mutate a readonly var outside the readonly scope, this 
> is never possible with immutable, let it be either head, tail 
> or head & tail immutable.

No, readonly would be one-level immutable. Basically the same as 
every other language. The only difference between readonly and 
D's immutable is that you can have immutable pointers to mutable 
data.

What you are talking of is head const?



More information about the Digitalmars-d mailing list