A simple one pass "load and go" Erlang scripting interface
Joe Armstrong
Robert Virding
3 - April - 2001
> ./factorial abc Usage factorial <Int> > ./factorial 100 factorial 100 = 9332621544394415268169923885626670049071596826438162146859 29638952175999932299156089414639761565182862536979208272237582511852109168 64000000000000000000000000The factorial script is as follows:
#!/usr/bin/env escript %% %% %% Usage: %% factorialmain([X]) -> case (catch list_to_integer(X)) of {'EXIT', _} -> usage(); J -> N = fac(J), io:format("factorial ~w = ~w~n",[J, N]) end; main(_) -> usage(). usage() -> io:format("Usage factorial ~n"). fac(0) -> 1; fac(N) -> N * fac(N-1).
The default mode of escript is to interpret the code. By adding the attribute:
-mode(compile).
Will cause the code in the script to be compiled, instead of interpreted. Note that for many scripts interpreting the code is much faster than compiling the code.