On Mon, Aug 9, 2010 at 9:00 PM, Phil Hagelberg <p...@hagelb.org> wrote:

> On Mon, Aug 9, 2010 at 5:24 PM, Carlos Torres <carlos.torr...@upr.edu>
> wrote:
> > (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))))))
>
> Michael's solution works too, but the problem here is that you're
> calling recur in a way that doesn't make sense. You'd want to replace
> the call to count-zeros with recur rather than calling both, but it's
> not in the tail-position, so it can't be TCO'd.
>
> Just remove the call to recur and it will work, albeit only for lists
> small enough to not blow the stack.
>
> -Phil
>
> --
> 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<clojure%2bunsubscr...@googlegroups.com>
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
>

I totally forgot about how to use recur. Thanks to all for the fast help and
for pointing out my errors, and even suggesting corrections and
alternatives.
This is by far the best mailing list I've ever participated in. As you can
see I'm still learning Clojure, and I've a long way to go to master it.
Again thank you all for your help.

--Carlos

-- 
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