# Using macroexpand inside a macro in Clojurescript doesn't work

**URL:** https://clojureverse.org/t/using-macroexpand-inside-a-macro-in-clojurescript-doesnt-work/6516
**Category:** Troubleshooting
**Tags:** macros, clojurescript
**Created:** [September 8, 2020, 10:53am UTC](https://clojureverse.org/t/using-macroexpand-inside-a-macro-in-clojurescript-doesnt-work/6516 "2020-09-08T10:53:46Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![jpmonettas](https://clojureverse.org/letter_avatar_proxy/v4/letter/j/a88e4f/32.png) [@jpmonettas](https://clojureverse.org/u/jpmonettas)
#### Post date: [September 8, 2020, 10:53am UTC](https://clojureverse.org/t/using-macroexpand-inside-a-macro-in-clojurescript-doesnt-work/6516/1 "2020-09-08T10:53:46Z")

</div>

Hi everybody!,Does anybody knows why this macro

```clojure
(defmacro tester [form]
(println (macroexpand form))
nil)

```

When used from clojure :

```clojure
(tester (let [a 5] a))
;; prints
(let* [a 5] a)

```

But when used from clojurescript :

```clojure
(tester (let [a 5] a))
;; prints
(let [a 5] a)

```

So the same macro doesn’t do the same, macroexpand doesn’t work at macro level when the cljs compiler calls it

---

<div class="post-metadata">

### Author: ![didibus](https://clojureverse.org/user_avatar/clojureverse.org/didibus/32/951_2.png) [@didibus](https://clojureverse.org/u/didibus)
#### Post date: [September 9, 2020, 2:05am UTC](https://clojureverse.org/t/using-macroexpand-inside-a-macro-in-clojurescript-doesnt-work/6516/2 "2020-09-09T02:05:56Z")

</div>

There is no `macroexpand` in ClojureScript. ClojureScript cannot expand macros, only Clojure can.

And in your case, I’m guessing maybe your macro isn’t defined properly for ClojureScript. I forgot the rules, but it is a bit tricky. The macro has to be in a `.clj` file, and in ClojureScript you need to call `require-macro`.

---

<div class="post-metadata">

### Author: ![jpmonettas](https://clojureverse.org/letter_avatar_proxy/v4/letter/j/a88e4f/32.png) [@jpmonettas](https://clojureverse.org/u/jpmonettas)
#### Post date: [September 9, 2020, 11:33am UTC](https://clojureverse.org/t/using-macroexpand-inside-a-macro-in-clojurescript-doesnt-work/6516/3 "2020-09-09T11:33:56Z")

</div>

Sorry, maybe I didn’t specified all the details.

This is a normal Clojure macro defined in a macros.clj file.

So it goes something like this:

**In macros.clj :**

```
 (ns project.macros)

(defmacro m [form]
  (let [form2 (macroexpand form)]
        ;; do something with form2
  ))

```

**In test.cljs :**

```
(ns project.test
   (:require-macros [project.macros :refer [m]])

(println (and 1 2))

```

So if I use that same macro from a clojure project, form2 gets bind to

```
(let* ... (if* ...))

```

While when using it from clojurescript form2 gets bind to

```
(and 1 2)

```

Shouldn’t the macro be expanding the same, since it is compile time and clojure world?

---

<div class="post-metadata">

### Author: ![system](https://clojureverse.org/uploads/default/original/2X/5/51079bf9e4b7d9466242c06cf1e43b9f8bd6da14.png) [@system](https://clojureverse.org/u/system)
#### Post date: [March 10, 2021, 11:34pm UTC](https://clojureverse.org/t/using-macroexpand-inside-a-macro-in-clojurescript-doesnt-work/6516/4 "2021-03-10T23:34:00Z")

</div>

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.
