pure-ifying my code
Philippe Sigaud
philippe.sigaud at gmail.com
Sun Nov 17 05:16:34 PST 2013
> If you just think about pure as meaning that the function doesn't access any
> mutable global state, then you'll have a much better grasp of pure.
I'll endeavour to keep this in mind :)
> Essentially, it restricts the function to accessing what's passed to it
> directly and to global constants which can't possibly have changed their value
> once they were set, even through other references to them. As such, pure has
> nothing to do with mutation. Though it is true that it can seem a bit weird
> with member functions if you forget the fact that they're being passed the
> this pointer/reference as one of their arguments, which is the case with
> popFront. So, that's probably what was throwing you off.
I considered that a hidden *this* was passed, but I forgot that a D
pure function could modify its arguments (unless the parameters are
specified as const or immutable in the function definition, of
course).
I hope I get it now. I guess this is the kind of subject (like Unicode
for example) that one only understands when one uses it in his code.
More information about the Digitalmars-d-learn
mailing list