Implement Exercise 2.12 in Scheme