I'd apreciate help on figuring out why a loop gets number boxing
warnings, when it shouldn't:
http://clojure.pastebin.com/9uLZqGhy
I'm using clojure from:
commit f30995c86056959abca53d0ca35dcb9cfa73e6e6
Author: Stuart Halloway <s...@thinkrelevance.com>
Date: Fri Dec 17 15:17:20 2010 -0500
Thanks.
Albert
http://clojure.pastebin.com/xs79ruw1
Allen
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clo...@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+u...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
Hi Allen,
Thanks for the effort.
What I don't understand is why one should cast to int or long at all
if the variables "l" and "r" of the loop are ints, and will remain
ints throughout. And k is an int since both r and l are ints, and i
and j will be ints too.
I can't see where the variables are boxed into objects. Both the loop
and the let declare them as primitives if they are given primitives.
Perhaps they are already objects before they reach the inc and dec
function calls in the recur, but if so, it's a mystery to me why.
Albert
Yeah that is interesting. I'm not sure the _why_ of it but I attempted
to narrow it down and it looks like it has something to do with nested
loops and recur. The code below is basically the same thing except the
first one generates auto-boxing warnings while the latter does not.
I'd also like to know why this is.
(set! *warn-on-reflection* true)
;; generates auto-boxing warnings
(defn example [^long x]
(loop [a x]
(let [i (loop [k a] k)]
(if false (recur i) i))))
;; no warnings
(defn example [^long x]
(loop [a x]
(let [i (let [k a] k)]
(if false (recur i) i))))
Also, I couldn't resist giving qsort another attempt. I got a new
laptop and need to break it in somehow :) So here is a rewritten
version based on an example in "Introduction to Algorithms" without
casts.
https://gist.github.com/763139
Allen
Very nice minimal example. If someone has access for filing bugs to
assembla, could this one please be filed in?
> Also, I couldn't resist giving qsort another attempt. I got a new
> laptop and need to break it in somehow :) So here is a rewritten
> version based on an example in "Introduction to Algorithms" without
> casts.
>
> https://gist.github.com/763139
Nice traditional example, with swap and partition functions. Very
pretty, and readable!
Albert
--
http://albert.rierol.net
I just filed this as:
http://dev.clojure.org/jira/browse/CLJ-701
--Chouser
http://joyofclojure.com/