Containers

deadalnix deadalnix at gmail.com
Tue Aug 31 18:24:54 UTC 2021


On Tuesday, 31 August 2021 at 18:11:04 UTC, Paul Backus wrote:
> This sounds similar to Clojure's immutable data structures. I 
> agree these would be a good thing to have, although I think 
> traditional mutable containers should also exist alongside them.

```d
class RefContainer {
     Container c;
}
```

Here you go :)

There is obviously some boilerplate missing, but I'm sure you get 
the idea. One nice bonus is that you get a practically free clone 
method, that will only do so when you actually mutate things.

You'll note that in practice, you don't need to clone the 
container every time you write, you need to keep a ref count and 
only clone when the number of references to the container is 
greater than 1.

Lastly, my experience tells me that container being traditionally 
references was a mistakes. I have many scars to show for it.

Thank you for the Head mutable article. I'll dig into this and 
see if I can make it work.


More information about the Digitalmars-d mailing list