如何在Clojure中执行部分应用程序?
我试过:
(dorun (map println ["1" "2" "3" "4"]))这很管用。
(async/send! channel "hello")也很管用。但如果我试图应用部分申请
(dorun (map (async/send! channel) ["1" "2" "3" "4"]))或
(dorun (map #(async/send! channel) ["1" "2" "3" "4"]))或
(apply (partial map (async/send! channel) ["1" "2" "3" "4"]))上面写着
clojure.lang.ArityException: Wrong number of args (1) passed to: immutant.web.async/send!我做错了什么?
发布于 2020-09-24 11:38:02
在密切竞争中,与ML、F#或Haskell等语言不同。
在Clojure中有两种执行部分应用程序的方法:
#(map str %)的(fn [coll] (map str coll))
使用分部的
(partial map str)
当您用比所需的参数更少的参数调用函数时,您将得到ArityException (除非它是一个多重性函数,它可以接受不同数量的参数)。
发布于 2020-09-24 09:55:26
不过,这似乎是可行的:
(dorun (map (partial async/send! channel) ["1" "2" "3" "4"]))有点搞不懂为什么这不起作用
(dorun (map #(async/send! channel) ["1" "2" "3" "4"]))https://stackoverflow.com/questions/64043626
复制相似问题