I am trying to start a simple process that will loop and receive addition or subtraction commands to calculate them. However when I register my process I try to print it with a whereis() to see if it is up and running and it returns undefined. Any idea what is going wrong?
-module(math).
-export([start/0, math/0]).
start() -> register(myprocess, spawn(math, math(), [])).
math() ->
io:format("~p~n", [whereis(myprocess)]),
receive
{add, X, Y} ->
io:format("~p + ~p = ~p~n", [X,Y,X+Y]),
math();
{sub, X, Y} ->
io:format("~p - ~p = ~p~n", [X,Y,X-Y]),
math()
end.
Here is my input in the erl shell as well:
Eshell V12.0 (abort with ^G)
1> c(math).
{ok,math}
2> math:start().
undefined
math()before theregisterbecause it's being passed as a parameter tospawnand that in turn toregister. I suspect the brackets aftermathin thespawncall are not supposed to be there. - Alnitakstart() -> register(myprocess, spawn(math, math(), [])).bystart() -> register(myprocess, spawn(math, math, [])).and it should work fine. - Brujo Benavides'or undefined if the name is not registered'- Joel