Errlang:没有右手边值的匹配 [英] Errlang: no match of right hand side value

查看:133
本文介绍了Errlang:没有右手边值的匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚开始使用Erlang,但我已经遇到麻烦了。我从一本书中复制了这个例子:

  -module(echo)。 
-export([start / 0,loop / 0])。

start() - >
spawn(echo,loop,[])。

loop() - >
收到
{From,Message} - >
从!消息,
loop()
结束。

但是当我尝试它时会收到一个我不明白的错误:

  31> C(回波)。 
{ok,echo}
32> F。
f
33> Pid = echo:start()。
**异常错误:右侧不匹配值<0.119.0>

为什么会这样?

解决方案

可能的是,Pid已经分配了一些值,而您正在尝试重新分配。



在我的机器上:

  Eshell V5.9.1(中止与^ G)
1> C(回波)。
{ok,echo}
2> F。
f
3> Pid = echo:start()。
< 0.39.0>
4> Pid = echo:start()。
**异常错误:右侧不匹配值<0.41.0>
5>

如您所见,第一个Pid =构建woks很好,但第二个抛出错误



我认为,您已经在shell中使用了Pid,并分配了一些值。



尝试'重置'Pid变量,并使用如下:

  8> F(PID)。 
ok
9> PID。
* 1:变量'Pid'是未绑定的
10> Pid = echo:start()。
< 0.49.0>

或者您可以通过使用这样的结构来忘记所有变量:

  13> F()。 
ok
14> Pid = echo:start()。
< 0.54.0>

注意使用的 f()。 - 不只是 f。


I'm getting started with Erlang, but I'm already in troubles. I copied this example from a book:

-module(echo).
-export([start/0, loop/0]).

start() ->
    spawn(echo, loop, []).

loop() ->
    receive
        {From, Message} ->
            From ! Message,
            loop()
    end.

But when I try it I get an error I don't understand:

31> c(echo).          
{ok,echo}
32> f.      
f
33> Pid = echo:start().
** exception error: no match of right hand side value <0.119.0>

Why does this happen?

解决方案

Probably, 'Pid' has some value assigned already and you're trying to re-assign it.

Here is how it behaves on my machine:

Eshell V5.9.1  (abort with ^G)
1> c(echo).
{ok,echo}
2> f.
f
3> Pid = echo:start().
<0.39.0>
4> Pid = echo:start().
** exception error: no match of right hand side value <0.41.0>
5>

As you can see, the first 'Pid = ' construction woks fine, but the second one throws error message you described.

I think, you used Pid in the shell before already and it has some value assigned.

Try to 'reset' Pid variable and use it like following:

8> f(Pid).
ok
9> Pid.
* 1: variable 'Pid' is unbound
10> Pid = echo:start().
<0.49.0>

Or you can forget all variables by using such a construction:

13> f().
ok
14> Pid = echo:start().
<0.54.0>

Pay attention on used f(). - not just f.

这篇关于Errlang:没有右手边值的匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆