To help LDC/GDC

Joseph Rushton Wakeling joseph.wakeling at webdrake.net
Tue Apr 9 03:52:59 PDT 2013


On 04/09/2013 12:28 PM, Manu wrote:
> There's nothing 'pure' about a function that has side effects. It's a totally
> different concept, and should be named appropriately.

But a natural way to define a pseudo-random number generator is a combination of
a state variable together with a pure function that takes the current state
variable and returns the next in the sequence -- see e.g.:
http://www.cs.berkeley.edu/~mhoemmen/cs194/Tutorials/prng.pdf

(Hope I'm not being condescending here, as I imagine you know the theory of this
better than I do.)

So, I'm not sure I see the disadvantage of allowing a slight relaxation in
purity that allows one to combine the state variable and transition function
together in a single struct -- which is pretty much analogous to what's
happening in the given examples where a private variable is being incremented by
a 'pure' function.

I do agree that it's a great pity there is not a way to declare strong purity
for D functions.


More information about the Digitalmars-d mailing list