Skip to content

clojure.walk/macroexpand-all

View this page on ClojureDocs

Type: function Added: Clojure 1.1 Examples: 4 Runnable: 1
([form])

Recursively performs all possible macroexpansions in form.

Examples

by BertrandDechoux on . May have evaluation errors.
by Sgeo on
by philos99 on . May have evaluation errors.
by owenRiddy on . May have evaluation errors.

Note by Sgeo

DO NOT USE THIS FUNCTION, it doesn't handle special forms at all, and, as such, does not in fact expand into the ultimate macroexpansion of the form.

For example,

(require '[clojure.walk :as walk])
(println (walk/macroexpand-all '(quote (let [a 1] a))))

Will print

(quote (let* [a 1] a))

When the correct answer is

(quote (let [a 1] a))

Showing an utter unawareness of proper handling of special forms

DO NOT USE THIS FUNCTION

Note by Cubic

@Sgeo - let is just a macro for let*:

(clojure.repl/source let) =>

(defmacro let
"binding => binding-form init-expr

 Evaluates the exprs in a lexical context in which the symbols in
 the binding-forms are bound to their respective init-exprs or parts
 therein."
 {:added "1.0", :special-form true, :forms '[(let [bindings*] exprs*)]}
 [bindings & body]
 (assert-args let
     (vector? bindings) "a vector for its binding"
     (even? (count bindings)) "an even number of forms in binding vector")
  `(let* ~(destructure bindings) ~@body))

Note by Sgeo

(quote (let [a 1] a)) is '(let [a 1] a) which evaluates to a list containing the symbol let, a vector [a 1], and a symbol a. In this context, the (let [a 1] a) is not code, but mere data, and as such, should not be macroexpanded at all, anymore than a string like "(-> a b c)" should be macroexpanded into "(c (b a))" (and yes, I know that's not the exact macroexpansion).

See also


Content from the matching ClojureDocs page, with authors credited on each contribution.