Matthew H
Matthew H

Reputation: 5879

Clojure: Wrong number of args (4) passed to: core$rest

Write a function which allows you to create function compositions. The parameter list should take a variable number of functions, and create a function applies them from right-to-left.

(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

What's causing this error? I can't see it.

Upvotes: 3

Views: 836

Answers (1)

mikera
mikera

Reputation: 106351

It's in your use of apply - this turns the last parameter into a flattened list of parameters, creating a call that looks like:

(rest 1 2 3 4)

Which is presumably not what you intended..... and explains the error you are getting.

Upvotes: 2

Related Questions