ClojureDocs

导航

命名空间

macroexpand

clojure.core

从 1.0 版本开始提供 (源代码)
  • (macroexpand form)
Repeatedly calls macroexpand-1 on form until it no longer
represents a macro form, then returns it.  Note neither
macroexpand-1 nor macroexpand expand macros in subforms.
2 Examples
;; It is useful to combine macroexpand with pprint as the
;; default output can be hard to read.
user=> (clojure.pprint/pprint (macroexpand '(time (print "timing"))))
(let*
 [start__3917__auto__
  (. java.lang.System (clojure.core/nanoTime))
  ret__3918__auto__
  (print "timing")]
 (clojure.core/prn
  (clojure.core/str
   "Elapsed time: "
   (clojure.core//
    (clojure.core/double
     (clojure.core/-
      (. java.lang.System (clojure.core/nanoTime))
      start__3917__auto__))
    1000000.0)
   " msecs"))
 ret__3918__auto__)

;; Even after pretty printing you may benefit from some
;; manual cleanup.

;; Also worth noting that most of the time macroexpand-1 is
;; a better alternative to avoid over expanding down too 
;; many levels.
user=> (macroexpand '(-> c (+ 3) (* 2)))    
(* (+ c 3) 2)
See Also

If form represents a macro form, returns its expansion, else returns form.

Added by kumarshantanu

Recursively performs all possible macroexpansions in form.

Added by pauldoo
0 Notes
No notes for macroexpand