# Using symbols from parent module without naming it

**URL:** <https://discourse.julialang.org/t/using-symbols-from-parent-module-without-naming-it/101833>\
**Category:** General Usage\
**Tags:** question\
**Created:** [July 20, 2023, 11:57am UTC](https://discourse.julialang.org/t/using-symbols-from-parent-module-without-naming-it/101833 "2023-07-20T11:57:22Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![algunion](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/algunion/32/51630_2.png) [@algunion](https://discourse.julialang.org/u/algunion)\
**Post date:** [July 20, 2023, 1:48pm UTC](https://discourse.julialang.org/t/using-symbols-from-parent-module-without-naming-it/101833/3 "2023-07-20T13:48:48Z")

</div>

How about this: `@.. c` (or `@.. c d e` - if you need to import multiple symbols).

The macro definition here:

```julia
macro (..)(s...)
    Expr(:using,
        Expr(:(:), Expr(:., :., :., Symbol(nameof(parentmodule( __module__ )))),
            (Expr(:., (Symbol(x))) for x in s)...))
end

```

In your context:

```julia
module Foo
const c = 1
const d = 2
module Bar

macro (..)(s...)
    Expr(:using,
        Expr(:(:), Expr(:., :., :., Symbol(nameof(parentmodule( __module__ )))),
            (Expr(:., (Symbol(x))) for x in s)...))
end

# works with importing multiple symbols
@.. c d

fc() = c
fd() = d

@info "happy import: " fc() fd()

end
end

```

Running the program would produce:

```julia
┌ Info: happy import: 
│ fc() = 1
└ fd() = 2

```

Not sure if this is reliable enough for any context (limited testing) - I am sure it can be improved.

Later edit: the initial version only worked if the macro was defined inside the calling module. The current version of the macro works even if defined in module X and invoked from Y (it will still import symbols from the parent of Y).

LE2: renamed it for more convenience. You can invoke it by `@.. c d e f g`.

---

_[View the full topic](https://discourse.julialang.org/t/using-symbols-from-parent-module-without-naming-it/101833)._
