Assume I have this
(def base ["one" "two" "three"])
I want to convert it to:
1. one 2. two 3. three
1. one \n2. two \n3. three)
join, I am not sure I can append a counter before joining:
(clojure.string/join " \n" base) => "one \ntwo \nthree"
doseq or similar, plus an atom, I do get individual strings but then will have to concatenate later on, something like
(def base ["one" "two" "three"]) (def pos (atom 0)) (defn add-pos [base] (for [b base] (do (swap! pos inc) (str @pos ". " b)))) (let [pos-base (add-pos base)] (clojure.string/join " \n" pos-base)) => "1. one \n2. two \n3. three"
While it works, I don't know if using an atom with a
for statement is he best way to do this, it doesn't look very clojure-esque.
Is there a better way to do this please?