Re: a bit mystified by unchecked-multiply

2013-02-22 Thread John Lawrence Aspden
So, something like: (type 23) the reader makes a list of a symbol and a primitive, the evaluator evals to get a generic function and a primitive, then tries to apply the generic function to the primitive, can't find a primitive version, so boxes the primitive to an object and tries again, and

Re: a bit mystified by unchecked-multiply

2013-02-22 Thread MichaƂ Marczyk
The reader always returns objects, it's the compiler that sometimes decides to unbox literal numbers. As for type, it's just a regular Clojure function which takes a single object argument (so the 23 will be passed to it in a Long box). Here it happens to delegate to class and ultimately

Re: a bit mystified by unchecked-multiply

2013-02-22 Thread Herwig Hochleitner
There is no evaluator in clojure (other than the one in the JVM) and certainly no retries. Clojure is a compiled language. All regular function are called via the IFn interface, which takes objects. Function arguments and return values can be type hinted to be primitive. Normally such primitives

Re: a bit mystified by unchecked-multiply

2013-02-21 Thread John Lawrence Aspden
Great, thanks! So if one is an object and one is a primitive is one of these not true? user= (type seed1) java.lang.Long user= (type 25214903917) java.lang.Long Cheers, John. On Wednesday, February 20, 2013 11:44:44 PM UTC, Herwig Hochleitner wrote: I agree that unchecked-multiply

Re: a bit mystified by unchecked-multiply

2013-02-21 Thread Herwig Hochleitner
Both are true. The type function doesn't have a primitive version, so its argument gets auto-boxed. -- -- 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

a bit mystified by unchecked-multiply

2013-02-20 Thread John Lawrence Aspden
Hi, I'm getting an unexpected exception trying to do unchecked arithmetic: user= (def seed1 25214903917) #'user/seed1 user= (type seed1) java.lang.Long user= (type 25214903917) java.lang.Long user= (unchecked-multiply seed1 0x5DEECE66D) ArithmeticException integer overflow

Re: a bit mystified by unchecked-multiply

2013-02-20 Thread AtKaaZ
looks like different methods are called: for: user= (unchecked-multiply 25214903917 0x5DEECE66D) this method: static public long unchecked_multiply(long x, long y){return x * y;} for: (unchecked-multiply seed1 0x5DEECE66D) this method: static public Number unchecked_multiply(long x, Object

Re: a bit mystified by unchecked-multiply

2013-02-20 Thread AtKaaZ
looks like if you make any(or both) to double it works as expected due to these being called: static public double multiply(double x, double y){ return x * y; } static public double multiply(double x, long y){ return x * y; } static public double multiply(long x, double y){ return x

Re: a bit mystified by unchecked-multiply

2013-02-20 Thread Herwig Hochleitner
I agree that unchecked-multiply should do an unchecked multiply, even when faced with objects. Going to bring that up on clojure-dev. A workaround: (unchecked-multiply (long seed1) 0x5DEECE66D) -- -- You received this message because you are subscribed to the Google Groups Clojure group. To