Throwing an exception is probably the right thing to do if it's supposed to 
closely model the behavior of `nth`, but it wonder if it's the most usefull 
behavior in practice.
I would guess that it introduces `not-empty` checks everywhere, instead of only 
for the cases where you want to be shure that the nil returned is actually an 
element of the collection.

cheers Jan

> On 30 Sep 2015, at 20:18, Mark Engelberg <mark.engelb...@gmail.com> wrote:
> 
>> On Wed, Sep 30, 2015 at 12:14 PM, Mark Engelberg <mark.engelb...@gmail.com> 
>> wrote:
>> 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 be clear, when I say that nth "conceptually is throwing the error", I just 
> mean that's how I rationalize Clojure's behavior.  That's not really what's 
> going on.  (rand-int 0) returns 0 (which it probably shouldn't, given that 
> the input is meant to be an exclusive upper bound).  So in fact, the error is 
> thrown by clojure.lang.RT.nthFrom, which is surprising.
> 
>  
> -- 
> 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.

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

Reply via email to