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))))
In my example I call this on a mocked-up html page
(head (title "the fortune cookie institute"))
(h1 "Welcome to the Fortune Cookie Institute")
(p "Our fortunes are guaranteed accurate no matter what.")
(p "Like these")
(li "You will gain weight")
(li "Taxes will rise")
(li "Fusion power will always be 50 years away"))
(p "Submit your own fortunes to firstname.lastname@example.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?