News for hackers. Stuff that matters.
Re:Is your JavaScript function actually pure? by nbevans on Tuesday September 20, 2016 @09:20AM (#12539278)
Math.random doesn't necessarily have side affects. If it's storing a seed value, and incrementing that each time; then yes it stores mutable state which is a side affect because future invocations of that function will then depend upon that pre-existing state.

If however Math.random is passively listening for background radiation through some sensor perhaps then it doesn't really have side affects does it? Nor does it have mutable state, for that matter.

But it would still be impure according the true definition of what is a pure function, I believe.

Re:Is your JavaScript function actually pure? by kimolas on Tuesday September 20, 2016 @10:21AM (#12539706)
I thought it was a bit pedantic as well, at first. But looking at Haskell, I can see why the author made this point. Haskell functions won't accept random values as input, since they're monadic values.
Re:Is your JavaScript function actually pure? by DasIch on Tuesday September 20, 2016 @12:16PM (#12540671)
Are there two identical inputs to Math.random that yield different results? If the answer to that question is yes, the function isn't pure.
Re:Is your JavaScript function actually pure? by pwdisswordfish on Tuesday September 20, 2016 @10:55AM (#12539978)
Replace Math.random with this, then:

    ((j) => () => j++)(0)