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.
Throwing an exception doesn't feel like idiomatic Clojure to me. In my experience Clojure throws on type errors, and returns nil to indicate failure or absence. first and next don't throw when you ask for non-existing elements of a collection - they return nil to indicate absense. Similarly get and get-in return nil rather than throwing when the provided key is not associated with a value in an associative data structure. That's why I found it odd that rand-nth throws. -- 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.