Erlang运行时错误

0 erlang compiler-errors

我正在处理一个erlang程序并得到一个奇怪的运行时错误.知道为什么吗?谢谢!

错误是(成功编译程序后):

   8> PID = spawn(planner,start,[]).
   ** exception error: no match of right hand side value <0.65.0>
   9> 
Run Code Online (Sandbox Code Playgroud)

这是该计划:

-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.
Run Code Online (Sandbox Code Playgroud)

ndi*_*dim 7

该变量PID可能设置为其他内容,但是<0.65.0>来自您在shell中输入的早期行:

5> PID = spawn(...).
<0.42.0>
8> PID = spawn(...).
** exception error: no match of right hand side value <0.65.0>
Run Code Online (Sandbox Code Playgroud)

这有效地使产生错误的线条像

8> <0.42.0> = <0.65.0>.
Run Code Online (Sandbox Code Playgroud)

这将导致"不匹配"错误.

更明显的问题说明:

1> X = 1.
1
2> X = 2.
** exception error: no match of right hand side value 2
Run Code Online (Sandbox Code Playgroud)

至于解决你的问题:你可能想要让f(PID)shell忘记PID变量,甚至f()让shell忘记所有变量.