On Mon, Aug 9, 2010 at 5:24 PM, Carlos Torres <carlos.torr...@upr.edu> wrote:
> Hi to everyone,
> I'm trying to create a function that takes a simple list and returns the
> number of zeros in the list.
> So I'm assuming that they will enter a list containing only numbers.
> This is what I have so far, but it only works when the list empty. Can
> somebody tell me what I'm missing?
> (defn count-zeros
>   "Returns the numbers of zero in a simple sequence of numbers"
>   [list1]
>   (cond
>     (empty? list1) 0
>     (not (zero? (first list1))) 0
>     :else
>     (recur (+ 1 (count-zeros (rest list1))))))
> --Carlos

I believe your second codition break the recursion but in general,
don't write your own unless you are learning how to write recursive
code in clojure. this is textbook filter then count or foldl(i.e.
reduce).

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to