this article may be helpful: http://insideclojure.org/2014/12/15/warn-on-boxed/
On 3 July 2017 at 13:36, Tomasz Sulej <tomek...@gmail.com> wrote: > When you decide to work with longs and doubles you can achieve the same in > pure clojure > Just add primitive type hints and (set! *unchecked-math* true). > (to see if you have boxed operations add (set! *unchecked-math* > :warn-on-boxed)) > > (set! *unchecked-math* :warn-on-boxed) ;; set math to be unchecked and > warn if boxed operations are used > > (defn add ^long [^long a ^long b] (+ a b)) > (defn not ^long [^long a] (bit-not a)) > > (add 10 10) > ;; => 20 > > (not 10) > ;; => -11 > > (type (add 10 10)) > ;; => java.lang.Long > > On 3 July 2017 at 11:44, Phillip Lord <phillip.l...@newcastle.ac.uk> > wrote: > >> >> >> This is the first alpha release of my new library! Comments welcome. >> >> Clojure has an extensive system for dealing with numbers, including >> error on overflow, or auto-promotion, defaulting to long and double data >> types. >> >> This is all well and good, but irritating if you need to implement an >> algorithm which depends on ints overflowing for instance. While, clojure >> provides functions for operating over ints, the names tend to be long >> and wieldy, such as clojure.core/unchecked-int-add. Clojure is also >> rather inconsistent; for example, the bit-shifting operators in Java are >> not accessible in Clojure over ints. >> >> This library provides accessible, easily named float and int functions >> for Clojure. Where possible, functions with the same name as the >> operators are provided as well as names (<< and left-shift). Three Java >> operators are not valid symbols in clojure (~, % and ^), so just have >> names. Short reader literals are also provided to simplify the creation >> of ints and float. >> >> (require '[primititve.operator.integer :as i]) >> >> (i/+ 10 10) >> => 20 >> >> (type (i/+ 10 10)) >> => java.lang.Integer >> >> (i/add 10 10) >> => 20 >> >> (i/not 10) >> => -11 >> >> (i/+ #p/i 10 #p/i 10) >> => 20 >> >> >> https://github.com/phillord/primitive-operator >> >> -- >> 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. >> > > -- 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.