Saturday, September 8, 2012

Experimenting Java library with Clojure

I'm reading Joy of Clojure. The book is a bit outdated in terms of library version. It was written when Clojure was at 1.2 but now Clojure is at 1.4 and 1.5 is development.

In one section of the book, it explains that we can easily use function show in clojure.contrib.repl.utils to display document of Java library but that was for Clojure.

According to Where Did Clojure.Contrib Go, show moved to clojure.reflect/reflect. Let play with it a little bit.

(require '[clojure.reflect :as cr])
(cr/reflect java.lang.Math)
;{:bases #{java.lang.Object}, :flags #{:public :final}, :me ....
; If you want to list all the method names of given class do
(map :name (:members (cr/reflect java.lang.Math)))
;(round nextUp nextUp exp min cos acos max hypot ceil ulp ulp min floor
;cbrt getExponent IEEEremainder log10 min rint tanh copySign
;negativeZeroDoubleBits max sin negativeZeroFloatBits E max PI expm1
;cosh toDegrees signum signum sinh pow initRNG max round log
;randomNumberGenerator atan sqrt toRadians abs nextAfter getExponent
;scalb tan nextAfter random scalb java.lang.Math log1p min copySign
;atan2 abs abs abs asin)
Pretty handy.

Note: you also can open Javadoc in browser with this snippet
(javadoc java.lang.Math)

No comments:

Collectd PostgreSQL Plugin

I couldn't find this link when searching with google https://www.collectd.org/documentation/manpages/collectd.conf.html#plugin-postgresq...