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

Paul Backus snarwin at gmail.com
Sat Nov 13 17:14:59 UTC 2021


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.


More information about the Digitalmars-d mailing list