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:
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:
Or you can forget all variables by using such a construction:
Pay attention on used f(). - not just f.