pure functions/methods

Ary Manzana ary at esperanto.org.ar
Fri Apr 20 01:19:07 PDT 2012


On 4/20/12 4:06 PM, Namespace wrote:
> The sense of pure functions isn't clear to me.
> What is the advantage of pure functions / methods?
> I inform the compiler with "const" that this method does not change the
> current object, and therefore he can optimize (at least in C++) this
> method. How and what optimized the compiler if i have "pure" or "const
> pure" functions / methods?

As far as I know pure functions always return the same results given the 
same arguments. They also don't cause any side effect.

http://en.wikipedia.org/wiki/Pure_function

Many invocations of a pure function can be executed in parallel because 
they don't have side effects. There's also a chance of caching their 
result since it only depends on the value of their arguments (though I 
doubt what rule the compiler can use to decide to do it).

I don't think any of the following benefits are implemented in DMD.


More information about the Digitalmars-d-learn mailing list