Non-transitive immutable? Read only struct.

Ola Fosheim Grøstad ola.fosheim.grostad at
Thu Dec 5 17:01:07 UTC 2019

So, I get it, head-const has been discussed to death before. But 
it seems to me that it is more of a problem that there is no (to 
my awareness) non-transitive immutable. If there is, I apologize.

So, there are at least 4 situations where you really want that:

1. Protect fields in structs/classes after initialization. 
Reduces bugs. Documents intent.

2. Turn received values from functions into something that cannot 
be modified reliably irrespective of what the protection the 
called function has set for it. Reduces bugs.

3. To have sensible immutable tuples that can point to 
non-immutable things. In my view, a must have.

4. To have structures in ROM that can point to memory mapped 
registers or RAM. Not a must have, but sensible.

I'm not saying that immutable should change, but that there is 
need for something in addition to that. Call it "readonly" if you 

More information about the Digitalmars-d mailing list