[erlang-questions] escript exception error, undefined function, why can't use fun in escript script?

lib nl <>
Sun Aug 6 13:44:58 CEST 2017


On Linux Mint 18.2 + Erlang/OTP 20.0, there are two escript scripts: a and b.

1.      a
#!/usr/bin/env escript
main(_) ->
       L = lists:map(fun(N) -> 2*N end, lists:seq(1,10)),
       io:format("~p~n", [L]).

2.      b
#!/usr/bin/env escript
main(_) ->
       L = lists:map(fun f2/1, lists:seq(1,10)),
       io:format("~p~n", [L]).

f2(N) -> 2 * N.

$ chmod u+x a
$ ./a

$ chmod u+x b
$ ./b
escript: exception error: undefined function erl_eval:f2/1

So why can't use fun in escript script? Is this a limitation or known issue? Are there any references that can give more info regarding this behavior? Thanks!


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20170806/4d2066c8/attachment.html>

More information about the erlang-questions mailing list