# \`esc\` asymmetry between \`public\` and \`export\`

**URL:** https://discourse.julialang.org/t/esc-asymmetry-between-public-and-export/127420
**Category:** General Usage
**Created:** [March 27, 2025, 2:23pm UTC](https://discourse.julialang.org/t/esc-asymmetry-between-public-and-export/127420 "2025-03-27T14:23:46Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![PatrickHaecker](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/patrickhaecker/32/222891_2.png) [@PatrickHaecker](https://discourse.julialang.org/u/PatrickHaecker)
#### Post date: [March 27, 2025, 2:23pm UTC](https://discourse.julialang.org/t/esc-asymmetry-between-public-and-export/127420/1 "2025-03-27T14:23:46Z")

</div>

I think I understood the semantic difference between `export` and `public`.

However, besides this semantic difference I thought that I can always exchange them syntactically. However, this does not seem to be the case.

In the following, only `@mypublic` fails with `ERROR: syntax: malformed "public" statement`, while `@myexport` does not result in an error (tested both on 1.11.4 and nightly).

```julia
macro mypublic()
    Expr(:public, :a)
end
@mypublic

macro mypublic_esc()
    Expr(:public, :a) |> esc
end
@mypublic_esc
 
macro myexport()
    Expr(:export, :a)
end
@myexport

macro myexport_esc()
    Expr(:export, :a) |> esc
end
@myexport_esc

```

Why is this the case? Where is this difference documented?

---

<div class="post-metadata">

### Author: ![GunnarFarneback](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gunnarfarneback/32/1827_2.png) [@GunnarFarneback](https://discourse.julialang.org/u/GunnarFarneback)
#### Post date: [March 27, 2025, 2:39pm UTC](https://discourse.julialang.org/t/esc-asymmetry-between-public-and-export/127420/2 "2025-03-27T14:39:21Z")

</div>

Some of the asymmetry between `public` and `export` is explained in the comments to [Make `public` parse similar to `export` · Issue #502 · JuliaLang/JuliaSyntax.jl · GitHub](https://github.com/JuliaLang/JuliaSyntax.jl/issues/502). I suspect there are similar reasons for this discrepancy.

---

<div class="post-metadata">

### Author: ![PatrickHaecker](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/patrickhaecker/32/222891_2.png) [@PatrickHaecker](https://discourse.julialang.org/u/PatrickHaecker)
#### Post date: [March 27, 2025, 3:08pm UTC](https://discourse.julialang.org/t/esc-asymmetry-between-public-and-export/127420/3 "2025-03-27T15:08:46Z")

</div>

> [@GunnarFarneback](#):
>
> Some of the asymmetry between `public` and `export` is explained in the comments to [Make `public` parse similar to `export` · Issue #502 · JuliaLang/JuliaSyntax.jl · GitHub](https://github.com/JuliaLang/JuliaSyntax.jl/issues/502). I suspect there are similar reasons for this discrepancy.

Thanks, very enlightening. However, I keep it open for the moment, as the linked discussion focuses on global scope vs local scope, which does not seem to apply here. Although the motivation is probably similar, I would still like to understand the motivation for the difference with `esc`.
