この特定の機能が期待どおりに機能しない理由を理解しようとしています。エラー メッセージから、アキュムレータ用の空のベクトルを作成する方法に関係があると思われます。
2 要素ベクトルのシーケンスを返す単純な関数があります。
(defn zip-with-index
"Returns a sequence in which each element is of the
form [i c] where i is the index of the element and c
is the element at that index."
[coll]
(map-indexed (fn [i c] [i c]) coll))
それはうまくいきます。別の関数で使用しようとすると問題が発生します
(defn indexes-satisfying
"Returns a vector containing all indexes of coll that satisfy
the predicate p."
[p coll]
(defn accum-if-satisfies [acc zipped]
(let [idx (first zipped)
elem (second zipped)]
(if (p elem)
(conj acc idx)
(acc))))
(reduce accum-if-satisfies (vector) (zip-with-index coll)))
コンパイルはできますが、使用しようとするとエラーが発生します。
user=> (indexes-satisfying (partial > 3) [1 3 5 7])
ArityException Wrong number of args (0) passed to: PersistentVector
clojure.lang.AFn.throwArity (AFn.java:437)
ここで何が問題なのかわかりません。また、私がやろうとしていることをもっと 'Clojure 風に' 行う方法があれば、それについても聞きたいです。