To me, the current behavior of nth makes sense because I know that the way you traditionally write nth on a seq / linked list is to call rest n times and then call first. Since Clojure's rest and first on nil (or the empty list) return nil, then I would expect nth to return nil when called on an empty sequence for any n. In other words, the behavior of nth makes complete sense in the context of first and rest returning nil (which is different from the philosophy of languages like Scheme, but is a feature people get along with just fine in Clojure).
I also think it makes perfect sense for rand-nth to throw an error on an empty collection. That's because the first step is it needs to generate a random number between 0 and the length of the collection (0), which is impossible. So it should throw an error. Note that it is the *random generation of the index*, not the nth that conceptually is throwing the error. To me, the only weird part is that rand-nth doesn't throw an error on nil. In this context, I expect nil to be treated as an empty sequence. Clojure has other inconsistencies relating to nil, so I wouldn't generally make assumptions rand-nth's handling of nil in my code, but it's pretty easy to write your code in such a way that you are using `seq`-ified linked lists, and then later make some change so that things are getting passed around before `seq` has been called on them, which would cause rand-nth to break. So this inconsistency is not ideal. -- 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 --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.