On Wed, Jan 7, 2009 at 5:26 AM, Chouser <chou...@gmail.com> wrote: > As discovered by cmvkk in IRC: > > user=> (count (reduce #(cons %2 %) [0] (range 4601))) > java.lang.StackOverflowError (NO_SOURCE_FILE:0) > > This is because Cons.count() is recursive via RT.count(). Presumably > it's to allow efficient counting of heterogeneous seqs, like: > > user=> (def big-vec (into [] (range 10000000))) ; this is slow > #'user/big-vec > user=> (count (cons :a big-vec)) ; but this is fast > 10000001 > > I've attached a patch that keeps this latter efficiency, but won't > blow the stack for pure chains of Cons's. However, it has > Cons.count() still defer to RT.count() for non-Cons rests. Since I > couldn't find any other class that uses this kind of recursion for > count(), it may be impossible to build a seq that would still cause > Cons.count() to overflow the stack, but I'm not completely certain.
We're all allowed to implement our own IPersistentCollections, but if they break 'count, then that would be a different bug, no? > > An alternative, of course, would be to do a simple loop as > ASeq.count() does, at the cost of the efficient vector counting > demonstrated above. > > If you have comments or questions, don't hesitate or I'll move this to > the issues page! > > --Chouser > > > > -- Venlig hilsen / Kind regards, Christian Vest Hansen. --~--~---------~--~----~------------~-------~--~----~ 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 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 -~----------~----~----~----~------~----~------~--~---