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.<div>
<br></div><div>Thanks,</div><div>Jared<br><div><br></div><div><br><br><div class="gmail_quote">On Fri, Oct 19, 2012 at 3:08 PM, Fred Hebert <span dir="ltr"><<a href="mailto:mononcqc@ferd.ca" target="_blank">mononcqc@ferd.ca</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">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.<br>

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