# Where is the macro system in the source tree?

**URL:** <https://racket.discourse.group/t/where-is-the-macro-system-in-the-source-tree/3043>\
**Category:** Internals\
**Created:** [July 19, 2024, 5:16pm UTC](https://racket.discourse.group/t/where-is-the-macro-system-in-the-source-tree/3043 "2024-07-19T17:16:29Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![abdulhamid-the-ottom](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/abdulhamid-the-ottom/32/1819_2.png) [@abdulhamid-the-ottom](https://racket.discourse.group/u/abdulhamid-the-ottom)\
**Post date:** [July 19, 2024, 5:16pm UTC](https://racket.discourse.group/t/where-is-the-macro-system-in-the-source-tree/3043/1 "2024-07-19T17:16:30Z")

</div>

Hi,  
I want to know where is the source code located for the Racket's macro system?

And what would it take to rewrite it from scratch?

Thanks

---

<div class="post-metadata">

**Author:** ![sorawee](https://avatars.discourse-cdn.com/v4/letter/s/ea5d25/32.png) [@sorawee](https://racket.discourse.group/u/sorawee)\
**Post date:** [July 19, 2024, 6:00pm UTC](https://racket.discourse.group/t/where-is-the-macro-system-in-the-source-tree/3043/2 "2024-07-19T18:00:35Z")

</div>

For the first question, it's [https://github.com/racket/racket/tree/master/racket/src/expander/expand](https://github.com/racket/racket/tree/master/racket/src/expander/expand)

For the second question, take a look at [https://www.youtube.com/watch?v=Or\_yKiI3Ha4](https://www.youtube.com/watch?v=Or_yKiI3Ha4) and [https://github.com/mflatt/expander](https://github.com/mflatt/expander).

---

<div class="post-metadata">

**Author:** ![LiberalArtist](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/liberalartist/32/151_2.png) [@LiberalArtist](https://racket.discourse.group/u/LiberalArtist)\
**Post date:** [July 19, 2024, 6:31pm UTC](https://racket.discourse.group/t/where-is-the-macro-system-in-the-source-tree/3043/3 "2024-07-19T18:31:10Z")

</div>

> [@abdulhamid-the-ottom](#):
>
> And what would it take to rewrite it from scratch?

Depending on what exactly you mean by "rewrite it", you might be interested in the discussion in this thread on how different pieces of Racket are put together:

> [@What would it take to write an independent Racket interpreter?](https://racket.discourse.group/t/what-would-it-take-to-write-an-independent-racket-interpreter/951):
>
> Hello all, I was curious what it would take to "reimplement Racket". As a Scheme derivative, it has a small core language[1], but this includes only the language and no standard library. I found a nice folder[2] of tables with about 1700 primitives in the Chez Scheme implementation that might suffice as the minimal standard library. It looks like the main language-level differences compared with e.g. SICP Scheme are: Syntax objects: (quote-syntax) Modules. Including multiple phases, since (…

In particular:

> [@What would it take to write an independent Racket interpreter?](https://racket.discourse.group/t/what-would-it-take-to-write-an-independent-racket-interpreter/951/4):
>
> Implementing a similar macro expander is maybe not that difficult, but building a separate and fully compatible macro expander is probably not practical. That would be similar to building a RnRS Scheme implementation that is not merely a drop-in replacement for another according to the standard, but would work for every use of the other Scheme implementation. So, for the foreseeable future, any compatible and practical implementation of Racket is just going to use the main implementation of the macro system.

> [@sorawee](#):
>
> For the second question, take a look at [https://www.youtube.com/watch?v=Or\_yKiI3Ha4](https://www.youtube.com/watch?v=Or_yKiI3Ha4) and [GitHub - mflatt/expander](https://github.com/mflatt/expander).

I heartily second the recommendation for Matthew's talk in that video, “Let’s Build a Hygenic Macro Expander”.
