musings of a Software Developer

Seven languages in seven weeks , my solutions for Erlang day 1


In this article I will present my solutions for the first chapter on erlang in the book Seven Languages in Seven Weeks: A Pragmatic Guide to Learning Programming Languages (Pragmatic Programmers).

Erlang is new for me, but it is based on prolog which is also included in the seven languages. The first chapter just introduces erlang, talks a bit about it strongpoints and weaknesses and introduce you to the syntax and basic functions.

The first exercise is to write a word counter that uses recursion to count the words in a string. For now I assumed that words are only separated by a space, character 32. Here is my solution:

I needed quite some time and googling to come up with the solutions, mainly because I’m not used to the prolog/erlang style of programming.

The second exercise was a lot easier, you had to write a program that counts to ten, using recursion.

This was quite simpel, I just used pattern matching to stop at 10, off course the order of the statements becomes important here if you switch the last lines it will probably count to infinity.

Last exercise was to write a function that uses pattern matching to printout a succes or an error message.

Leave a Reply

Required fields are marked *.