I can't solve this problem from the 4clojure site and the errors are not helping much:
;;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))))))
This version of the function shows this error:
java.lang.IllegalArgumentException: Mismatched argument count to recur,
expected: 0 args, got: 2, compiling:(NO_SOURCE_PATH:0)
Why is recur
expecting 0
arguments, however I tried tried this other function:
(fn osc [value & funs]
(let [value value
funs (cycle funs)]
(cons value (lazy-seq
(osc ((first funs) value) (drop 1 funs))))))
But it yiels this:
java.lang.ClassCastException: clojure.lang.LazySeq cannot be cast to clojure.lang.IFn
The only place I can think of where the error is after the lazy-seq
function it seems to be ok syntactically.
Both functions fail on this test
(= (take 3 (__ 3.14 int double)) [3.14 3 3.0])