Learning a new Er lang…

November 30, 2008

I’ve had the itch to learn a different language for a good while now, I thought about picking up Ruby or Python & saw no personal practical use for them, plus the fact that I’d still be stuck in the same paradigm just with different a syntax.

Whilst surfing a three weeks ago I came across a piece of code of which I had never encountered (I can’t recall where I stumpled upon this right now).

Being naturally curious my fingers sent me to Google, quickly followed by Amazon, the day after I had Joe Armstong’s “Erlang Programming” book. I have to say I cant remember the last time reading a techie book threw me into boughts of laughter chapter after chapter, not because it a helarious book but purely down to how the language solved problems.

list([Item|Items]) -> io:format("~p~n", [Item]), list(Items);
list([]) -> [].

As apposed to a ‘C type language’ which would look like:-

foeach($items as $item) {
print($item ."\n");

I’ve been playing with Erlang for three weeks now and am impressed, at the moment I’m playing with a twitter API, basically retrieving public & user specific twitters. Once I get my head around HTTP authentication with Erlang i’ll extend it further utilising a few other systems tying them together to track and send messages over multiple networks.

For now I’ll show you a little bit of code that will store the body of a HTTP response:
{ok,{_Status,_Head,Body}} = http:request("http://www.google.co.uk").

Firstly this is a piece of pattern matching one of the main princples of Erlang, on the right we retrieve a Tuple which we match to the left hand pattern, if the pattern is matched the response body is stored in Body.The pattern reads as:

“Our http:request from Google must match a Tuple containing the atom ‘ok’ preceeded by a Tuple containing 2 items we don’t care (_Status,_Head) and 1 which we’ll store in the item body.”

The other items (Status,_Head) are dismissed indicated by the prefixed underscore, removing the prefix would mead Status & Head would also be assign values.

It’s this pattern matching that makes Erlang fun to play with, you can quite easily find yourself getting losting in tuples, lists & atoms, at the moment I tend to find myself playing around with matching patterns within erl (Erlangs shell) storing the needed values.

In my opinion reading Joe Armstrong’s “Software for a Concurrent World” is a must, I’m still going through it now & find the reference in the appendix an constant help, I also found Kevin Smith’s screencast’s “Erlang in practice” an excellent help too, especially in regards to the TDD using eunit, I still have a great deal to learn in regards to TDD with Erlang, mainly down to me hacking around & trying to get my self familiar with the syntax.

There are also a number of cool tool, some of which I have yet to play with, mnesia (Erlang DBMS) is definately on my to play with list, along with Yaws (erlang based webserver) & Erlyweb (web ramework).



  1. […] I as mentioned in a previous post I’ve had the itch to learn a new language. I started off by reading Programming Erlang […]

  2. […] I as mentioned in a previous post I’ve had the itch to learn a new language. I started off by reading Programming Erlang […]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: