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

Andrei Alexandrescu SeeWebsiteForEmail at erdani.com
Tue Nov 16 14:39:08 UTC 2021


On 2021-11-13 12:14, Paul Backus wrote:
> On Saturday, 13 November 2021 at 16:57:47 UTC, Imperatorn wrote:
>> On Saturday, 13 November 2021 at 14:43:00 UTC, Paul Backus wrote:
>>> On Saturday, 13 November 2021 at 14:35:36 UTC, Imperatorn wrote:
>>>> Many use the "compromise edition" to pure, I think it's ok. Pure in 
>>>> that sense is just same out for a given in, doesn't matter what the 
>>>> function does inside.
>>>
>>> [`pureMalloc`][1] does not return the same output for a given input.
>>>
>>> [1]: https://druntime.dpldocs.info/core.memory.pureMalloc.html
>>
>> Yeah, these words are not precise enough.
> 
> To be fair, the language spec is also not very precise about this:
> 
>> An implementation may assume that a strongly pure function that 
>> returns a result without mutable indirections will have the same 
>> effect for all invocations with equivalent arguments. It is allowed to 
>> memoize the result of the function under the assumption that 
>> equivalent parameters always produce equivalent results.
> 
> What does "equivalent" mean, here? The intent seems to be something like 
> "equal, if you ignore differences in memory addresses," but the term is 
> never actually defined.

The upside of these missing definitions is you have the opportunity to 
introduce them. I'm sure related pull requests would be received well.


More information about the Digitalmars-d mailing list