Created
March 31, 2010 10:42
-
-
Save noidi/350177 to your computer and use it in GitHub Desktop.
This file contains 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.walk :only [prewalk-replace]]) | |
(defmacro doto$ | |
"Like doto, but replaces $ with a reference to the object." | |
[object & forms] | |
(let [object-sym (gensym "object")] | |
`(let [~object-sym ~object] | |
(doto ~object-sym | |
~@(prewalk-replace {'$ object-sym} forms))))) | |
;;; Usage example | |
(comment | |
(doto$ (JSpinner. (SpinnerNumberModel. default min max step)) | |
(.setEditor (JSpinner$NumberEditor. $ "#")))) | |
;; Expands to: | |
; (let [object3906 (JSpinner. (SpinnerNumberModel. default min max step))] | |
; (doto object3906 | |
; (.setEditor (JSpinner$NumberEditor. object3906 "#")))) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
(doto (JSpinner. (SpinnerNumberModel. default min max step) (-> (JSpinner$NumberEditor. "#") .setEditor))