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 [^Object x]))
(deftype PrimitiveTester [] IPrimitiveTester (getType [this ^int x] :int) (getType [this ^long x] :long) (getType [this ^float x] :float) (getType [this ^double x] :double) (getType [this ^byte x] :byte) (getType [this ^short x] :short) (getType [this ^char x] :char) (getType [this ^boolean x] :boolean) (getType [this ^Object x] :object)) (defmacro primitive-type [x] `(.getType (PrimitiveTester.) ~x)) (defmacro primitive? [x] `(not= :object (primitive-type ~x))) (comment ;; Clojure 1.2 (primitive? 1) ;=> false (primitive-type 1) ;=> :object (primitive? (Math/pow 2 2)) ;=> true (primitive? (* 2 (Math/pow 2 2))) ;=> false ;; Clojure 1.3 (primitive? 1) ;=> true (primitive-type 1) ;=> :long (primitive? (Math/pow 2 2)) ;=> true (primitive? (* 2 (Math/pow 2 2))) ;=> true ) -- 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