Re: Casting numbers to ints

2011-09-19 Thread Justin Kramer
Here's a fleshed-out version that tests for any type of primitive: (definterface IPrimitiveTester (getType [^int x]) (getType [^long x]) (getType [^float x]) (getType [^double x]) (getType [^byte x]) (getType [^short x]) (getType [^char x]) (getType [^boolean x]) (getType [^Objec

Re: Casting numbers to ints

2011-09-18 Thread Meikel Brandmeyer
Hi, Am 18.09.2011 um 18:54 schrieb Brent Millare: > That's cool. Good to know. And another (concluding?) remark: Calling .getClass on a primitive doesn't work, since primitives are no objects. So the integer is boxed again to … Long. Hence you get the same result as with type or class. Sincer

Re: Casting numbers to ints

2011-09-18 Thread Brent Millare
That's cool. Good to know. Thanks, Brent On Sep 18, 12:25 pm, David Nolen wrote: > No need to leave Clojure to see what's going on: > > (definterface IntTest >   (intTest [^int n]) >   (intTest [^long n])) > > (deftype IntTester [] >   IntTest >   (intTest [this ^int n] (println "A primitive int

Re: Casting numbers to ints

2011-09-18 Thread David Nolen
No need to leave Clojure to see what's going on: (definterface IntTest (intTest [^int n]) (intTest [^long n])) (deftype IntTester [] IntTest (intTest [this ^int n] (println "A primitive int!")) (intTest [this ^long n] (println "A primitive long!"))) (comment (.intTest (IntTester.) 1)

Re: Casting numbers to ints

2011-09-18 Thread Meikel Brandmeyer
Hi, Am 18.09.2011 um 15:36 schrieb Brent Millare: > Even if I use what type does underneath and call .getClass myself (so > there is no boxing), I still get type long. Also to be more specific, > I am interested in the primitive int, not java.lang.Integer. You could do a hardcore try and use a s

Re: Casting numbers to ints

2011-09-18 Thread Brent Millare
Hi Meikel, Even if I use what type does underneath and call .getClass myself (so there is no boxing), I still get type long. Also to be more specific, I am interested in the primitive int, not java.lang.Integer. Best, Brent On Sep 18, 4:10 am, Meikel Brandmeyer wrote: > Hi, > > Am 18.09.2011 um

Re: Casting numbers to ints

2011-09-18 Thread Meikel Brandmeyer
Hi, Am 18.09.2011 um 07:31 schrieb Brent Millare: > Is it possible to cast a number into an int in 1.3.0-RC0? > > ;user=> (type 0) > java.lang.Long > ;user=> (type (int 0)) > java.lang.Long int does cast to an integer for direct java interop. type is function so the integer will be boxed. 1.3