spawn function in erlang using function in another module -
i have been learning erlang past week , going through joe armstrong's pragmatic erlang book . writing code spawn processes , have come across situation have function in module myatom.erl looks
start(anatom,fun) -> case whereis(anatom) of undefined -> pid = spawn(fun), try register(anatom,pid) of true -> true catch error:reason -> reason end; other -> {error,already_defined} end.
there function in module named tloop.erl
loop() -> receive { , no } -> ! { self(), no*4}; other -> void end.
if use start() spawn loop in erlang shell , how can ? following error when do
anatom:start(atomname,tloop:loop).
thanks in advance !
anatom:start(myatom,fun tloop:loop). * 2: syntax error before: ')
you must write following
anatom:start(myatom, fun tloop:loop/0).
you have specify arity (number of arguments) of function, in erlang functions same name different arity not considered same function.
Comments
Post a Comment