summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/clj/clojure/core.clj4
-rw-r--r--src/jvm/clojure/lang/RT.java15
2 files changed, 10 insertions, 9 deletions
diff --git a/src/clj/clojure/core.clj b/src/clj/clojure/core.clj
index 3974204e..4096a6ff 100644
--- a/src/clj/clojure/core.clj
+++ b/src/clj/clojure/core.clj
@@ -547,8 +547,8 @@
bounds, nth throws an exception unless not-found is supplied. nth
also works for strings, Java arrays, regex Matchers and Lists, and,
in O(n) time, for sequences."
- {:inline (fn [c i] `(. clojure.lang.RT (nth ~c ~i)))
- :inline-arities #{2}}
+ {:inline (fn [c i & nf] `(. clojure.lang.RT (nth ~c ~i ~@nf)))
+ :inline-arities #{2 3}}
([coll index] (. clojure.lang.RT (nth coll index)))
([coll index not-found] (. clojure.lang.RT (nth coll index not-found))))
diff --git a/src/jvm/clojure/lang/RT.java b/src/jvm/clojure/lang/RT.java
index 18be0bf2..a5da74a2 100644
--- a/src/jvm/clojure/lang/RT.java
+++ b/src/jvm/clojure/lang/RT.java
@@ -756,16 +756,17 @@ static public Object nth(Object coll, int n){
}
static public Object nth(Object coll, int n, Object notFound){
- if(coll == null)
- return notFound;
- else if(n < 0)
- return notFound;
- else if(coll instanceof IPersistentVector) {
- IPersistentVector v = (IPersistentVector) coll;
- if(n < v.count())
+ if(coll instanceof Indexed) {
+ Indexed v = (Indexed) coll;
+ if(n >= 0 && n < v.count())
return v.nth(n);
return notFound;
}
+ else if(coll == null)
+ return notFound;
+ else if(n < 0)
+ return notFound;
+
else if(coll instanceof String) {
String s = (String) coll;
if(n < s.length())