# How to import functions defined in a Julia script file without running the script itslef

**URL:** <https://discourse.julialang.org/t/how-to-import-functions-defined-in-a-julia-script-file-without-running-the-script-itslef/6603>\
**Category:** General Usage\
**Created:** [October 21, 2017, 9:52pm UTC](https://discourse.julialang.org/t/how-to-import-functions-defined-in-a-julia-script-file-without-running-the-script-itslef/6603 "2017-10-21T21:52:54Z")\
**Posts on this page:** 1\
**Showing post:** 15

<div class="post-metadata">

**Author:** ![lucatrv](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lucatrv/32/5650_2.png) [@lucatrv](https://discourse.julialang.org/u/lucatrv)\
**Post date:** [October 29, 2017, 10:34pm UTC](https://discourse.julialang.org/t/how-to-import-functions-defined-in-a-julia-script-file-without-running-the-script-itslef/6603/15 "2017-10-29T22:34:48Z")

</div>

After lots of searching and reading, I think now I have a better understanding on how Julia code should be organized in modules to make it reusable.  
I have to say that the [“Modules” section of the official Julia documentation](https://docs.julialang.org/en/latest/manual/modules/) (which I had already read before starting this thread) did not help me very much on this, while I found more useful the [“Modules and packages” section of the “Introducing Julia” Wikibook](https://en.wikibooks.org/wiki/Introducing_Julia/Modules_and_packages).  
What however finally opened my eyes are the following two GitHub threads (I add the links here thinking they may be useful for others in future hitting this discussion):  
[https://github.com/JuliaLang/julia/issues/4600](https://github.com/JuliaLang/julia/issues/4600)  
[https://github.com/JuliaLang/julia/issues/23619](https://github.com/JuliaLang/julia/issues/23619)  
IMHO the Julia documentation should eventually include more insight and examples on this topic, but I understand that some important details are still under discussion, so I guess we should wait for them to be completely defined and implemented.

Now I feel I am starting to think more Julia than Python, so if you agree in order to make the `julia-config.jl` functions reusable in `juliac.jl` I am going to submit a PR with the following edits:

- Take all reusable functions out from the `julia-config.jl` script, and put them in a `JuliaConfig.jl` script.
- In the `JuliaConfig.jl` script, wrap all the code within a module named `JuliaConfig`, and export all reusable functions (`cflags`, `ldflags`, `ldlibs`, `allflags`).
- In the `julia-config.jl` script add the following lines:

```julia
include("JuliaConfig.jl")
using .JuliaConfig

```

- Similarly, in the `juliac.jl` script add the following lines:

```julia
include(joinpath("path_to_JuliaConfig", "JuliaConfig.jl"))
using .JuliaConfig

```

If I understood correctly, this is the current syntax as of Julia v0.6 (please let me know otherwise).

In future, from the two GitHub threads linked above maybe the `include` statement will not be needed anymore, however in this case it is not clear to me how I would set the `"path_to_JuliaConfig"`. I am going to ask this question [there](https://github.com/JuliaLang/julia/issues/23619#issuecomment-340309489).

---

_[View the full topic](https://discourse.julialang.org/t/how-to-import-functions-defined-in-a-julia-script-file-without-running-the-script-itslef/6603)._
