[erlang-bugs] Escript and fun local_func/arity runtime error

Fred Hebert mononcqc@REDACTED
Fri Oct 19 23:08:31 CEST 2012


If I recall this error correctly, the fun gets attributed to erl_eval 
during the evaluation rather than the escript itself. You can solve the 
problem by adding a -module declaration to the top of the file, if I 
remember.

Regards,
Fred.

On 12-10-19 4:57 PM, Scott Lystig Fritchie wrote:
> Hi, all.  A colleague noticed this less-than-helpful runtime error when
> using:
>
> * escript
> * "fun local_func/1" syntax
>
> The error message:
>
> % /usr/local/erlang/R15B02.64bit/bin/escript ~/foo
> Starting main....
> escript: exception error: undefined function erl_eval:bar/0
>
> See the example script below.  If your script doesn't have any initial
> output (as the example does), then the error message could lead the
> unsuspecting soul to believe that there's a compile-time error.  Well,
> except that escripts aren't really compiled by default, but ... believe
> that there's a syntax error detected prior to executing main().  But
> main() really is executing.
>
> I don't see fun syntax difference documented in the
> http://www.erlang.org/doc/man/escript.html reference.
>
> Yes, the problem disappears if "-mode(compile)." is added to the script.
>
> -Scott
>
> --- snip --- snip --- snip --- snip --- snip --- snip ---
>
> #!/usr/bin/env escript
> %%! -args_file ./data/ssl_distribution.args_file
> %% -*- mode: erlang;erlang-indent-level: 4;indent-tabs-mode: nil -*-
> %% ex: ft=erlang ts=4 sw=4 et
> %% -------------------------------------------------------------------
>
> main( _) ->
>      io:format("Starting main....\n"),
>      X = fun() -> foo() end,
>      Y = fun bar/0,
>      X(),
>      Y().
>
> foo() ->
>      io:format("Hello, foo!\n").
>
> bar() ->
>      io:format("Hello, bar!\n").
> _______________________________________________
> erlang-bugs mailing list
> erlang-bugs@REDACTED
> http://erlang.org/mailman/listinfo/erlang-bugs




More information about the erlang-bugs mailing list