[erlang-questions] Programming Erlang book code question

Aaron Feng <>
Mon Oct 22 00:34:45 CEST 2007

The following code snippet appeared on page 352:

-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
= [])

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

%% 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

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

Thanks in advance,

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

More information about the erlang-questions mailing list