为什么这会一直问杰克他是否想要一杯茶而不是其他父亲。
(defn tea-anyone
"Ask 'fathers' if they would like some tea"
[fathers]
(loop [asks 0 to-ask fathers]
(let [[father & others] to-ask]
(println (str "Cup of tea " father "? "))
(if (> asks 6)
(println (str father ": All right then!"))
(recur (inc asks) (conj others father))))))
(tea-anyone ["Jack" "Ted" "Dougle"])
答案 0 :(得分:3)
因为others
不是矢量。亲眼看看:
(let [[f & o :as a] [1 2 3 4]]
(println f)
(println o)
(println a)
(println (type f))
(println (type o))
(println (type a))
(println (type (conj o 5)))
(println (type (conj a 5))))
要达到您想要的效果,您可以使用cycle
。
答案 1 :(得分:2)
试试这个:
(recur (inc asks) (conj (vec others) father))