(defmacro doto
"Evaluates x then calls all of the methods and functions with the
value of x supplied at the front of the given arguments. The forms
are evaluated in order. Returns x.
(doto (new java.util.HashMap) (.put \"a\" 1) (.put \"b\" 2))"
{:added "1.0"}
[x & forms]
(let [gx (gensym)]
`(let [~gx ~x]
~@(map (fn [f]
(with-meta
(if (seq? f)
`(~(first f) ~gx ~@(next f))
`(~f ~gx))
(meta f)))
forms)
~gx)))