Exercises in this lecture  previous -- Keyboard shortcut: 'p'        Go to the slide, where this exercise belongs -- Keyboard shortcut: 'u'  

Exercise 2.12
Higher-order functions in 'Functional Programming Languages' **


A number of short papers appeared in 1996 in the journal Computing Surveys (as part of the 50 years celebration of the ACM) - among them a paper titled 'Functional Programming Languages' by Benjamin Goldberg. Take a brief look at the paper - in particular the section about 'Higher-order functions'. It is an easy paper to read.

Rewrite the functions prod, fac, and power in Scheme, and give them a try. Do you get the results you would expect? If not, carry out the necessary corrections.

The product operator is introduced to improve the recursive factorial function, suposedly in the direction of iteration. However, the paper is not successful in that respect. Why?

Write an iterative, memory efficient, tail-recursive version of prod in Scheme.


Solution