Skip to content

Instantly share code, notes, and snippets.

@jasonjohnson
Created February 1, 2013 17:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jasonjohnson/4692634 to your computer and use it in GitHub Desktop.
Save jasonjohnson/4692634 to your computer and use it in GitHub Desktop.
(def connection {:host "127.0.0.1"})
(defn query [conn query]
(str (:host conn) ":" query))
(defn query-with-modifiers [conn query modifiers]
(str (:host conn) ":" query ":" modifiers))
(defmacro with-connection
[conn & body]
`(map (fn [op#]
(let [call# (resolve (first op#))
args# (rest op#)]
(apply (partial call# ~conn) args#)))
(quote ~body)))
(with-connection connection
(query "q1")
(query "q2")
(query "q3")
(query-with-modifiers "q4" "my-modifiers"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment