When should pure function modify parameters?

Lance Bachmeier no at spam.net
Mon Nov 17 14:58:07 UTC 2025


On Monday, 17 November 2025 at 14:46:06 UTC, Brother Bill wrote:
> Pure functions in Functional Programming provide the same 
> result when provided the same arguments.
>
> They are not allowed to read or write to system resources such 
> as file system, console, clock, network, etc.  In addition, 
> they may not read/write to module level variables.
>
> 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.
>
> Also, would you agree that not mutating parameters to have 
> "true" purity would be preferred?

It's been this way the entire time I've been using D (since 
2013). I've always found it weird to misuse a standard 
programming language term like this, and as a result I've never 
used it. The spec distinguishes weak and strong purity in a way 
that complexifies things without benefit, but it's not going to 
change: https://dlang.org/spec/function.html#weak-purity


More information about the Digitalmars-d-learn mailing list