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