Erlang运行时错误

发布于 2024-11-01 01:20:52 字数 1117 浏览 1 评论 0原文

我正在开发一个 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.

I'm working on an erlang program and getting a strange runtime error. Any idea why? Thanks!

The errors are (after compiling the program successfully):

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

This is the program:

-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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

韵柒 2024-11-08 01:20:52

变量 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>

这实际上使生成错误的行成为其他内容这样

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 忘记所有变量。

The variable PID is probably set to something else but <0.65.0> from an earlier line you entered in the shell:

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

This effectively makes the line which generates the error something like

8> <0.42.0> = <0.65.0>.

which will result in a "no match" error.

More obvious illustration of the issue:

1> X = 1.
1
2> X = 2.
** exception error: no match of right hand side value 2

As to solving your issue: You probably want to run f(PID) to have the shell forget just the PID variable, or even f() to have the shell forget ALL variables.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文