Starting erlang

If you are running a unix system type "erl" or, if you are running on windows start Erlang by clicking on the Erlang start icon. You should see something like this:

$ erl
Erlang R14B (erts- [source] [smp:2:2] [rq:2] [async-threads:0] [kernel-poll:false]
Eshell V5.8.1.1 (abort with ^G)

The ">" prompt means the system is waiting for input. Using Erlang as a calculator

1> 2*6.

Remember to terminate every expression with a DOT followed by a newline!

Editing previous expressions

Previous expressions can be retrieved and edited using simple emacs line editing commands. The most common of these are:
  • ^P fetch the previous line.
  • ^N fetch the next line.
  • ^A Go to the beginning of the current line.
  • ^E Go to the end of the current line.
  • ^D Delete the character under the cursor.
  • ^F Go forward by one character.
  • ^B Go Back by one character.
  • Return Evaluate the current command.

Note: ^X means press Control + X

Try typing Control+P to see what happens.

Compiling your first program

Type the following into a file using your favorite text editor:


fac(0) -> 1;
fac(N) -> N * fac(N-1).

Save the file as test.erl The file name must be the same as the module name.

Compile the program by typing c(test) then run it:

3> c(test).
30> test:fac(20).
4> test:fac(40).

Now go and write some games!

Powered by Erlang Web