Starting with Erlang

by Gregor Uhlenheuer on October 17, 2011

Earlier last week we tried to use ejabberd at work for some testing. As part of that we had to apply a patch to the ejabberd sources in order to add some additional features we wanted to have.

Since there was no one really familiar with programming in Erlang I gave it a shot. After half an hour of reading in google on Erlang syntax we managed to patch the sources and add some additional logging information.

Factorial function

Later at home I tried if I could come up with some basic functionality to kind of get a feeling for the language. A common example when starting to learn a new programming language is to implement the factorial function:

This is the first approach I came up with that uses recursion:

The more interesting way of solving the above problem is to use tail-recursion. That way the temporary processing values are stored in an accumulator argument of the function that is being called. Using tail-recursion it is not necessary that every step of the recursive function has to be hold up in the stack.

References

This post is tagged with programming and erlang