On Dec 14, 8:04 pm, Ken Wesson <kwess...@gmail.com> wrote: > On Tue, Dec 14, 2010 at 8:23 PM, Benny Tsai <benny.t...@gmail.com> wrote: > > As Brian said, primitive math is now the default in 1.3. If auto- > > promotion on overflow is desired, you can use the +', -', *', inc', > > dec' functions (note the single quote suffix). > > Why was this done? I preferred having +, -, etc. DTRT in general and > unchecked-+, etc. for when you really needed efficient primitive math. > My code is littered with + but has few unchecked-+s. Which means I'll > have to go through it all adding little tick-marks everywhere and > making the math look funny to keep its behavior the same whenever 1.3 > is released. This topic has been discussed to death before on this group.
Short version: Doing the right thing is actually harder than you might first think: methods in Java must choose between returning a primitive and returning in reference type. This means that you have to choose between fast primitive math or slow reference type math. To advance the goal of writing Clojure in Clojure, it is necessary for it be easy to write high-performance Clojure code (although you might not care about how hard photosynthesis is, the plants do). Since it is generally the case that longs are sufficient for most purposes and it generally known ahead of time when they are not (Project Euler problems for example), primitive math is being made default in 1.3 Another change in 1.3 is that BigInteger math will not auto-reduce and will be contagious. This means that the prime versions of operations (+', -', etc.) are almost never necessary as one can use a BigInteger literal to ensure the operation will not overflow. Your example will work correctly if you change 1 to 1N. (Since java.lang.BigInteger is slow on small numbers, clojure.lang.BigInt is also being introduced (which is the type of 1N) that should be as fast as math was in 1.2 when the numbers fit into a long) For better or worse (hopefully for better), Clojure is increasingly adopting C++'s philosophy of pay for what you need. -- 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