全部博文(124)
分类:
2010-07-14 17:57:47
Explaination:
%%1:Erlang程序文件称为module(模块)。第一行就是告诉我们这个模块的名字。
当我们在使用另一个模块中的函数时,我们使用下面的语法
module_name:function_name(arguments).所以:test:fac(10).
意味着我们从test模块中调用一个叫做fac的函数,并且带有参数“10”.
%%2:-export([fac/1]):导出一个带有一个参数的函数fac
2nd Example:
-module(tut1).
-export([fac/1, mult/2]).
fac(1) ->
1;
fac(N) ->
N * fac(N - 1).
mult(X, Y) ->
X * Y.
save it as test.erl
in a directory that’s easy to get to
with the Terminal. Then, from the Terminal, cd
into that
directory and type erl
(which, if everything worked right,
should start the Erlang command-line interpreter). From the interpreter,
run the following commands:
1> c(test).
{ok,test}
2> test:fac(20).
2432902008176640000
3> test:fac(40).
815915283247897734345611269596115894272000000000