In Clojurescript, calling rand-nth on an empty Set results in an
"Index out of bounds" exception, whereas calling it on an empty Vector
results in nil.

ClojureScript:cljs.user> (rand-nth (set []))
"Error evaluating:" (cljs.core.prn (rand-nth (set []))) :as
"cljs.core.prn.call(null,cljs.core.rand_nth.call(null,cljs.core.set.call(null,cljs.core.Vector.fromArray([]))));
\n"sun.org.mozilla.javascript.internal.JavaScriptException: Index out
of bounds (cljs/core.cljs#937)

ClojureScript:cljs.user> (rand-nth (vec []))
nil

Drilling down, the problem is that calling nth with an out-of-range
index returns nil for Vectors, but throws that exception for Sets.
But, using the set as a function, you do get nil:

ClojureScript:cljs.user> ((set [1 2 3]) 10)
nil

Am I doing something wrong?  Or is there a bug in how nth is defined
for Sets?

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

Reply via email to