Challenge: write a reference counted slice that works as much as possible like a built-in slice

Ola Fosheim Grøstad ola.fosheim.grostad at gmail.com
Tue Nov 9 15:35:09 UTC 2021


On Tuesday, 9 November 2021 at 11:19:38 UTC, deadalnix wrote:
> Yes. In addition, it is worth mentioning that many functional 
> programming languages are using reference counting internally. 
> It is so that they can do copy on write instead of copying 
> everything all the time for no reason.

Functional programming language design and implementation can be 
useful to think about, yes.

The main point is that if you say "built in" then you are allowed 
to do things that seemingly break the rules, but only if you can 
imagine a corresponding simple hypothetical implementation that 
shows that the type system invariants actually are upheld.

One such hypothetical implementation could be to pass in a 
"reference tracker database" as a hidden parameter in all 
function calls and use that for acquire/release/destruction.

This is impractical, but if that is sufficient to uphold all 
invariants, then you only have to prove that an efficient 
implementation is equivalent to the hypothetical implementation.

I think.



More information about the Digitalmars-d mailing list