我无法从4clojure站点解决此问题,并且错误没有太大帮助:
;;Write an oscillating iterate: a function that takes an initial value and a
;;variable number of functions. It should return a lazy sequence of the functions
;;applied to the value in order, restarting from the first function after it hits the end.
(fn osc [value & funs]
(loop [value value
funs (cycle funs)]
(cons value (lazy-seq
(recur ((first funs) value) (drop 1 funs))))))
此版本的函数显示此错误:
java.lang.IllegalArgumentException: Mismatched argument count to recur,
expected: 0 args, got: 2, compiling:(NO_SOURCE_PATH:0)
为什么recur
期待0
参数,但是我尝试了这个其他功能:
(fn osc [value & funs]
(let [value value
funs (cycle funs)]
(cons value (lazy-seq
(osc ((first funs) value) (drop 1 funs))))))
但它产生了这个:
java.lang.ClassCastException: clojure.lang.LazySeq cannot be cast to clojure.lang.IFn
我能想到的唯一地方错误在lazy-seq
函数之后,它在语法上似乎没问题。
这两个函数在这个测试中都失败了
(= (take 3 (__ 3.14 int double)) [3.14 3 3.0])