When I create a list like this:
LF1 = [fun(X)->X*Y end || Y <- lists:seq(1,10)].
I receive
[#Fun<erl_eval.6.52032458>,#Fun<erl_eval.6.52032458>,
#Fun<erl_eval.6.52032458>,#Fun<erl_eval.6.52032458>,
#Fun<erl_eval.6.52032458>,#Fun<erl_eval.6.52032458>,
#Fun<erl_eval.6.52032458>,#Fun<erl_eval.6.52032458>,
#Fun<erl_eval.6.52032458>,#Fun<erl_eval.6.52032458>]
Then, when I use it like this:
[F(3) || F <- LF1].
I receive the result as it mentioned:
[3,6,9,12,15,18,21,24,27,30]
But, when I spawn all that functions from list:
LPF = [spawn(fun()->F(3) end) || F <- LF1].
[<0.1424.0>,<0.1425.0>,<0.1426.0>,<0.1427.0>,<0.1428.0>,
<0.1429.0>,<0.1430.0>,<0.1431.0>,<0.1432.0>,<0.1433.0>]
And then send them the parameter:
[X ! 3 || X <- LPF].
I receive:
[3,3,3,3,3,3,3,3,3,3]
What is happening here?
1条答案
按热度按时间zed5wv101#
对不起,我发现我的错误:
发送消息的方法不对。