[erlang-questions] Escript doc mismatch?
Mon Sep 28 16:17:02 CEST 2009
2009/9/25 Håkan Mattsson <hakan@REDACTED>:
> On Fri, Sep 25, 2009 at 4:52 AM, Michael Richter <ttmrichter@REDACTED> wrote:
>> Quoting from http://www.erlang.org/doc/man/escript.html:
>> The header of an Erlang script differs from a normal Erlang module. The
>>> first line is intended to be the interpreter line, which invokes escript.
>>> However if you invoke escript like this
>>> $ *escript factorial 5*
>>> *the contents of the first line does not matter, but it cannot contain
>>> Erlang code as it will be ignored. *
The #! will not be mandatory on the first line in R13B03.
> The documentation needs to be updated.
The documentation will be updated in R13B03 to clarify pieces
of the header syntax as well as documenting some features that
have been experimental up to now, like the "-d" option. Try
"escript -d factorial 5" to see what I am getting at.
> If the escript has a header, the first line in the file must start with #!.
> If you run the escript by explicitly invoking the escript executable,
> e.g. like "escript factorial 5", the characters after #! on the first line
> are ignored.
> As the header is optional you can in fact "execute" an .erl, .beam or
> .zip file as long as escript can find the main/1 function.
> # cat factorial.erl
> -export([main/1, fac/1]).
> main([String]) ->
> N = list_to_integer(String),
> F = fac(N),
> io:format("factorial ~w = ~w\n", [N,F])
> _:_ ->
> main(_) ->
> usage() ->
> io:format("usage: factorial integer\n"),
> fac(0) -> 1;
> fac(N) -> N * fac(N-1).
> # escript factorial.erl 5
> factorial 5 = 120
> # erlc factorial.erl
> # escript factorial.beam 4
> factorial 4 = 24
> # zip factorial.zip factorial.erl factorial.beam
> adding: factorial.erl (deflated 44%)
> adding: factorial.beam (deflated 29%)
> # rm factorial.erl
> # rm factorial.beam
> # escript factorial.zip 7
> factorial 7 = 5040
More information about the erlang-questions