Skip to content

Instantly share code, notes, and snippets.

@drewr
Created September 22, 2009 14:15
Show Gist options
  • Select an option

  • Save drewr/191109 to your computer and use it in GitHub Desktop.

Select an option

Save drewr/191109 to your computer and use it in GitHub Desktop.
(ns com.draines.test)
(def *opts* [{:one 1 :two 2 :three 3}
{:four 4 :five 5 :six 6}])
(defmacro foo [args]
`(do ~@(map #(list 'keys %) args)))
(macroexpand-1
'(foo [{:one 1 :two 2 :three 3}
{:four 4 :five 5 :six 6}]))
; (do (keys {:one 1, :two 2, :three 3}) (keys {:four 4, :five 5, :six 6}))
(macroexpand-1
'(foo *opts*))
; I'd like to have the benefit of the clean macro-style call but
; give foo a symbol to expand at runtime.
; Function I'm trying to avoid:
(defn make-options [opts]
(loop [o (Options.)
opts* opts]
(if (seq opts*)
(let [opt (first opts*)]
(.addOption o (:short opt) (:long opt) (:req? opt) (:desc opt))
(recur o (rest opts*)))
o)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment