ex5.1 - tail recursive implementation of toList