gpt4 book ai didi

clojure - 为什么映射传感器的结果包含大于 2 个参数?

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

问题在标题中。下面我复制了 map 源的传感器部分:

([f]
(fn [rf]
(fn
([] (rf))
([result] (rf result))
([result input]
(rf result (f input)))
([result input & inputs] ;why?
(rf result (apply f input inputs))))))

这里是 the source of clojure.core 的链接其中包含 map 的定义。

最佳答案

map 可以同时处理多个集合,为每个集合项调用带有参数的映射函数:

(map + [1 2 3] [4 5 6])
=> (5 7 9)

+ 函数为这些集合中的每对值调用一次,例如(+ 1 4)(+ 2 5)(+ 3 6)。非传感器版本看起来像 this .

map 换能器的工作方式相同:

(sequence (map +) [1 2 3] [4 5 6])
=> (5 7 9)

[map] Returns a lazy sequence consisting of the result of applying f tothe set of first items of each coll, followed by applying f to theset of second items in each coll, until any one of the colls isexhausted. Any remaining items in other colls are ignored. Functionf should accept number-of-colls arguments. Returns a transducer whenno collection is provided.

关于clojure - 为什么映射传感器的结果包含大于 2 个参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65371277/

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