This summer I’ve decided to learn ERLANG, so I’ll publish some posts about this argument.

First of all, I had to install Erlang. On my debian virtual machine, the installation of erlang is a one step operation.

$ sudo apt-get install erlang

nothing more.

Hello World:

using your favourite text editor type the following program and save it as hello.erl

-module(hello).
-export([hello_world/0]).

hello_world() -> io:fwrite("hello, world\n").

 

erlang-logo-darkback

run the erl shell typing the command

$ erl

The above command will launch the erlang shell. Inside the shell compile the hello world program issueing the command:

1> c(hello).
{ok,hello}

then run the compiled hello world program typing the following command into the erl shell:

2> hello:hello_world().
hello, world
ok

Note that each command must end with a dot.

To quit the erlang shell type CTRL-C and then q + enter.

Some info about the hello.erl source code:

Module

Modules are a bunch of functions grouped in a single file, under a single name. Module is always the first attribute of a source file.

Export

Exported functions represent a module’s interface.

exportis used to define what functions of a module can be called by the outside world. It takes a list of functions with their respective arity. The arity of a function is an integer representing how many arguments can be passed to the function.

Functions

Last, there is the implementation of the hello_world function.

Gg1