【问题标题】:Clojure: Wrong number of args (4) passed to: core$restClojure:错误数量的参数(4)传递给:core$rest
【发布时间】:2013-03-21 07:34:21
【问题描述】:

编写一个允许您创建函数组合的函数。这 参数列表应采用可变数量的函数,并创建 一个函数从右到左应用它们。

(fn [& fs]
  (fn [& args]
    (->> (reverse fs)
         (reduce #(apply %2 %1) args))))

http://www.4clojure.com/problem/58

=> (= [3 2 1] ((_ rest reverse) [1 2 3 4]))

clojure.lang.ArityException: Wrong number of args (4) passed to: core$rest

是什么导致了这个错误?我看不到。

【问题讨论】:

    标签: clojure


    【解决方案1】:

    在您使用 apply 时 - 这会将最后一个参数转换为扁平的参数列表,创建一个如下所示的调用:

    (rest 1 2 3 4)

    这可能不是您想要的......并解释了您遇到的错误。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-02-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多