On Thu, Oct 20, 2011 at 1:54 AM, nathanmarz <nathan.m...@gmail.com> wrote: > Yes, I understand the behavior perfectly well. The primitive int gets > converted to a Long immediately, as this code demonstrates: > > user=> (class (Integer/parseInt "5")) > java.lang.Long
class is a clojure function that takes Objects, so the int must be boxed. > The int isn't being "boxed" into a Long -- the type is being changed. > > I'm aware that I can "fix" things by converting the type back to an > Integer manually, but that's not the point. Changing the types is > unusual behavior that leads to hard to track down bugs like I ran into > with the ClassCastException. My proposal still stands. > > -Nathan > > > On Oct 19, 5:29 pm, Kevin Downey <redc...@gmail.com> wrote: >> On Wed, Oct 19, 2011 at 5:14 PM, nathanmarz <nathan.m...@gmail.com> wrote: >> > Here's a code example illustrating the problem I'm having: >> >https://gist.github.com/1300034I've simplified it to the bare minimum >> > necessary to illustrate the problem. >> >> > Agree 100% that ints and longs are broken in Java. The hashcode/ >> > equality stuff is messed up. Clojure can try really hard to hide this, >> > but it can't hide it completely since Java libraries can always return >> > you Integer objects. The additional complexity added from changing the >> >> Existing Integer objects are unchanged. If the method call in your >> example did return an Integer object then you would never notice >> anything. >> >> > types on you isn't worth it IMO. >> >> > Here's my proposal for what I think would be better behavior: >> >> > 1. Clojure boxes ints into Integers rather than convert them into >> > longs >> >> clojure does not convert ints into longs, you are putting a primitive >> into a collection, which requires boxing, clojure 1.3 boxes ints as >> Longs. If you put (Integer. …) around your call you will be fine. >> >> >> >> >> >> >> >> >> >> > 2. If you wrap the form in "(long ...)", Clojure skips the boxing and >> > does what it does now. Since this is done explicitly, there's no >> > confusion about types. >> >> > -Nathan >> >> > On Oct 19, 7:38 am, Stuart Halloway <stuart.hallo...@gmail.com> wrote: >> >> > Thanks. I read through that and it didn't quite answer my question. To >> >> > me it seems more logical that: >> >> >> > 1. Clojure defaults to longs when you create a new number (with a >> >> > literal 0, 1, etc) >> >> > 2. You can create ints by doing (int 0) >> >> > 3. Clojure never changes the types of things you're using >> >> >> > I find Clojure's behavior of changing the types of primitive ints to >> >> > longs highly unusual, and it is causing a lot of pain in upgrading >> >> > Storm to 1.3. >> >> >> Integers and longs are going to be painful no matter what because they >> >> are broken in Java, e.g. >> >> >> Object[] objects = new Object[] {-1, -1L}; >> >> System.out.println(objects[0].hashCode()); >> >> System.out.println(objects[1].hashCode()); >> >> >> Clojure avoids this pit by standardizing on longs, which leaves you with >> >> the need to specifically request ints when you need them for interop. You >> >> can use (int n) hints to select the correct interop method invocation, or >> >> box an int if you want to hold on to a value guaranteed to be int. >> >> >> Can you post a code example that shows a problem you are having? >> >> >> Stu >> >> >> Stuart Halloway >> >> Clojure/corehttp://clojure.com >> >> > -- >> > 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 >> >> -- >> And what is good, Phaedrus, >> And what is not good— >> Need we ask anyone to tell us these things? > > -- > 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 -- And what is good, Phaedrus, And what is not good— Need we ask anyone to tell us these things? -- 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