On Wednesday, 8 January 2014 at 18:40:46 UTC, Ola Fosheim Grøstad
wrote:
Is pure meant to be a compiler hint so that it is up to the
programmer to enforce it? It is sometimes useful to maintain
hidden state for lazy evaluation, that does not affect purity
optimizations:
e.g.
a = foo(1) // evaluates, caches and returns value
b = foo(1) // returns cached value
c = foo (1) // returns cached value
is optimized to
a = b = c = foo(1) // evaluates, caches and returns value
pure is enforced by the compiler (bugs allowing...). However, D
purity has more shades to it than the black and white concept
that most are familiar with.
I'll leave it to someone who knows better to explain it.