Created
September 22, 2009 14:15
-
-
Save drewr/191109 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| (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