Should `unchecked-multiply` throw an exception in this case? (see also:
http://stackoverflow.com/questions/33306984/why-does-my-hash-function-fail-with-arithmeticexception-integer-overflow-even/33308956#33308956
)

user> (reduce unchecked-multiply (range 1 22))
ArithmeticException integer overflow  clojure.lang.Numbers.throwIntOverflow
(Numbers.java:1388)

The loop-recur version also fails, unless you use a type hint:

user> (loop [n 1
             r (range 1 22)]
        (if-let [a (first r)]
          (recur (unchecked-multiply n a) (next r))
          n))
ArithmeticException integer overflow  clojure.lang.Numbers.throwIntOverflow
(Numbers.java:1388)

user> (loop [n 1
             r (range 1 22)]
        (if-let [^long a (first r)]
          (recur (unchecked-multiply n a) (next r))
          n))
-4249290049419214848

-- 
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
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to