我想生成一个给定项目和计数的相同项目的矢量。这似乎是一个比循环更容易完成的事情。任何让这个功能更紧密/简化的想法?生成长度相同的N的矢量N
;take an object and a nubmer n and return a vector of those objects that is n-long
(defn return_multiple_items [item number-of-items]
(loop [x 0
items [] ]
(if (= x number-of-items)
items
(recur (+ x 1)
(conj items item)))))
>(return_multiple_items "A" 5)
>["A" "A" "A" "A" "A"]
>(return_multiple_items {:years 3} 3)
>[{:years 3} {:years 3} {:years 3}]
这正是我一直在寻找。我探索clojure文件有点找不到我在找什么。 THanks – zach
http://clojure.org/cheatsheet有一个很棒的页面 – hsestupin