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
Clojure 错误的参数数(2)传递给:core/first_Clojure_Jvm Languages_Arity - Fatal编程技术网

Clojure 错误的参数数(2)传递给:core/first

Clojure 错误的参数数(2)传递给:core/first,clojure,jvm-languages,arity,Clojure,Jvm Languages,Arity,我是Clojure的新手,在迭代数据方面遇到了一些问题 我写的代码如下: (defn save-monthly-targets "Parse Monthly Targets Data and Save" [monthlyTargets] (println "Save Monthly " monthlyTargets) (if (first monthlyTargets) (let [month (first monthlyTargets :month) y

我是Clojure的新手,在迭代数据方面遇到了一些问题

我写的代码如下:

(defn save-monthly-targets
  "Parse Monthly Targets Data and Save"
  [monthlyTargets]
  (println "Save Monthly " monthlyTargets)
  (if (first monthlyTargets)
   (let [month (first monthlyTargets :month)
         year (first monthlyTargets :year)
         name (first monthlyTargets :name)]
        (do
            (println "Calling Save Method" month)
            (users/set-monthly-target month year name)
            (save-monthly-targets (rest monthlyTargets))))))
当我调用函数时:

(save-monthly-targets [
    {:month "May", :year "2021", :target "1200"},
    {:month "May", :year "2016", :target "1200"}
])
我在(if(first monthlyTargets)语句中得到了错误数量的args错误

例外情况是:

ArityException传递给的参数(2)数目错误:core/first clojure.lang.AFn.throwArity

有人能指出这里出了什么问题吗


非常感谢。

由于错误状态,您首先将两个参数传递给
,例如

(first monthlyTargets :month)
当您需要时:

(let [month (:month (first monthlyTargets))
      ...])
可以使用分解结构一次匹配所有值:

(let [{:keys [month year name]} (first monthlyTargets)
      ...])

在错误状态下,您将两个参数传递给
first
,例如

(first monthlyTargets :month)
当您需要时:

(let [month (:month (first monthlyTargets))
      ...])
可以使用分解结构一次匹配所有值:

(let [{:keys [month year name]} (first monthlyTargets)
      ...])