The sample code for the book "Programming erlang 2nd" of exercise 23