6. Recursion and Looping
Activity 6.01: Generating HTML from Clojure Vectors
Solution:
- We'll use
clojure.string
in our solution. It is not strictly necessary, butclojure.string/join
is a very convenient function. Becauseclojure.string
is a standard Clojure namespace, adeps.edn
file containing only an empty map is sufficient for this activity:(ns my-hiccup  (:require [clojure.string :as string]))
- Here are the smaller functions that we'll use later in the main HTML-producing function:
(defn attributes [m] Â (clojure.string/join " " Â Â Â Â Â Â Â Â Â Â Â Â (map (fn [[k v]] Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â (if (string? v) Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â (str (name k) "=\"" v "\"") Â Â Â Â Â Â Â Â Â Â Â ...