我最近开始从https://learnyousomeerlang.com学习Erlang 在errors and processes这一章中,我了解了程序的功能以及如何执行,但是我无法弄清楚此函数的目的是什么,何时以及如何调用此函数?
据我了解,如果元组模式与Pid和atom匹配,它将返回一个atom。我将如何发送消息以接收内部法官?
print(f"Some text and a {value}")
输出
start_critic() ->
spawn(?MODULE, critic, []).
judge(Pid, Band, Album) ->
Pid ! {self(), {Band, Album}},
receive
{Pid, Criticism} -> Criticism
after 2000 ->
timeout
end.
critic() ->
receive
{From, {"Rage Against the Turing Machine", "Unit Testify"}} ->
From ! {self(), "They are great!"};
{From, {"System of a Downtime", "Memoize"}} ->
From ! {self(), "They're not Johnny Crash but they're good."};
{From, {"Johnny Crash", "The Token Ring of Fire"}} ->
From ! {self(), "Simply incredible."};
{From, {_Band, _Album}} ->
From ! {self(), "They are terrible!"}
end,
critic().
答案 0 :(得分:1)
第Pid ! ...
行向评论者发送消息。评论者然后将通过From ! ...
行之一发送回复。 receive
函数中的judge
等待所述响应,然后简单地返回响应中包含的字符串。