Tail-recursive implementation of task9-17. Deleted unused template in iterate fun ction