gpt4 book ai didi

clojure - 通过 recur 调用时 conj 不添加到向量末尾

转载 作者:行者123 更新时间:2023-12-01 19:53:55 26 4
gpt4 key购买 nike

为什么这一直问 jack 是否想要一杯茶而不是其他父亲。

(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"])

最佳答案

因为 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 .

关于clojure - 通过 recur 调用时 conj 不添加到向量末尾,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29598993/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com