<html>
<head>
<meta content="text/html; charset=windows-1252"
http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<div class="moz-cite-prefix">On 2015-05-10 08:24, Peter J Etheridge
wrote:<br>
</div>
<blockquote
cite="mid:3f13067c82b13e494226b8e5d7ebba994dfdda20@webmail.iinet.net.au"
type="cite"><span
style="color:rgb(51,51,51);line-height:19.2000007629395px;">-module(fac/1).
% from p.165 of joe's book</span><br
style="color:rgb(51,51,51);line-height:19.2000007629395px;">
<span style="color:rgb(51,51,51);line-height:19.2000007629395px;">-export([main/1]).</span><br
style="color:rgb(51,51,51);line-height:19.2000007629395px;">
<span style="color:rgb(51,51,51);line-height:19.2000007629395px;"> main([A])-></span><br
style="color:rgb(51,51,51);line-height:19.2000007629395px;">
<span style="color:rgb(51,51,51);line-height:19.2000007629395px;"> I
= list_to_integer(atom_to_list(A)),</span><br
style="color:rgb(51,51,51);line-height:19.2000007629395px;">
<span style="color:rgb(51,51,51);line-height:19.2000007629395px;"> F
= fac(I),</span><br
style="color:rgb(51,51,51);line-height:19.2000007629395px;">
<span style="color:rgb(51,51,51);line-height:19.2000007629395px;"> io:format("factorial
~w = ~w~n", [I,F]),</span><br
style="color:rgb(51,51,51);line-height:19.2000007629395px;">
<span style="color:rgb(51,51,51);line-height:19.2000007629395px;"> init:stop().</span><br
style="color:rgb(51,51,51);line-height:192000007629395px;">
<br style="color:rgb(51,51,51);line-height:19.2000007629395px;">
<span style="color:rgb(51,51,51);line-height:19.2000007629395px;"> fac(0)
-> 1;</span><br
style="color:rgb(51,51,51);line-height:19.2000007629395px;">
<span style="color:rgb(51,51,51);line-height:19.2000007629395px;"> fac(N)
-> N*fac(N-1).</span></blockquote>
Replace <br>
-module(fac/1). <br>
with <br>
-module(fac).<br>
<br>
I ran the code via:<br>
<br>
erl -s fac main ...<br>
<br>
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:<br>
<br>
<span style="color:rgb(51,51,51);line-height:19.2000007629395px;">-module(fac).</span><br
style="color:rgb(51,51,51);line-height:19.2000007629395px;">
<span style="color:rgb(51,51,51);line-height:19.2000007629395px;">-export([fac/1]).</span><span
style="color:rgb(51,51,51);line-height:19.2000007629395px;"></span><br>
<br style="color:rgb(51,51,51);line-height:19.2000007629395px;">
<span style="color:rgb(51,51,51);line-height:19.2000007629395px;"> fac(0)
-> 1;</span><br
style="color:rgb(51,51,51);line-height:19.2000007629395px;">
<span style="color:rgb(51,51,51);line-height:19.2000007629395px;"> fac(N)
-> N*fac(N-1).</span> <br>
<br>
This allow you to call fac:fac(...) directly, multiple times, with
different input as well as many other things ...<br>
<br>
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.<br>
</body>
</html>