Store mutable indirections in immutable data with this one weird trick!

Dukc ajieskola at gmail.com
Sun Nov 14 10:32:14 UTC 2021


On Saturday, 13 November 2021 at 21:26:46 UTC, Ola Fosheim 
Grøstad wrote:
> On Saturday, 13 November 2021 at 18:55:11 UTC, Dukc wrote:
>> Not at all. He suggested having the compiler to catch the 
>> mistakes, not the runtime.
>
> He argued against using identity and relying fully on content, 
> that is crazy expensive in common situations/algorithms.
>
> This is not practical in a language where you expect to use 
> library abstractions. As such, you end up not being able to use 
> "pure" for anything that is non-trivial.

In `@safe` code with only the language constructs, that is. You 
could still write sound `@trusted pure` library functions that 
can do those in efficient way.

>
>> I'm assuming you mean that the language would allow caching 
>> values even with arguments with mutable indirection, if the 
>> compiler can prove they are similar to an earlier call.
>
> Just stick to the keyword ```pure``` meaning "no globals", and 
> leave it at that. Want more? Introduce a new well defined 
> concept.

My mistake, you were proposing the exact opposite of what I 
thought. That's the surest way to go but I hope it won't be 
necessary. It'd leave `pure` a bit lame.


More information about the Digitalmars-d mailing list