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.
给定以下顺序:
seq = ( (a b) ( (c d) a ) a ) (replace a z seq) => ( (z b) ( (c d) z ) z )
如何使用惰性序列和尾递归来做到这一点?
看起来您想要遍历数据结构。
user=> (def s '((:a :b)((:c :d) :a) :a)) #'user/s user=> (use 'clojure.walk) nil user=> (prewalk #(if (= :a %1) :z %1) s) ((:z :b) ((:c :d) :z) :z)
编辑:或者,如果您确实只需要更换,更简单
user=> (prewalk-replace '{a z} '((a b) ((c d) a))) ((z b) ((c d) z))