[erlang-questions] Process scope variable

Imants Cekusins imantc@REDACTED
Tue Feb 17 18:08:37 CET 2015


> you're missing the distinction between messages and arguments -- they are not the same thing.

I used the word "message" in a misleading way. I did not mean
"message" as erlang message sent to another process. simply alleged to
"message" (a "tweet" if you prefer) passed from person A to person B
intended for person C, from function to function in this case, an arg
passed to fun z() like this:

a()->
S = #state{},
 b(S).

b(S)->
c(S).

...

z(S)->
Z = S#state.some_var.

an arg S passed to another fun X, which fun X may or may not use,
simply pass it to the next fun and so on.

this state passing clutters the code and makes refactoring difficult.
I prefer to only pass the args the fun actually needs. If some other
fun down the line needs the state, let it get it directly.

common state could be dangerous if simultaneous state modification
could happen. But in Erlang this does not happen, does it? each single
process is a single thread, isn't it?



More information about the erlang-questions mailing list