[erlang-questions] and the argument is...?
Sun May 10 10:21:20 CEST 2015
On 2015-05-10 08:24, Peter J Etheridge wrote:
> -module(fac/1). % from p.165 of joe's book
> I = list_to_integer(atom_to_list(A)),
> F = fac(I),
> io:format("factorial ~w = ~w~n", [I,F]),
> fac(0) -> 1;
> fac(N) -> N*fac(N-1).
I ran the code via:
erl -s fac main ...
on the command line and it appears to work fine. But I have to say that
it is probably simpler to compile using erlc on the command line and run
the resulting .beam file interactively in the erlang shell (see the erl
command) as you can then simplify the code into:
fac(0) -> 1;
fac(N) -> N*fac(N-1).
This allow you to call fac:fac(...) directly, multiple times, with
different input as well as many other things ...
The erlang shell is also much more convenient if you need to pass more
complex arguments or if you want to pass the result of previously
executed commands as input.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the erlang-questions