1
我是Erlang的初學者,我一直在努力通過「瞭解你一些Erlang的好處!」。我用的this example code的修改版本,其中評論家有一個參數:無法用數字參數產生?
critic(Count) ->
receive
{From, {"Rage Against the Turing Machine", "Unit Testify"}} ->
From ! {self(), {"They are great!", Count}};
{From, {"System of a Downtime", "Memoize"}} ->
From ! {self(), {"They're not Johnny Crash but they're good.", Count}};
{From, {"Johnny Crash", "The Token Ring of Fire"}} ->
From ! {self(), {"Simply incredible.", Count}};
{From, {_Band, _Album}} ->
From ! {self(), {"They are terrible!", Count}}
end,
critic(Count).
這是催生這樣的:
restarter() ->
process_flag(trap_exit, true),
Pid = spawn_link(?MODULE, critic, [my_atom]),
register(critic, Pid),
receive
{'EXIT', Pid, normal} -> % not a crash
ok;
{'EXIT', Pid, shutdown} -> % manual termination, not a crash
ok;
{'EXIT', Pid, _} ->
restarter()
end.
該模塊用於這樣的:
1> c(linkmon).
{ok,linkmon}
2> Monitor = linkmon:start_critic().
<0.163.0>
3> linkmon:judge("Rage Against the Turing Machine", "Unit Testify").
{"They are great!",my_atom}
現在,當我將「my_atom」更改爲簡單數字(如255)時,顯示器崩潰:
1> c(linkmon).
{ok,linkmon}
2> Monitor = linkmon:start_critic().
=ERROR REPORT==== 14-Jul-2013::20:42:20 ===
Error in process <0.173.0> with exit value: {badarg,[{erlang,register,[critic,<0.174.0>] []},{linkmon,restarter,0,[{file,"linkmon.erl"},{line,16}]}]}
然而,當我發送[1](因此代碼是「spawn(.....,[[255]])時它會工作。」) 爲什麼我不能傳遞一個數字?只是略讀了spawn/3的文檔並沒有真正告訴我任何東西......除了也許我錯過了一些東西,並且一個數字不是Erlang術語。但是,我如何傳遞一個數字?
我認爲這是後者。重新啓動shell後,它可以正常工作。 – cronotk