This is a command line program, you can directly enter expressions in it for calculation, for example, a simple:
quote
Erlang R15B01 (erts-5.9.1) [smp:4:4] [async-threads:0]
Eshell V5.9.1 (abort with ^G)
1> 100+300.
400
2>
Eshell V5.9.1 (abort with ^G)
1> 100+300.
400
2>
Note that you enter "." at the end of the statement to indicate completion, and press Enter to start calculating the result, as shown above.
Next, we use Notepad to write a factorial Erlang program:
quote
-module (test).
-export ([fac / 1]).
fac (0) -> 1;
fac (N) -> N * fac (N-1).
-export ([fac / 1]).
fac (0) -> 1;
fac (N) -> N * fac (N-1).
This program defines a module called "test" that contains a function called fac that takes 1 parameter.
According to Erlang's convention, the file name must be the same as the module name, so we save this file as "test.erl", and save the file in the D:\test1 directory.
The question is, how to run this file? Using the cd method, change Erlang's current working path:
quote
2> cd("d:/test1").
d:/test1
ok
3>
d:/test1
ok
3>
Then compile the program file just now:
quote
ok
3> c(test).
{ok,test}
4>
3> c(test).
{ok,test}
4>
Note that the parameter of the compilation command c can be written with the name of the module defined in the file, and double quotation marks are not required. After compilation, the file "test.beam" will be generated under the current working directory.
Then, the methods in the module can be executed:
quote
4> fac(10).
** exception error: undefined shell command fac/1
5> test:fac(10).
3628800
6>
** exception error: undefined shell command fac/1
5> test:fac(10).
3628800
6>
Note that a custom "external module" is used here, so you need to specify the module name: method name (parameter) when executing.
What if the compiled program needs to be reloaded next time?
It's very simple, just use l (module name), as in the following example:
quote
6> l(test).
{module,test}
7> test:fac(4).
24
8>
{module,test}
7> test:fac(4).
24
8>
So far, the whole process of installing, writing, compiling, running, and loading an Erlang language program is completed. The entry process is still very simple, right?
Reference: http://www.cnblogs.com/bluedoctor/archive/2012/09/03/2668053.html