Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/clojure/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Map 将函数参数映射到Clojure中的嵌套列表_Map_Clojure - Fatal编程技术网

Map 将函数参数映射到Clojure中的嵌套列表

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

我认为有一种方法可以做到这一点——我就是找不到确切的语法

我想映射一个函数,该函数在一个大小为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 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)