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

Jared Morrow jared@REDACTED
Sat Oct 20 00:00:03 CEST 2012


I was the "colleague" who first hit the issue and was stumped.  It is fixed
now with the -mode(compile) setting, so chalk this "bug" up to a
documentation bug possibly or a "better error should be printed" bug.  I
had 7 or 8 `fun F/A` callouts in the escript and only the first one in call
chain showed the `escript: exception error: undefined function ...` error
which led me down a typo, syntax, etc., etc. rabbit hole.

Thanks,
Jared



On Fri, Oct 19, 2012 at 3:08 PM, Fred Hebert <mononcqc@REDACTED> wrote:

> 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<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<http://erlang.org/mailman/listinfo/erlang-bugs>
>>
>
> ______________________________**_________________
> erlang-bugs mailing list
> erlang-bugs@REDACTED
> http://erlang.org/mailman/**listinfo/erlang-bugs<http://erlang.org/mailman/listinfo/erlang-bugs>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-bugs/attachments/20121019/35dc4dff/attachment.htm>


More information about the erlang-bugs mailing list