gpt4 book ai didi

Clojure 线程宏

转载 作者:行者123 更新时间:2023-12-01 07:09:40 25 4
gpt4 key购买 nike

我不确定这是发布的最佳地点,但为什么 2) 不起作用?线程宏不是将 seq 的结果传递给 (map str) ?

;; 1
(map str (seq (str (* 8 8)))) -> ("6" "4")

;; 2
(defn a [x y]
(-> (* x y)
str
seq
(map str)))


(a 8 8) -> Don't know how to create ISeq from: clojure.core$str

最佳答案

您正在使用 thread-first宏,将每个表单作为下一个的第二项插入,如下所示:

(-> (* x y) str seq (map str))
(-> (str (* x y)) seq (map str))
(-> (seq (str (* x y))) (map str))
(map (seq (str (* x y))) str)

您要的是 thread-last宏:
(defn a [x y]
(->> (* x y) str seq (map str)))

(a 8 8) ;=> ("6" "4")

关于Clojure 线程宏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37062642/

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