| Paste number 82973: | Macro this! |
| Pasted by: | Lau_of_DK |
| When: | 2 years, 7 months ago |
| Share: | Tweet this! | http://paste.lisp.org/+1S0T |
| Channel: | #clojure |
| Paste contents: |
user> (defn foo [x bar] (.replaceFirst x "%foo%" bar))
#'user/foo
user> (-> "hi %foo%, welcome to %foo%"
(foo "mister")
(foo "#clojure"))
"hi mister, welcome to #clojure"
user> (macroexpand '(macfoo "mister" "#clojure")
(-> "hi %foo%, welcome to %foo%" (foo "mister") (foo "#clojure"))
Question: What should macfoo look like?Annotations for this paste:
| Annotation number 1: | Macroed |
| Pasted by: | Chouser |
| When: | 2 years, 7 months ago |
| Share: | Tweet this! | http://paste.lisp.org/+1S0T/1 |
| Paste contents: |
(defmacro macfoo
[string & subs]
`(-> ~string ~@(for [sub subs] `(foo ~sub))))
user> (macfoo "hi %foo% %foo%" "foo" "bar")
"hi foo bar"