Skip to content

Instantly share code, notes, and snippets.

@noidi
Created March 31, 2010 10:42
Show Gist options
  • Save noidi/350177 to your computer and use it in GitHub Desktop.
Save noidi/350177 to your computer and use it in GitHub Desktop.
(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 "#"))))
@hiredman
Copy link

(doto (JSpinner. (SpinnerNumberModel. default min max step) (-> (JSpinner$NumberEditor. "#") .setEditor))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment