How do "pure" member functions work?

Simen Kjaeraas simen.kjaras at gmail.com
Mon Aug 22 15:30:54 PDT 2011


On Mon, 22 Aug 2011 22:19:50 +0200, Don <nospam at nospam.com> wrote:

> BTW: The whole "weak pure"/"strong pure" naming was just something I  
> came up with, to convince Walter to relax the purity rules. I'd rather  
> those names disappeared, they aren't very helpful.

The concepts are useful, but better names might be worth it. But what
short word eloquently conveys 'accesses no mutable global state'? :p

What we call strongly pure is what in other languages is simply called
'pure', and that is likely the word that should be used for it.

Weakly pure is a somewhat different beast, and the 'best' solution would
likely be for it to be the default (But as we all know, this would
require changing the language too much. Perhaps in D3...). Noglobal
might be the best we have. My favorite thus far is 'conditionally pure'.
It conveys that the function is pure in certain circumstances, and not
in others. However, it might be somewhat diluted by the addition of pure
inference in newer versions of DMD - that definitely is conditionally
pure.

Const pure is not a concept I'm particularly familiar with. Is this the
special case of calling a conditionally pure function with only
const/immutable parameters, with arguments that are immutable in the
calling context, and that it in those cases can be considered
strongly pure?

-- 
   Simen


More information about the Digitalmars-d-learn mailing list