macroexpand

clojure.core

  • (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 top

  • ;; 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)))    
    (* (clojure.core/-> c (+ 3)) 2)
    
Log in to add / edit an example.

See Also top

Log in to add a see also.

Plus_12x12 Minus_12x12 Source clojure/core.clj:3564 top

(defn macroexpand
  "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."
  {:added "1.0"
   :static true}
  [form]
    (let [ex (macroexpand-1 form)]
      (if (identical? ex form)
        form
        (macroexpand ex))))
Vars in clojure.core/macroexpand:
Used in 0 other vars

Comments top

No comments for macroexpand. Log in to add a comment.