Clojure-传递给doall的参数数目错误
我目前正在开发一个路径规划机器人,向doall传递错误数量的参数时出错Clojure-传递给doall的参数数目错误,clojure,shortest-path,Clojure,Shortest Path,我目前正在开发一个路径规划机器人,向doall传递错误数量的参数时出错 (defn multipleparcels [parcel] (let [newparcel (first parcel) start (:start newparcel) end (:end newparcel) delivery (:delivery newparcel)] (if (empty? parcel) (println "Deliveries Completed")
(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
传递三个参数,而不是预期的参数。这是由于括号放错了位置。containingif
表达式还包含三个参数,而不是预期的一个或两个参数。如果要在表达式中执行某些副作用,请使用do
:
(if (empty? parcel)
(do
(println "Deliveries Completed")
(doall (journey start end)))
(if delivery
(println "Parcel Delivered")
(println "Parcel Collected")))
请注意,您正在丢弃由
(旅程开始-结束)
返回的已计算序列。嗨,Lee,我已尝试更改括号,但是现在我的if语句出现了一个问题,它指出传入的参数太多。我猜这是括号位置的另一个问题。我已经以editHi Lee的身份添加了我的新代码,谢谢,我已经成功地删除了那个错误。然而,我现在得到一个空指针异常