
Do pure functions exist in JavaScript? - robinpokorny
https://hackernoon.com/do-pure-functions-exist-in-javascript-b128ed5f0ed2
======
jepler
I doubt pure functions exist in any language. For instance, consider the C
function 'unsigned twice(unsigned a) { return a + a; }'. Here are some ways it
can be non-pure:

It could be called with an argument that has never been given a value: int j;
twice(j);

It could be called with an argument that is volatile: volatile int j;
twice(j); twice(j);

it could be called at just the right moment to exhaust the allocated stack:
int j=4; twice(j); char arr[8388608]; twice(j); [I didn't actually find where
the C(99) standard states that an implementation may have a maximum stack
size! I am clearly using the wrong search terms]

A signal could arrive during the execution of twice() and cause it never to
return int j=4; twice(j);

~~~
robinpokorny
At least true functional languages have them, think Haskell.

I do not know much (read: any) C, so I have a question: why does an argument
that has never been given a value make it impure?

~~~
jepler
.. some haskell implementations apparently had (practically) limited stack
size, at least as of 2007, so as long as "pure" functions still allocate stack
frames, it's possible for the result of the pure function call to be "stack
exhausted" in one case and not another.
[https://mail.haskell.org/pipermail/haskell-
cafe/2007-Novembe...](https://mail.haskell.org/pipermail/haskell-
cafe/2007-November/034017.html)

