[erlang-questions] Does Erlang pure functional programming language?
Richard O'Keefe
ok@REDACTED
Mon Jan 23 04:47:10 CET 2012
On 20/01/2012, at 3:52 AM, Gleb Peregud wrote:
> It's incorrect. It is possible to write a pure functions in Erlang,
> but it is possible to have side effects like:
> - sending messages to other processes (changes state of other process)
> - mutating own process dictionary
> - manipulating ETS tables
> - changing things like operating system environmental variables, etc.
It's worth noting that the process dictionary can be regarded in a pure
functional way. That is, you can understand each Erlang function
definition as a short-hand for an "underlying" function which would be
pure if it didn't use any of the other features. To keep this message
short, I'll use a tiny example. State threading is pretty well understood,
and was used as part of the demonstration that the programming language
Euclid could be regarded as pure functional; before that it was used to
convert Fortran to Lisp for the Boyer-Moore prover.
f(X) -> g(h(X), m(X)).
f(X, State0) ->
{T1,State1} = h(X, State0),
{T2,State2} = m(X, State1),
g(T1, T2, State2).
Then
get(K)
=> {get(K, State), State}
put/1 is one of the few things that makes a new state.
The big deal that makes Erlang impure, of course, is one of its reasons
for existence: you can dynamically load and unload modules.
More information about the erlang-questions
mailing list