Map 将函数参数映射到Clojure中的嵌套列表
我认为有一种方法可以做到这一点——我就是找不到确切的语法 我想映射一个函数,该函数在一个大小为3的元组列表上使用三个参数。比如:Map 将函数参数映射到Clojure中的嵌套列表,map,clojure,Map,Clojure,我认为有一种方法可以做到这一点——我就是找不到确切的语法 我想映射一个函数,该函数在一个大小为3的元组列表上使用三个参数。比如: (def mylist '((1 2 3)(3 4 5))) (defn myfunc [a b c] (println "this is the first value in this tuple: " a)) (map myfunc mylist) 有人能给我精确的语法吗?你只需要在那里放一对方括号来分解嵌套的列表元素 (defn myfunc [[a
(def mylist '((1 2 3)(3 4 5)))
(defn myfunc [a b c] (println "this is the first value in this tuple: " a))
(map myfunc mylist)
有人能给我精确的语法吗?你只需要在那里放一对方括号来分解嵌套的列表元素
(defn myfunc
[[a b c]]
(println "this is the first value in this tuple: " a))
但是,请注意,由于map
返回一个懒惰的seq,您可能不会得到您在这里想要得到的副作用,除非您使用doall
强制计算seq,或者检查REPL中的seq
文档:是一个非常好的方法,而且这是正确的方法,除非您已经有了要映射的函数
因此,如果myfunc
是外部函数,最好使用apply
而不是编写额外的包装器:
(map (partial apply myfunc) mylist)