I'm getting my feet wet with Clojure and have come up against a problem that I'm not able to resolve on my own:
defn add-list-members
([x] (add-list-members x 0))
([x total]
(println ">>> our list now: " x)
(println ">>> our total now: " total)
(if (= (count x) 2)
(println "outcome 2 : " (+ (first x) (first (rest x)) total)))
(if (= (count x) 1)
(println "outcome 1 : " (+ (first x) total)))
(if (> (count x) 2)
(recur (rest (rest x)) (+ (+ (first x) (first (rest x))) total)))))
This function takes a list of numeric values and simply sums them together. In its present form it does absolutely the right thing. When I lose the print statements, however, and try to use the output, it's returning nil, rather than the evaluated expressions. FYI, I'm developing in Vim with the Leiningen REPL. Any hints about where I'm going wrong or need to adjust my thinking would be most appreciated.
Thanks much in advance.
Aucun commentaire:
Enregistrer un commentaire