[erlang-questions] dumb question from rookie

Tim Watson <>
Tue Mar 6 11:11:14 CET 2012


Hi there,

I'm not sure about this second issue (of the _app module not being loaded in the shell) but I can explain the former. When you run the 'erl' program with -s you are telling the built in 'init' module to run the following module, function with optional arguments. When you pass '-s mysample_app start' you are telling the init module to call that function, but 'init' is a special module, part of the runtime system. Your module isn't special, so the code server hasn't loaded it yet and 'init' can't find it so it is 'undefined' hence the error message. 

Now when you call '-s application start mysample' you're telling 'init' to run application:start(mysample) where application is a module in the 'kernel' application (which is loaded by the runtime system before everything else) and 'mysample' is an atom and the name of the application you're asking to start. The application:start/1 function uses the code server to find the application resource file (mysample.app) and load the required modules and then calls 'mysample_app:start(Type, Args)' for you, which sets up the top level supervisor (process) and so on and so forth.

Hope that makes a bit better sense of it. 

Cheers,

Tim

On 6 Mar 2012, at 07:32, envelopes envelopes wrote:

> Another interesting thing is : though erl -pa ebin -s application start mysample works, mysample_app is not listed in loaded modules from shell command m().
> 
> ???
> 
> 
> 
> On Mon, Mar 5, 2012 at 10:34 PM, envelopes envelopes <> wrote:
> weird.
>  
> Why "erl -pa ebin -s mysample_app start x y" doesn't work, but  "erl -pa ebin -s application start mysample" works, 
> 
> is it a bug in erlang? 
> 
> 
> On Mon, Mar 5, 2012 at 10:21 PM, Ryan Huffman <> wrote:
> It looks like you are trying to call your state function with 0 arguments, but the start function has an arity of 2 (it expects 2 arguments).  You can add 2 dummy arguments or use `-s application start mysample` instead.
> On Monday, March 5, 2012 at 10:07 PM, envelopes envelopes wrote:
> 
>> 
>> I have a sample program generated from rebar
>> 
>> 1. mysample_app.erl
>> 
>> -module(mysample_app).
>> 
>> -behaviour(application).
>> 
>> %% Application callbacks
>> -export([start/2, stop/1, main/1]).
>> 
>> %% ===================================================================
>> %% Application callbacks
>> %% ===================================================================
>> 
>> start(_StartType, _StartArgs) ->
>>     mysample_sup:start_link().
>> 
>> stop(_State) ->
>>     ok.
>> 
>> 
>> main([A]) ->
>> I = list_to_integer(atom_to_list(A)),
>> F = fac(I),
>> io:format("factorial ~w = ~w~n" ,[I, F]),
>> init:stop().
>> fac(0) -> 1;
>> fac(N) -> N*fac(N-1).
>> 
>> 
>> 2. mysample_sup.erl
>> 
>> 
>> -module(mysample_sup).
>> 
>> -behaviour(supervisor).
>> 
>> %% API
>> -export([start_link/0]).
>> 
>> %% Supervisor callbacks
>> -export([init/1]).
>> 
>> %% Helper macro for declaring children of supervisor
>> -define(CHILD(I, Type), {I, {I, start_link, []}, permanent, 5000, Type, [I]}).
>> 
>> %% ===================================================================
>> %% API functions
>> %% ===================================================================
>> 
>> start_link() ->
>>     supervisor:start_link({local, ?MODULE}, ?MODULE, []).
>> 
>> %% ===================================================================
>> %% Supervisor callbacks
>> %% ===================================================================
>> 
>> init([]) ->
>>     {ok, { {one_for_one, 5, 10}, []} }.
>> 
>> 
>> 3) the problem.
>> erl -pa ebin -s mysample_app main 23  ===> worked fine
>> erl -pa ebin -s mysample_app start   ===> crashed on boot.
>> 
>> {"init terminating in do_boot",{undef,[{mysample_app,start,[],[]},{init,start_it
>> ,1,[{file,"init.erl"},{line,1042}]},{init,start_em,1,[{file,"init.erl"},{line,10
>> 22}]}]}}
>> 
>> Crash dump was written to: erl_crash.dump
>> init terminating in do_boot ()
>> 
>> what is the cause ? my erlang is the latest R15.
>> _______________________________________________
>> erlang-questions mailing list
>> 
>> http://erlang.org/mailman/listinfo/erlang-questions
> 
> 
> 
> _______________________________________________
> erlang-questions mailing list
> 
> http://erlang.org/mailman/listinfo/erlang-questions

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


More information about the erlang-questions mailing list