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

Popular posts from this blog

ruby on rails - Permission denied @ sys_fail2 - (D:/RoR/projects/grp/public/uploads/ -

c++ - nodejs socket.io closes connection before upgrading to websocket -

java - What is the equivalent of @Value in CDI world? -