[erlang-questions] dumb question from rookie
Tue Mar 6 21:53:23 CET 2012
On 6 Mar 2012, at 16:39, envelopes envelopes wrote:
> On Mar 6, 2012 2:11 AM, "Tim Watson" <watson.timothy@REDACTED> wrote:
> > 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.
> how come ' erl -pa ebin -s mysample_app main 23' works? If the code server has not loaded it yet. The behavior is not consistent.
My mistake I withdraw my original explanation as it was completely wrong. Ryan was correct it is due to the arity of your function. In the 'erl' documentation:
"... If no arguments are provided, the function is assumed to be of arity 0. Otherwise it is assumed to be of arity 1, taking the list[Arg1,Arg2,...] as argument. "
If you want to pass more than one argument on startup, you'll need to use -eval instead: 'erl pa ebin -eval 'prototype_app:start(25, 30)'
My misdirection notwithstanding, the idiomatic way to start an application is to either put it in a release or to pass '-s application start <myapp>' rather than call the module's start/2 function explicitly.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the erlang-questions