[erlang-questions] Programming Erlang book code question

Aaron Feng aaron.feng@REDACTED
Mon Oct 22 00:34:45 CEST 2007


The following code snippet appeared on page 352:

-module(sellaprime_supervisor).
-behaviour(supervisor). % see erl -man supervisor
-export([start/0, start_in_shell_for_testing/0, start_link/1, init/1]).

start() -> spawn(fun() ->
                        supervisor:start_link({local,?MODULE}, ?MODULE, _Arg
= [])
                        end).

start_in_shell_for_testing() ->
  {ok, Pid} = supervisor:start_link({local,?MODULE}, ?MODULE, _Arg = []),
  unlink(Pid).

%% rest of the code intentionally left out

Question 1:

What's the benefit to call spawn for supervisor:start_link in the start()
function?  Why not just call supervisor:start_link without the spawn?
Doesn't supervisor:start_link already spawn and register the process
already?

Question 2:

What's the benefit for start_in_shell_for_testing() function?  Why not just
call start() function when testing in the shell?  I know what the
unlink(Pid) does, but why unlinking it?  What if unlink it left out?

Question 3:

I don't understand _Arg = [] ?  why not just pass [] as the last argument of
start_link?

Thanks in advance,

Aaron
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20071021/31de8572/attachment.htm>


More information about the erlang-questions mailing list