Jason Wolfe
unread,Mar 19, 2009, 7:18:34 PM3/19/09Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Clojure
I was debugging with inspect-tree and noticed that it errors when it
encounters a set (it thinks it's not atomic, but then nth produces an
UnsupportedOperationException).
I made a small patch (below) that makes inspect-tree work on
java.util.Sets, and also anything else that implements
clojure.lang.Seqable. If this is of interest, please let me know and
I can create an issue.
Cheers,
Jason
Index: src/clj/clojure/inspector.clj
===================================================================
--- src/clj/clojure/inspector.clj (revision 1335)
+++ src/clj/clojure/inspector.clj (working copy)
@@ -20,8 +20,10 @@
(defn collection-tag [x]
(cond
(instance? java.util.Map$Entry x) :entry
- (instance? java.util.Map x) :map
+ (instance? java.util.Map x) :seqable
+ (instance? java.util.Set x) :seqable
(sequential? x) :seq
+ (instance? clojure.lang.Seqable x) :seqable
:else :atom))
(defmulti is-leaf collection-tag)
@@ -42,11 +44,15 @@
(defmethod get-child-count :entry [e]
(count (val e)))
-(defmethod is-leaf :map [m]
+(defmethod is-leaf :seqable [parent]
false)
-(defmethod get-child :map [m index]
- (nth (seq m) index))
+(defmethod get-child :seqable [parent index]
+ (nth (seq parent) index))
+(defmethod get-child-count :seqable [parent]
+ (count (seq parent)))
(defn tree-model [data]
(proxy [TreeModel] []
(getRoot [] data)