Paste number 82973: Macro this!

Index of paste annotations: 1

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:
Raw Source | XML | Display As
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:
Raw Source | Display As
(defmacro macfoo 
    [string & subs] 
   `(-> ~string ~@(for [sub subs] `(foo ~sub))))

user> (macfoo "hi %foo% %foo%" "foo" "bar")
"hi foo bar"

Colorize as:
Show Line Numbers
Index of paste annotations: 1

Lisppaste pastes can be made by anyone at any time. Imagine a fearsomely comprehensive disclaimer of liability. Now fear, comprehensively.