Assert allowed to have side effects?

bearophile bearophileHUGS at lycos.com
Mon May 30 17:20:24 PDT 2011


Stewart Gordon:

> Only if purity rules are relaxed.  AIUI, one of the restrictions at the moment is that in 
> a pure function only immutable data can be accessed.  As long as this restriction remains 
> in place, adding the restriction of purity to asserts would erode their usefulness.

You are of course right, I didn't think enough about this.
So something different than purity is needed here, something like a "constview" (I have suggested something similar time ago, for different purposes), this means it's allowed to read mutable data in the outer scopes, but can't modify it. To work well this too has to become transitive, like pure and nothrow. And this is probably too much complexity added. So no game :-)

Bye and thank you,
bearophile


More information about the Digitalmars-d-learn mailing list