Erlang, day one

So today I start the Erlang chapter of Bruce Tate's Seven Languages in Seven Weeks. Erlang is a language whose main strength lies in its support for concurrent programming. Created at Ericsson by Joe Armstrong in 1986, it is a pretty mature language and has been used to create software that needs to run reliably and has a lot of moving parts. Like other languages featured in this book so far it uses the Actor model for concurrency, and its VM is said to be able to very comfortably handle hundreds of thousands of erlang's lightweight processes. It also has an interesting approach to fault tolerance with its 'let it crash' philosophy and has a robust system for monitoring and if necessary restarting failed erlang processes.

My only previous exposure to erlang is in the form of Apache CouchDB, which I have used in a few projects and is written in erlang. One thing I learned that i hadn't heard before is that erlang traces its roots to Prolog, and this shows in the syntax. It basically started out as a prolog system that evolved into it own language and platform.

The intro in day one was quite painless, introducing some basic concepts and syntax, with a few quick exercises at the end. I found it pretty straightforward, maybe because of the similarity to prolog and i was able to go through the first section quite quickly. Here are my solutions to the problems posed. Erlangs documentation was also pretty readable :-) (I'm looking at you scala...)

There isn't much to highlight here, other than the strong similarity to prolog in problem solving via pattern matching. I quite like being able to decompose a function like printRet to handle the different kinds of input expected. It is also quite easy to add a case that captures anything that doesn't match the first two. I cheated a tiny bit on the second question and wrote a function that counts to any number you give it, didn't really see a simpler solution if it is hardcoded to 10. Another thing to note is that erlang makes you define you functions in modules and explicitly which ones you want available in other namespaces (via export).

Anyway, I'm looking forward to playing with erlang and its concurrency model and robust vm! I need to think of fun concurrent things to do with it!

Posted On 17th June 2011

comments powered by Disqus