Clojure - 传递给 doall 的参数数量错误

Clojure - wrong number of args passed to doall

我目前正在开发一个路线规划机器人,我在向 doall 传递错误数量的参数时遇到错误。

(defn multipleparcels [parcel]
  (let [newparcel (first parcel)
   start (:start newparcel)
   end (:end newparcel)
   delivery (:delivery newparcel)]
  (if (empty? parcel)
    (println "Deliveries Completed")
    (doall (journey start end)
    (if delivery
      (println "Parcel Delivered")
      (println "Parcel Collected")) 
  (multipleparcels (rest parcel))))))

我在下面的函数中使用了这段代码。

(defn robotroute [robot]
  (let [parcels (:parcels robot)
  numstops (:numStops robot)]
  (if (= 1 numstops)
    (oneparcel parcels)
    (multipleparcels parcels))
   (calccost parcels 0)))

然后我通过以下代码使用这些函数:

(def task3parcel [(Parcel. :main-office :r113 false)
                  (Parcel. :r113 :r115 true)])
(def task3robot (Robot. task3parcel 2))
(def task3 (robotroute task3robot)

代码跑通,输出所有正确信息。但是最后我收到以下错误。

CompilerException clojure.lang.ArityException: Wrong number of args (3) passed to: core/doall, compiling:(form-init9046500356350698733.clj:1:12) 

错误是停止我从 运行 到 calccost 代码。任何人都可以看到此错误的来源吗?我试过移动括号等等。但是到目前为止我一直无法使任何工作正常进行。

谁能看出这个错误是从哪里来的?如果是这样,有人有修复它的任何提示吗?

编辑:实施建议的答案。

(defn multipleparcels [parcel]
  (let [newparcel (first parcel)
   start (:start newparcel)
   end (:end newparcel)
   delivery (:delivery newparcel)]
  (if (empty? parcel)
    (println "Deliveries Completed")
    (doall (journey start end))
    (if delivery
      (println "Parcel Delivered")
      (println "Parcel Collected")) 
  (multipleparcels (rest parcel)))))

如错误所述,您将三个参数传递给 doall 而不是预期的一个。这是由于括号放错了。包含 if 的表达式还包含三个参数,而不是预期的一两个。如果你想执行一些副作用作为表达式的一部分,使用 do:

(if (empty? parcel)
    (do
      (println "Deliveries Completed")
      (doall (journey start end)))
      (if delivery
        (println "Parcel Delivered")
        (println "Parcel Collected")))

请注意,您正在丢弃 (journey start end)

返回的评估序列