Search code examples
multicoreglobal-state

Can pure functions read global state?


Please note: by a "pure" function, I don't mean "pure virtual"
I'm referring to this

If a function "reads" some global state, does that automatically render it impure? or does it depend on other factors?

If it automatically renders it impure, please explain why.

If it depends on other factors, please explain what are they.


Solution

  • A "pure" function is a function whose result depends only on its input arguments. If it reads anything else, it is not a pure function.