Pure not acting pure.

Jonathan M Davis jmdavisProg at gmx.com
Thu Jun 16 11:33:17 PDT 2011


On 2011-06-16 10:38, Charles McAnany wrote:
> Ok, I think I get it. That cleared it up. =).
> So, if you have a functioned labelled pure, it's your job to not pass it
> mutable arguments, but the compiler's job to make sure it doesn't mutate
> anything not in the arguments. And that's why a strongly pure function can
> call a weakly pure one - only the first function's internal state can be
> mutated by a weakly pure function. Thanks!

Well, essentially. But it's a question of parameters, not arguments. It 
doesn't matter whether you pass the function mutable arguments or not. What 
matters is whether its parameters are immutable or implicitly immutable. If 
they are, then you'll be forced to pass it arguments which are immutable or 
implicitly immutable. If they aren't, then the function is weakly pure and no 
optimizations can take place (but the function still can't access mutable 
global variables and can still be called from other pure functions), 
regardless of how mutable the arguments are.

- Jonathan M Davis


More information about the Digitalmars-d-learn mailing list