going through the exercises in the fp-oo book and i'm having trouble with an early exercise to add squares. Here's my code:
(defn square [n]
(* n n))
(defn add-squares [l]
(cond
(nil? l) 0
:else (+ (square (first (l))) (add-squares (rest (l))))))
This example:
(add-squares '(2 2 2 2))
should return
16
but fails with this exception:
ClassCastException clojure.lang.PersistentList cannot be cast to clojure.lang.IFn user/add-squares (NO_SOURCE_FILE:4)
which i guess means i'm trying to pass a function somewhere instead of a list which was expected. Can someone tell me which part of the code is the culprit?
Thanks, James