# \#macro-hygiene

**URL:** https://discourse.julialang.org/tag/macro-hygiene/1143.md

[Latest](https://discourse.julialang.org/latest.md) · [Categories](https://discourse.julialang.org/categories.md) · [Tags](https://discourse.julialang.org/tags.md)

---

## [How use eval to define macros that involve function definitions](https://discourse.julialang.org/t/how-use-eval-to-define-macros-that-involve-function-definitions/93773)

<div class="topic-metadata">

**Author:** [@hhaensel](https://discourse.julialang.org/u/hhaensel)\
**Replies:** 3\
**Last updated:** [October 19, 2024, 6:12pm UTC](https://discourse.julialang.org/t/how-use-eval-to-define-macros-that-involve-function-definitions/93773 "2024-10-19T18:12:58Z")

</div>

I want to define a bunch of macros that define function methods in a private module. module MyModule function f() end function g() end end using Main.MyModule struct T i end macro f(T, expr) esc(:(MyModule.…

---

## [@kwdef constructor not available outside of module](https://discourse.julialang.org/t/kwdef-constructor-not-available-outside-of-module/114675)

<div class="topic-metadata">

**Author:** [@veddox](https://discourse.julialang.org/u/veddox)\
**Replies:** 4\
**Last updated:** [May 31, 2024, 8:59am UTC](https://discourse.julialang.org/t/kwdef-constructor-not-available-outside-of-module/114675 "2024-05-31T08:59:00Z")

</div>

Hi everyone, working on an ecological model, I have a macro @species that creates a new struct using @kwdef. In most use cases, this works just fine. However, if I use this macro outside of the module in which it was de…

---

## [How to discourage macros: disable automerge of General registry PRs?](https://discourse.julialang.org/t/how-to-discourage-macros-disable-automerge-of-general-registry-prs/104529)

<div class="topic-metadata">

**Author:** [@nsajko](https://discourse.julialang.org/u/nsajko)\
**Replies:** 41\
**Last updated:** [October 19, 2023, 9:49pm UTC](https://discourse.julialang.org/t/how-to-discourage-macros-disable-automerge-of-general-registry-prs/104529 "2023-10-19T21:49:32Z")

</div>

It seems to me that macros are defined much too often in the Julia ecosystem and the (error-prone) definitions of such macros are often very complex. FWIW, the Julia Manual page on metaprogramming already heavily discou…

---

## [Can I "unescape" a variable name within an \`esc(..)\` node?](https://discourse.julialang.org/t/can-i-unescape-a-variable-name-within-an-esc-node/102396)

<div class="topic-metadata">

**Author:** [@iago-lito](https://discourse.julialang.org/u/iago-lito)\
**Replies:** 6\
**Last updated:** [August 4, 2023, 9:41am UTC](https://discourse.julialang.org/t/can-i-unescape-a-variable-name-within-an-esc-node/102396 "2023-08-04T09:41:48Z")

</div>

Hello, I’m curious whether it is possible to individually pick expressions within an esc()aped node to make them hygienic again. For instance: macro f(...) xp = esc(:(...)) unescape!(xp.args\[2\]) # or something …

---

## [Creating a variable inside a macro with specified name](https://discourse.julialang.org/t/creating-a-variable-inside-a-macro-with-specified-name/102187)

<div class="topic-metadata">

**Author:** [@shawn\_T](https://discourse.julialang.org/u/shawn_T)\
**Replies:** 7\
**Last updated:** [July 28, 2023, 5:44pm UTC](https://discourse.julialang.org/t/creating-a-variable-inside-a-macro-with-specified-name/102187 "2023-07-28T17:44:50Z")

</div>

Hi all, I am trying to create a variable inside a Julia macro, then return the variable to the REPL, the variable should also have the name I specified from the macro input argument. I have two tests, the first test fun…

---

## [Prevent escaping for single symbol inside macro body](https://discourse.julialang.org/t/prevent-escaping-for-single-symbol-inside-macro-body/89609)

<div class="topic-metadata">

**Author:** [@disberd](https://discourse.julialang.org/u/disberd)\
**Replies:** 0\
**Last updated:** [November 1, 2022, 10:37am UTC](https://discourse.julialang.org/t/prevent-escaping-for-single-symbol-inside-macro-body/89609 "2022-11-01T10:37:12Z")

</div>

Is there a function or any other way to prevent escaping of a specific symbol when wrapping the expr returned by a macro with esc()? I sometime want to have a few symbols within the macro body to be unescaped and it wou…

---

## [Higher order function as macro](https://discourse.julialang.org/t/higher-order-function-as-macro/87867)

<div class="topic-metadata">

**Author:** [@jlbosse](https://discourse.julialang.org/u/jlbosse)\
**Replies:** 1\
**Last updated:** [September 27, 2022, 11:07am UTC](https://discourse.julialang.org/t/higher-order-function-as-macro/87867 "2022-09-27T11:07:37Z")

</div>

I am trying provide a macro form of a higher order function, but the automatic macro hygiene means that the name of the resulting function gets mangled. Here is my attempt so far: # The higher order function I want to…
