Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
How can I lazily "clone" a seq in Clojure. Something along the lines of
(let [[s1 s2] (clone-seq s)] ...)
such that s1 and s2 are independent seqs backed by s?
“克隆”一个 seq 对我来说是错误的:在正常的 Clojure 使用中,你会期望 seqs 是不可变的,所以做这样的事情应该是完全可以的:
(let [s1 s s2 s] .....)
如果您的 seq 是可变的或在遍历它们时有某种副作用,那么您可能会因为不同的原因遇到问题:可变的 seq 往往不适合像 Clojure 这样的函数式语言。你会遇到各种奇怪的问题:例如,当你“克隆”一个序列时,你是否希望副作用发生两次?您是否还需要对所有内容进行深度克隆?