Hi! I'm having problem with this code:
-module(sample).
-export([start/0, loop/0]).
start() ->
Pid = spawn(sample, loop, []),
Pid ! {self(), do_sum_of, 1, 2},
receive
{Pid, Msg} ->
io:format("~w~n", [Msg])
end,
Pid ! stop.
loop() ->
receive
{From, sum, First, Second} ->
From ! {self(), First + Second},
loop();
{From, do_sum_of, First, Second} ->
self() ! {From, sum, First, Second};
stop -> true
end.
When I type "sample:start()." the shell hangs, it doesn't return
anything.
Can anybody explain what the problem is and why does this happen?
Can erlang processes send messages to themselves without crashing?
I don't get it?
Where should I insert the loop(); ???