user=> (use 'clojure.walk)
; tryclj.com and lazybot on #clojure get the following wrong
user=> (let [-> inc] (-> 5))
6
; Below macroexpansion is supposed to result in equivalent code to the above
user=> (macroexpand-all '(let [-> inc] (-> 5)))
(let* [-> inc] 5)
user=> (let* [-> inc] 5)
5
; However, as is clear above, it does not
user=> (use 'clojure.walk)
; tryclj.com and lazybot on #clojure get the following wrong
user=> (let [-> inc] (-> 5))
6
; Below macroexpansion is supposed to result in equivalent code to the above
user=> (macroexpand-all '(let [-> inc] (-> 5)))
(let* [-> inc] 5)
user=> (let* [-> inc] 5)
5
; However, as is clear above, it does not
Comments top
3 comment(s) for macroexpand-all.
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,
Will print
When the correct answer is
Showing an utter unawareness of proper handling of special forms
DO NOT USE THIS FUNCTION
@Sgeo -
letis just a macro forlet*:(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))(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).