macro | since v0.0-3165 | clojure.core/macroexpand-1 | Edit |
(macroexpand-1 quoted)
(only intended as a REPL utility)
If the given quoted form is a macro call, expand it once. NOTE: subforms are not expanded.
See macroexpand
if you wish to repeatedly expand a form.
See how (-> 2 inc)
is progressively expanded:
(macroexpand-1 '(-> 2 inc))
;;=> (inc 2)
(macroexpand-1 '(inc 2))
;;=> (cljs.core/+ 2 1)
(macroexpand-1 '(cljs.core/+ 2 1))
;;=> (js* "(~{} + ~{})" 2 1)
Notice how the nested inc
form is not expanded:
(macroexpand-1 '(inc (inc 2)))
;;=> (cljs.core/+ (inc 2) 1)
If form represents a macro form, returns its expansion, else returns form.
(core/defmacro macroexpand-1
[quoted]
(core/assert (core/= (core/first quoted) 'quote)
"Argument to macroexpand-1 must be quoted")
(core/let [form (second quoted)]
(if (seq? form)
`(quote ~(ana/macroexpand-1 &env form))
form)))