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.
在 repl 中添加跨向量按预期工作
> (map + [1 2 3] [1 2 3]) (2 4 6)
但是我所拥有的是向量的向量,当我尝试时
> (apply #(map + %) [[1 2 3] [1 2 3]]) ArityException Wrong number of args (2) passed to: user$eval14$fn clojure.lang.AFn.throwArity (AFn.java:437)
如何在向量的向量中添加相应的数字?
这只是您的第一个示例的一步:
user> (apply map + [[1 2 3] [1 2 3]]) (2 4 6)
阅读器宏方法可以使用:
(user=> (apply #(map + % %2) [[1 2 3] [1 2 3]]) (2 4 6)
它要求您知道向量中有多少个向量,并指定每个参数。如果“应用”方法适合您,它将更加灵活,例如:
user=> (apply map + [[1 2 3] [1 2 3] [1 2 3]]) (3 6 9)