exer 1.46 - yay functions which take functions and create functions and recurse!
improvements after viewing Bill-the-Lizard's answer