bug? discrepancy with (get ...)

4 views
Skip to first unread message

jon

unread,
Apr 5, 2008, 6:53:48 PM4/5/08
to Clojure
Hi Rich..
Just been eyeballing your java :) and came up with this discrepancy in
RT.get() which I don't think you intend?

user=> (get "abcde" 4 \q)
\e
user=> (get "abcde" 5 \q)
\q
user=> (get "abcde" 4)
\e
user=> (get "abcde" 5)
java.lang.StringIndexOutOfBoundsException: String index out of range:
5
java.lang.StringIndexOutOfBoundsException: String index out of range:
5
at java.lang.String.charAt(String.java:558)
at clojure.lang.RT.nth(RT.java:534)
at clojure.lang.RT.get(RT.java:444)
at clojure.fns.clojure.get__192.invoke(boot.clj:674)
...etc

Cheers, bugfinder Jon ;P

Rich Hickey

unread,
Apr 6, 2008, 9:50:36 AM4/6/08
to Clojure


On Apr 5, 6:53 pm, jon <superuser...@googlemail.com> wrote:
> Hi Rich..
> Just been eyeballing your java :) and came up with this discrepancy in
> RT.get() which I don't think you intend?
>
> user=> (get "abcde" 4 \q)
> \e
> user=> (get "abcde" 5 \q)
> \q
> user=> (get "abcde" 4)
> \e
> user=> (get "abcde" 5)
> java.lang.StringIndexOutOfBoundsException: String index out of range:
> 5
> java.lang.StringIndexOutOfBoundsException: String index out of range:
> 5

Fixed - thanks for the report,

Rich

jon

unread,
Apr 6, 2008, 8:22:47 PM4/6/08
to Clojure
> 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)))

Rich Hickey

unread,
Apr 6, 2008, 10:05:37 PM4/6/08
to Clojure


On Apr 6, 8:22 pm, jon <superuser...@googlemail.com> wrote:
> > Fixed - thanks for the report,
>
> Hi Rich,
> Oops.. As they say, "close... but no cigar" ;)
> Your pair of get() functions still don't match..
>

> java.lang.StringIndexOutOfBoundsException: String index out of range:
> -1

Got that now too, thanks,

Rich
Reply all
Reply to author
Forward
0 new messages