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 "\"") ...