Clojure 中预期的向量?
Vector expected in Clojure?
目前我遇到了这个错误。
Parameter declaration symmetrize-body-parts should be a vector,
compiling:(braveclojure/core.clj:41:49)
我的 core.clj 文件
(ns braveclojure.core
(:gen-class))
(def asym-hobbit-body-parts [{:name "head" :size 3}
{:name "left-eye" :size 1}
{:name "left-ear" :size 1}
{:name "mouth" :size 1}
{:name "nose" :size 1}
{:name "neck" :size 2}
{:name "left-shoulder" :size 3}
{:name "left-upper-arm" :size 3}
{:name "chest" :size 10}
{:name "back" :size 10}
{:name "left-forearm" :size 3}
{:name "abdomen" :size 6}
{:name "left-kidney" :size 1}
{:name "left-hand" :size 2}
{:name "left-knee" :size 2}
{:name "left-thigh" :size 4}
{:name "left-lower-leg" :size 3}
{:name "left-achilles" :size 1}
{:name "left-foot" :size 2}])
(defn needs-matching-part? [part]
(re-find #"^left-" (:name part)))
(defn make-matching-part [part] {:name (clojure.string/replace (:name part) #"^left-" "right-")
:size (:size part)})
(defn symmetrize-body-parts
"Expects to see a seq of maps which have a :name and :size"
[asym-body-parts]
(loop [remaining-asym-parts asym-body-parts
final-body-parts []]
(if (empty? remaining-asym-parts)
final-body-parts
(let [[part & remaining] remaining-asym-parts
final-body-parts (conj final-body-parts part)]
(if (needs-matching-part? part)
(recur remaining (conj final-body-parts (make-matching-part part)))
(recur remaining final-body-parts))))))
(defn -main (symmetrize-body-parts asym-hobbit-body-parts))
我在 clojure 应用程序文件夹中使用 lein run
,但它引发了上述错误。关于 symmetrize-body-parts 函数定义的参数括号 []
位置,我已经将不同的东西从文档字符串的上方切换到文档字符串的下方,但无济于事。这是怎么回事?
遵循 here 中的教程。
尝试:
(defn -main []
(symmetrize-body-parts asym-hobbit-body-parts))
目前我遇到了这个错误。
Parameter declaration symmetrize-body-parts should be a vector,
compiling:(braveclojure/core.clj:41:49)
我的 core.clj 文件
(ns braveclojure.core
(:gen-class))
(def asym-hobbit-body-parts [{:name "head" :size 3}
{:name "left-eye" :size 1}
{:name "left-ear" :size 1}
{:name "mouth" :size 1}
{:name "nose" :size 1}
{:name "neck" :size 2}
{:name "left-shoulder" :size 3}
{:name "left-upper-arm" :size 3}
{:name "chest" :size 10}
{:name "back" :size 10}
{:name "left-forearm" :size 3}
{:name "abdomen" :size 6}
{:name "left-kidney" :size 1}
{:name "left-hand" :size 2}
{:name "left-knee" :size 2}
{:name "left-thigh" :size 4}
{:name "left-lower-leg" :size 3}
{:name "left-achilles" :size 1}
{:name "left-foot" :size 2}])
(defn needs-matching-part? [part]
(re-find #"^left-" (:name part)))
(defn make-matching-part [part] {:name (clojure.string/replace (:name part) #"^left-" "right-")
:size (:size part)})
(defn symmetrize-body-parts
"Expects to see a seq of maps which have a :name and :size"
[asym-body-parts]
(loop [remaining-asym-parts asym-body-parts
final-body-parts []]
(if (empty? remaining-asym-parts)
final-body-parts
(let [[part & remaining] remaining-asym-parts
final-body-parts (conj final-body-parts part)]
(if (needs-matching-part? part)
(recur remaining (conj final-body-parts (make-matching-part part)))
(recur remaining final-body-parts))))))
(defn -main (symmetrize-body-parts asym-hobbit-body-parts))
我在 clojure 应用程序文件夹中使用 lein run
,但它引发了上述错误。关于 symmetrize-body-parts 函数定义的参数括号 []
位置,我已经将不同的东西从文档字符串的上方切换到文档字符串的下方,但无济于事。这是怎么回事?
遵循 here 中的教程。
尝试:
(defn -main []
(symmetrize-body-parts asym-hobbit-body-parts))