[erlang-questions] escript vs erl

Lukas Larsson <>
Mon Mar 7 23:13:10 CET 2011


Importing only means that meaning_of_life/0 will be expanded with it's module added before it i.e. to scriptedmain:meaning_of_life/0, so you still have to compile that module.

Lukas
----- Original Message -----
From: "Andrew Pennebaker" <>
To: 
Cc: "Yurii Rashkovskii" <>, "Erlang Questions" <>
Sent: Sunday, March 6, 2011 10:29:16 PM GMT +01:00 Amsterdam / Berlin / Bern / Rome / Stockholm / Vienna
Subject: Re: [erlang-questions] escript vs erl

That helps with a recursive call within a module. But try this:

scriptedmain.erl:

-module(scriptedmain).
-mode(compile).
-export([meaning_of_life/0]).
-import(lists, [map/2]).

meaning_of_life() -> 42.

main(_) ->
io:format("Main: The meaning of life is ~w~n", [meaning_of_life()]).

test.erl:

-module(test).
-import(scriptedmain, [meaning_of_life/0]).

main(_) ->
io:format("Test: The meaning of life is ~w~n", [meaning_of_life()]).

$ escript scriptedmain.erl
Main: The meaning of life is 42
$ ls *.beam
ls: *.beam: No such file or directory
$ escript test.erl
escript: exception error: undefined function scriptedmain:meaning_of_life/0

(When -mode(compile) is added to test.erl)

$ escript test.erl
escript: exception error: undefined function scriptedmain:meaning_of_life/0
  in function  test_erl__escript__1299__446882__865649:main/1
  in call from escript:run/2
  in call from escript:start/1
  in call from init:start_it/1
  in call from init:start_em/1

Cheers,

Andrew Pennebaker
www.yellosoft.us



On Wed, Feb 23, 2011 at 6:46 PM, Yurii Rashkovskii <> wrote:

> Another option is to specify
>
> -mode(compile).
>
> and in your spawn/3 code use ?MODULE for module
>
>
>
>
> ________________________________________________________________
> erlang-questions (at) erlang.org mailing list.
> See http://www.erlang.org/faq.html
> To unsubscribe; mailto:
>


More information about the erlang-questions mailing list