Pure Danger Tech


navigation
home

Learning Clojure #6: Inspector

10 Feb 2010

One useful utility built into Clojure is the ability to pop up a Swing app that can inspect a data structure.

The inspector comes with clojure core so just do this to start using it:

user=> (use 'clojure.inspector)

If we want to look at our data in the form of a tree we can do something like this:

(inspect-tree {:a 1 :b 2 :c [1 2 3 {:d 4 :e 5 :f [6 7 8]}]})

which will yield the following gui:

Or try a table view if that’s more convenient:

(inspect-table [[1 2 3][4 5 6][7 8 9][10 11 12]])

Or you can use the generic inspect function to look at arbitrary objects.

(inspect (System/getProperties))

You’ll note some intriguing looking buttons in the button bar at the top of that UI but as far as I can tell, they don’t do anything.