Pure
John Colvin
john.loughran.colvin at gmail.com
Wed Jan 8 11:04:22 PST 2014
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.
More information about the Digitalmars-d-learn
mailing list