Memory allocation purity
via Digitalmars-d
digitalmars-d at puremagic.com
Mon May 19 10:44:59 PDT 2014
On Monday, 19 May 2014 at 17:35:34 UTC, Steven Schveighoffer
wrote:
> Returning the same immutable object, when called with the same
> immutable parameters, should never cause a break in code, pure
> or not.
This isn't at all obvious to me. Also I think the "coin flip
trick" represent a class of algorithms that depend on imposing a
sort order on objects. I can easily see an algorithm break if you
sometimes receive the same object and sometimes receive a new
object with the same values as parameters. That's how an
optimizer works, sometimes it optimizes, sometimes not. If your
algorithm depends on running something twice and then comparing
the two results then it could easily break. In order to prevent
this you would need to "box it as a value" and let the type
system forbid object identity comparison.
More information about the Digitalmars-d
mailing list