Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- loop() ->
- receive
- {From, Msg} ->
- if
- is_integer(Msg), Msg >= 0 ->
- From ! {self(), factorial(Msg)},
- loop();
- Msg == stop ->
- From ! {self(), papa};
- true ->
- From ! {self(), Msg},
- loop()
- end
- end.
- start() ->
- spawn(echo, loop, []).
- send(Pid, MSG) ->
- B = is_process_alive(Pid),
- if
- B ->
- Pid ! {self(), MSG},
- receive
- {Pid, Msg} ->
- io:format("~w~n", [Msg])
- end;
- true ->
- io:format("Watek nie zyje~n")
- end.
- factorial(N) ->
- if
- N == 0 -> 1;
- N > 0 -> N * factorial(N-1)
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement