Last years I’ve had some contact with Ruby, Python or Objective C, but it never has been something more than a first contact, it’s now since assisting to the WeLovePHP talks at Softonic (Barcelona) when my interest for a more serious approach to functional languages has come. After some days reading about functional languages Erlang was the chosen, maybe because the hype of this days because of being used at Facebook, at Amazon, or Whatsapp, or maybe because some of it’s unique characteristics.
Other functional languages I was considering:
- Runs on the JVM, access to java libraries, strongly typed, combines functional language with object oriented.
- Runs on the JVM, access to java libraries.
- Strong static typed.
Some info on Erlang
- OTP, it comes bundled with Erlang
- Web Framework
- Chicago Boss is probably the most important
- We can use relational databases as MySQL through Erlang ODBC, there are also NoSQL databases created with Erlang, as CouchDB or Riak
Erlang can be installed on Mac (my notebook is a Macbook), but I choose installing it on an Ubuntu’s virtual machine that I already have for Laravel testing. In this case it installs really ease using the terminal, in Erlang Solutions there are the instructions for installing on any Operating System.
Ubuntu (probably Debian is the same) Erlang installation:
and only with this, we already have the Erlang interpreter working!
First steps with the Erlang shell
In Erlang variables can be assigned only once
if we try to change it’s value after assign it for the first time, we’ll get an error. Other important thing in Erlang is that the expressions are finished with a dot “.”
The “b()” function will show us the variables already assigned:
A simple function in Erlang would be for example to divide any amount by the half:
And to call the function:
On Erlang shell would be something like this:
Did you test Erlang? Did you choose any different functional language? leave your comment!!!