listings 3.1 and 3.2. Compiles, but not tested
fun with tail calls