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").
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
Just a question: why not Elixir that uses the same Erlang VM but is way less complicated?
I studied functional programming at University (when I was young, sigh!) and then I never used them.
I discovered Erlang few months ago, running one of the more scalable, reliable mqtt broker I ever seen (despite it is in 0.x stage): emqtt.io.
About the ELixir, I can say I discovered it a few minutes ago.
Gg1
Here is where I heard about Elixir: http://www.alexbottoni.com/2015/05/05/un-primo-contatto-con-elixir/
It’s written in Italian but I hope you don’t mind 😉
@Luca: In what sense is Elixir “way less complicated” than Erlang?
Hi Michel,
probably “complicated” is the wrong word. What I meant to say is that its syntax is a little strange to me.