# "using" keyword in Julia

**URL:** <https://discourse.julialang.org/t/using-keyword-in-julia/28419>\
**Category:** General Usage\
**Created:** [September 5, 2019, 8:43am UTC](https://discourse.julialang.org/t/using-keyword-in-julia/28419 "2019-09-05T08:43:15Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![bsnyh](https://avatars.discourse-cdn.com/v4/letter/b/ce7236/32.png) [@bsnyh](https://discourse.julialang.org/u/bsnyh)\
**Post date:** [September 5, 2019, 8:43am UTC](https://discourse.julialang.org/t/using-keyword-in-julia/28419/1 "2019-09-05T08:43:16Z")

</div>

I’m a bit confused about the “using” keyword in Julia.

```julia
using OpenStreetMapX
distance1(a::ECEF, b::ECEF) =....

```

The above code works. On the other hand, if inside of a module, say module myModule,

```julia
module myModule
using OpenStreetMapX
......
end

```

then

```julia
using myModule
distance1(a::ECEF, b::ECEF) =....

```

does not work. Apparently, the ECEF is not recognisable. This is rather strange from my understanding.

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [September 5, 2019, 8:50am UTC](https://discourse.julialang.org/t/using-keyword-in-julia/28419/2 "2019-09-05T08:50:03Z")

</div>

You are asking a very general question, with a very specific reference to a particular package, yet without any runable code, or what “does not work” means in this context. This makes it hard to help you.

That said, I am guessing that you want to define a method for `OpenStreetMapX.distance`. Either `import` it, or qualify with the package name. Please read  
[https://docs.julialang.org/en/v1/manual/modules/](https://docs.julialang.org/en/v1/manual/modules/)

Also, you seem to be asking a lot of general Julia questions here (which is fine), but all somehow involving `OpenStreetMapX`. Even if your work focuses on this specific package, I would suggest that you consider reading the general Julia docs multiple times carefully, so that you gain a better understanding about the language. I think it would help you in the long run.

Finally, please consider reading

> [@Please read: make it easier to help you](https://discourse.julialang.org/t/psa-make-it-easier-to-help-you/14757):
>
> Welcome to the Julia Discourse! We are enthusiastic about helping Julia programmers, both beginner and experienced. This public service announcement (PSA) outlines best practices when asking for help. Following these points makes it easier for us to help you and more likely you’ll get a prompt, useful answer. Keywords are highlighted to make it easier to refer to specific points. Choose a descriptive title that captures the key part of your question, eg “plots with multiple axes” instead of …

---

<div class="post-metadata">

**Author:** ![bsnyh](https://avatars.discourse-cdn.com/v4/letter/b/ce7236/32.png) [@bsnyh](https://discourse.julialang.org/u/bsnyh)\
**Post date:** [September 5, 2019, 8:51am UTC](https://discourse.julialang.org/t/using-keyword-in-julia/28419/3 "2019-09-05T08:51:34Z")

</div>

Thank you.

---

<div class="post-metadata">

**Author:** ![KajWiik](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kajwiik/32/199_2.png) [@KajWiik](https://discourse.julialang.org/u/KajWiik)\
**Post date:** [September 5, 2019, 8:54am UTC](https://discourse.julialang.org/t/using-keyword-in-julia/28419/4 "2019-09-05T08:54:13Z")

</div>

Maybe you are after this functionality:  
[https://github.com/simonster/Reexport.jl](https://github.com/simonster/Reexport.jl)

---

<div class="post-metadata">

**Author:** ![bsnyh](https://avatars.discourse-cdn.com/v4/letter/b/ce7236/32.png) [@bsnyh](https://discourse.julialang.org/u/bsnyh)\
**Post date:** [September 5, 2019, 8:57am UTC](https://discourse.julialang.org/t/using-keyword-in-julia/28419/5 "2019-09-05T08:57:41Z")

</div>

```julia
using myModule
distance1(a::ECEF, b::ECEF) =....

```

When I run the above code, it gives me “UndefVarError: ECEF not defined”. It’s a bit strange. Because I have “using myModule” in the same file, and inside of the module “myModule.jl”, I have “using OpenStreetMapX”.

---

<div class="post-metadata">

**Author:** ![MatFi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/matfi/32/10002_2.png) [@MatFi](https://discourse.julialang.org/u/MatFi)\
**Post date:** [September 5, 2019, 9:00am UTC](https://discourse.julialang.org/t/using-keyword-in-julia/28419/6 "2019-09-05T09:00:08Z")

</div>

Just implement Reexport ( as KajWiik mentioned)

```julia
module myModule
 using Reexport
 @reexport using OpenStreetMapX
......
end

```

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [September 5, 2019, 9:03am UTC](https://discourse.julialang.org/t/using-keyword-in-julia/28419/7 "2019-09-05T09:03:28Z")

</div>

Yes, but that `using OpenStreetMapX` brings the exported symbols of the latter into the namespace of `myModule`. They are available as eg `myModule.ECEF`, but since they are not exported to `Main`, you don’t see them there.

Personally I find something like

```julia
using OpenStreetMapX, myModule

```

conceptually cleaner than reexporting things.

---

<div class="post-metadata">

**Author:** ![MatFi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/matfi/32/10002_2.png) [@MatFi](https://discourse.julialang.org/u/MatFi)\
**Post date:** [September 5, 2019, 9:11am UTC](https://discourse.julialang.org/t/using-keyword-in-julia/28419/8 "2019-09-05T09:11:17Z")

</div>

> [@Tamas\_Papp](#):
>
> They are available as eg `myModule.ECEF` , but since they are not exported to `Main` , you don’t see them there.

So an better solution when only `ECEF` is needed outside the module, could be

```julia
module myModule
 using OpenStreetMapX
 export ECEF
......
end

```

---

<div class="post-metadata">

**Author:** ![bsnyh](https://avatars.discourse-cdn.com/v4/letter/b/ce7236/32.png) [@bsnyh](https://discourse.julialang.org/u/bsnyh)\
**Post date:** [September 5, 2019, 9:13am UTC](https://discourse.julialang.org/t/using-keyword-in-julia/28419/9 "2019-09-05T09:13:17Z")

</div>

I did this earlier, but then I deleted it from the module “myModule.jl”. Thank you a lot.

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [September 5, 2019, 9:20am UTC](https://discourse.julialang.org/t/using-keyword-in-julia/28419/10 "2019-09-05T09:20:29Z")

</div>

Perhaps you missed what I suggested above: simply `using OpenStreetMapX` in `Main`, too.

I don’t think that reexporting is a better solution, except possibly in a user-facing umbrella package that uses other modules/packages as internal implementation details (but that does not seem to be the case here, `OpenStreetMapX` is a package designed for direct use).

Fine-grained control over namespaces may seem tedious at first, but it is generally valuable as it is very easy to clutter your namespace and get conflicts even in medium-sized projects.

---

<div class="post-metadata">

**Author:** ![MatFi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/matfi/32/10002_2.png) [@MatFi](https://discourse.julialang.org/u/MatFi)\
**Post date:** [September 5, 2019, 9:30am UTC](https://discourse.julialang.org/t/using-keyword-in-julia/28419/11 "2019-09-05T09:30:28Z")

</div>

Ok the point is yours…
