Created
February 1, 2011 20:33
-
-
Save GeorgeJahad/806595 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(use ' clojure.contrib.reflect) | |
(defn- gf [obj field] | |
[(keyword (.getName field)) (get-field (class obj) (.getName field) obj)]) | |
(defn get-all-fields [obj] | |
(into (sorted-map) (map (partial gf obj) (.getDeclaredFields (class obj))))) | |
;; user=> (def a (memoize (partial (comp inc last concat) [2]))) | |
;; #'user/a | |
;; user=> (a [4]) | |
;; 5 | |
;; user=> (a [3]) | |
;; 4 | |
;; user=> (pprint (-> a get-all-fields)) | |
;; {:__meta {:line 5090}, | |
;; :const__0 #<Var@4d8f9b75: #<core$if_let clojure.core$if_let@70b125bd>>, | |
;; :const__1 #<Var@19e09a4: #<core$let clojure.core$let@213eb2bc>>, | |
;; :const__2 #<Var@3b47788d: #<core$find clojure.core$find@1d429498>>, | |
;; :const__3 #<Var@6708f8e0: #<core$deref clojure.core$deref@48cc258a>>, | |
;; :const__4 #<Var@78871e65: #<core$val clojure.core$val@6e8af0b0>>, | |
;; :const__5 #<Var@fa7f9dc: #<core$apply clojure.core$apply@69ebcd0>>, | |
;; :const__6 #<Var@11dfc8a0: #<core$swap_BANG_ clojure.core$swap_BANG_@9bc850f>>, | |
;; :const__7 #<Var@1dfd868: #<core$assoc clojure.core$assoc@6a0239f6>>, | |
;; :f #<core$partial$fn__3678 clojure.core$partial$fn__3678@6629a046>, | |
;; :mem #<Atom@12b0f0ae: {([3]) 4, ([4]) 5}>} | |
;; nil | |
;; user=> (pprint (-> a get-all-fields :f get-all-fields)) | |
;; {:__meta {:line 2009}, | |
;; :arg1 [2], | |
;; :const__0 #<Var@fa7f9dc: #<core$apply clojure.core$apply@69ebcd0>>, | |
;; :f #<core$comp$fn__3644 clojure.core$comp$fn__3644@4cc68351>} | |
;; nil | |
;; user=> (pprint (-> a get-all-fields :f get-all-fields :f get-all-fields)) | |
;; {:__meta {:line 1951}, | |
;; :const__0 #<Var@fa7f9dc: #<core$apply clojure.core$apply@69ebcd0>>, | |
;; :f #<core$inc clojure.core$inc@b6be7ee>, | |
;; :g #<core$last clojure.core$last@26fc5b01>, | |
;; :h #<core$concat clojure.core$concat@372bab9>} | |
;; nil | |
;; user=> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment