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

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -