我正在处理一个erlang程序并遇到一个奇怪的运行时错误。知道为什么吗?谢谢!
错误是(成功编译程序后):
8> PID = spawn(planner,start,[]).
** exception error: no match of right hand side value <0.65.0>
9>
这是该计划:
-module(planner).
-export([start/0]).
start() ->
loop([],[]).
loop(ContactsList,EventsList) ->
receive
{contact, Last, First, Number} ->
loop([{Last,First,Number}|ContactsList],EventsList);
{event, Date, Time, What} ->
loop([{Date,Time,What}|ContactsList],EventsList);
print_contacts ->
NewList=lists:sort(ContactsList),
lists:foreach(fun(Elem)->io:format("~p~n", [Elem]) end, NewList),
loop(ContactsList,EventsList);
print_events ->
NewList=lists:sort(EventsList),
lists:foreach(fun(Elem)->io:format("~p~n", [Elem]) end, NewList),
loop(ContactsList,EventsList);
exit ->
io:format("Exiting.~n");
_ ->
io:format("Dude, I don't even know what you're talking about.~n"),
loop(ContactsList,EventsList)
end.
答案 0 :(得分:7)
变量PID
可能设置为除了您在shell中输入的早期行中的<0.65.0>
之外的其他内容:
5> PID = spawn(...).
<0.42.0>
8> PID = spawn(...).
** exception error: no match of right hand side value <0.65.0>
这有效地使产生错误的行像
8> <0.42.0> = <0.65.0>.
会导致“不匹配”错误。
更明显的问题说明:
1> X = 1.
1
2> X = 2.
** exception error: no match of right hand side value 2
至于解决您的问题:您可能希望运行f(PID)
让shell忘记PID
变量,甚至f()
让shell忘记 所有 变量。