Errlang: match right side value

I start with Erlang, but I already have problems. 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, I get an error message that I do not 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 is this happening?

+4
source share
1 answer

Perhaps "Pid" is already assigned a specific value, and you are trying to reassign it.

Here's how it works 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 construction of "Pid =" woks is excellent, but the second produces the error message that you described.

I think you have already used Pid in the shell, and it has a specific meaning.

Try "reset" the Pid variable and use it as shown below:

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

, ​​:

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

f(). - f.

+9

Source: https://habr.com/ru/post/1530823/


All Articles