When should pure function modify parameters?

Guillaume Piolat first.name at gmail.com
Wed Nov 19 11:31:25 UTC 2025


On Monday, 17 November 2025 at 14:46:06 UTC, Brother Bill wrote:
> In D, they are allowed to mutate parameters which seems to 
> violate purity.  Why did D make this choice and when to best 
> exploit this architectural decision.

It only violate purity in the sense of how other language define 
it, but it makes a lot of sense to be allowed to mutate.

"pure" is a nice idea, the problem start when you want to use it 
and a lot of stuff isn't actually marked pure, such as a lot of 
core.stdc.math:

https://github.com/dlang/dmd/blob/master/druntime/src/core/stdc/math.d#L2968

Why is atan2f not pure? I have no idea.
Then constructs that could be all pure end up not being marked 
pure.


More information about the Digitalmars-d-learn mailing list