pure-ifying my code

Ali Çehreli acehreli at yahoo.com
Sun Nov 17 08:46:49 PST 2013


On 11/17/2013 02:55 AM, Jonathan M Davis wrote:

 > And since additional calls to strongly pure functions are only 
optimized out
 > within a single expression (or maybe statement - I'm not sure which - but
 > certainly not across multiple statements), it's not like calls to 
strongly
 > pure functions can be optimized out very often anyway.

I don't see why not.

     if (pure_func(a)) {
         // ...
     }

     // assume 'a' is not mutated here

     if (pure_func(a)) {
         // ...
     }

There is no reason why pure_func(a) cannot be executed only once, right?

Ali



More information about the Digitalmars-d-learn mailing list