# Defining a macro in a local scope?

**URL:** <https://discourse.julialang.org/t/defining-a-macro-in-a-local-scope/73148>\
**Category:** General Usage\
**Tags:** macros, scope, local\
**Created:** [December 15, 2021, 3:11pm UTC](https://discourse.julialang.org/t/defining-a-macro-in-a-local-scope/73148 "2021-12-15T15:11:17Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![woclass](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/woclass/32/212699_2.png) [@woclass](https://discourse.julialang.org/u/woclass)\
**Post date:** [December 15, 2021, 3:45pm UTC](https://discourse.julialang.org/t/defining-a-macro-in-a-local-scope/73148/2 "2021-12-15T15:45:07Z")

</div>

> Macros in Julia are only allowed to be defined in the global scope.

> [@Lexically Scoped Macros?](https://discourse.julialang.org/t/lexically-scoped-macros/6835/2):
>
> I heard from someone [here](https://www.reddit.com/r/lisp/comments/7961z9/are_there_any_new_interesting_lisps_being/dp6hoav/) that Lexical macros were excluded for performance reasons as they make it “impossible to statically analyse the code and generate fast code”. This makes no sense to me as lexically scoping the macro should only serve to further localize its effects and should be converted to proper code at before compilation so I fail to see any problem.

What happens if you define this macro globally?

You can also try defining the macro in a new module.

---

_[View the full topic](https://discourse.julialang.org/t/defining-a-macro-in-a-local-scope/73148)._
