> Fixed - thanks for the report,
>
Hi Rich,
Oops.. As they say, "close... but no cigar" ;)
Your pair of get() functions still don't match..
user=> (get "abcde" 4 \q)
\e
user=> (get "abcde" 5 \q)
\q
user=> (get "abcde" -1 \q)
\q
user=> (get "abcde" 4)
\e
user=> (get "abcde" 5)
nil
user=> (get "abcde" -1)
java.lang.StringIndexOutOfBoundsException: String index out of range:
-1
java.lang.StringIndexOutOfBoundsException: String index out of range:
-1
at java.lang.String.charAt(String.java:558)
at clojure.lang.RT.nth(RT.java:536)
at clojure.lang.RT.get(RT.java:445)
at clojure.fns.clojure.get__192.invoke(boot.clj:674)
...etc
---
I guess, the get() code is (more-or-less) duplicated for a slight
speed increase, although I assume you aren't heavily concentrating on
speed at this stage.
But while we are on the subject, when I looked at drop and nthrest
yesterday, I figured that unlike nthrest, drop redundantly calls seq
on coll every time round the loop? Is that a candidate for a tweak?
Thanks, Jon
(defn drop
"Returns a lazy seq of all but the first n items in coll."
[n coll]
(if (and (pos? n) (seq coll))
(recur (dec n) (rest coll))
coll))
(defn nthrest
"Returns the nth rest of coll, (seq coll) when n is 0."
[coll n]
(loop [n n xs (seq coll)]
(if (and xs (pos? n))
(recur (dec n) (rest xs))
xs)))