On Saturday, 31 March 2018 at 20:44:13 UTC, Andrei Alexandrescu
wrote:
Yah, only strongly pure functions would qualify. Indeed that's
easy for the compiler to figure - so I'm thinking
pragma(isStronglyPure, expression) would be easy to define.
What would be some good uses of this?
Andrei
It can be used for some rudimentary compiler checks. Namely, in
some contexts it doesn't make sense for an expression to have (or
rather not have) any side effects:
- The increment section in a for loop must have a side effect,
unless it's empty.
- An assert expression shouldn't have any side effects (because
assertions disappear in release mode).
Maybe the compiler already does such checks, I don't know.
In general this seems far less useful than the concept of a pure
function.