Just for kicks, I built with nth throwing an exception on nil instead of returning nil and all tests passed, so that's at least promising that changing nth on nil would be possible.
On Wednesday, September 30, 2015 at 9:14:22 AM UTC-5, Alex Miller wrote: > > rand-nth cannot return a random element if there are no elements to > return, so I do not find this surprising. Returning nil would be an invalid > answer in my opinion. > > The rand-nth doc string implies that rand-nth will inherit the semantics > of nth for the specified collection. nth will generally throw on an invalid > index (and all indexes are invalid for an empty collection). > > For nil, the docstring for nth does not mention nil explicitly, so I would > treat this as undefined behavior unless you consider it as a degenerate > sequence. > > The code (in RT.nthFrom()) explicitly handles this case and effectively > treats nil as an infinite indexed source of nils, rather than as an empty > sequence. In my own opinion (but maybe not Rich's), it seems to make more > sense to take the sequence interpretation and say that on nil, nth should > throw instead. > > So that might be a valid ticket. I'm not sure what, if any, negative > consequences would arise out of existing uses of nth that rely on this > behavior though. Given the number of things built on nth, it may be > impossible to change this even if it made sense to. > > Alex > >> -- 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.