[erlang-questions] wierd "function not used" problem - code included

deepblue_other cktgatb@REDACTED
Mon Oct 6 00:55:10 CEST 2008


beautiful, it works now. 
Thank you Edwin.
so when I want to use spawn_link() with a named function that function has
to be exported?
same stands for regular spawn()?

just a side question:
once a certain "receive" configuration is set for a process it can never be
changed to another "receive" configuration? it just popped in my head here
when you said that i can inline the error "receive". 

thanks for your time


Edwin Fine wrote:
> 
> Well, there are a couple of problems, but the reason why you get that
> warning is that you have to export a function that you spawn_link to using
> Module/Func/Args syntax, otherwise you would have to
> 
> Handler_process = spawn_link(fun() -> data_process(Socket, []) end),
> 
> The other problem is that your fun Listen_for_errors may as well be
> inline, i.e. you could change this code:
> 
>    %-----------------------------------------------
>    Listen_for_errors =
>    fun() ->
>            io:format("listening started~n"),
>            receive
>                {'EXIT', Pid, Why} ->
>                    io:format("~p exited because:~p", [Pid,Why]);
>                Other                 ->
>                    io:format("Other:~p~n", [Other])
>            end
>    end,
>    Listen_for_errors(),
>     %-----------------------------------------------
> 
>     Handler_process = spawn_link(?MODULE, data_process, [Socket, []]),
> 
> To this:
> 
>     %-----------------------------------------------
>     io:format("listening started~n"),
>     receive
>         {'EXIT', Pid, Why} ->
>             io:format("~p exited because:~p", [Pid,Why]);
>         Other                 ->
>             io:format("Other:~p~n", [Other])
>     end,
>     %-----------------------------------------------
> 
>     Handler_process = spawn_link(?MODULE, data_process, [Socket, []]),
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/wierd-%22function-not-used%22-problem---code-included-tp19826465p19829936.html
Sent from the Erlang Questions mailing list archive at Nabble.com.




More information about the erlang-questions mailing list