I'm trying to translate some exercises from The Little Schemer into Clojure. The idea is to produce a variant of map that works on collections of nested lists.
(defn treemap [f tr]
(if (list? tr)
(if (empty? tr)
()
(cons (treemap f (first tr))
(treemap f (rest tr))))
(f tr)))
In my example I call this on a mocked-up html page
(html
(head (title "the fortune cookie institute"))
(body
(h1 "Welcome to the Fortune Cookie Institute")
(p "Our fortunes are guaranteed accurate no matter what.")
(br)
(p "Like these")
(ol
(li "You will gain weight")
(li "Taxes will rise")
(li "Fusion power will always be 50 years away"))
(br)
(p "Submit your own fortunes to fortunes@fci.org!")))
In the example I call treemap with a function called SHOUT that substitutes all p tags for h1.
My question is this. My goal here is to show my students that there are things you can do with recursion that you can't do with a for loop. But I know that what I've written here is inadequate for real-world use for a lot of reasons. What's the right way to do recursion on a nested set of collections in Clojure?