# Importing Functions from module

**URL:** <https://discourse.julialang.org/t/importing-functions-from-module/34413>\
**Category:** New to Julia\
**Created:** [February 10, 2020, 2:10pm UTC](https://discourse.julialang.org/t/importing-functions-from-module/34413 "2020-02-10T14:10:51Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![samantp](https://avatars.discourse-cdn.com/v4/letter/s/f475e1/32.png) [@samantp](https://discourse.julialang.org/u/samantp)\
**Post date:** [February 10, 2020, 2:10pm UTC](https://discourse.julialang.org/t/importing-functions-from-module/34413/1 "2020-02-10T14:10:51Z")

</div>

I’m quite confused about what exactly a module is. As I understand it a module is just a collection of functions that I can import, similar to a package. So, I have four functions that I want to import that I have put into a module, as below, in a file called `DVHMetric.jl`

```julia
module DVHMetric
using SpecialFunctions: erf

        function probit(x) #Probit function
                return 0.5*(1+erf(x/sqrt(2)))
        end

        function EUD(D,V,n) #EUD summation
                return sum(V.*(D.^(1/n))).^n
        end

        function NTCP(EUD,D_50,m)
                probit((EUD-D_50)/(m*D_50))
        end

        function TCP(D,V,D_50,γ_50)
                (1/2)^(sum(V.*exp(2*γ_50*(1-D/d_50)/log(2))))
        end # function
export probit, EUD, NTCP, TCP
end

```

If I understand correctly, the code above writes four functions and specifies that those four functions are what is contained in the module (in the export line).

Now, in a separate script, I want to import this module and call its functions using their given names. So I have tried the following in a script that is saved in the same directory as the module.

```julia
include("DVHMetric.jl")
probit(2)

```

However I get an error that probit is not defined. I have also tried `import DVHMetric` and `using DVHMetric` both of which return errors saying “Package DVHMetric not found in current path”.

So, how do I import this module and use its functions as I have named them? I was able to call the functions using the syntax below without issue

```julia
include("DVHMetric.jl")
DVHMetric.probit(2)

```

but I want to use the previous syntax where I just call probit.

---

<div class="post-metadata">

**Author:** ![fredrikekre](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fredrikekre/32/1688_2.png) [@fredrikekre](https://discourse.julialang.org/u/fredrikekre)\
**Post date:** [February 10, 2020, 2:15pm UTC](https://discourse.julialang.org/t/importing-functions-from-module/34413/2 "2020-02-10T14:15:08Z")

</div>

You need to load the module with `using` (or `import`), see [Modules · The Julia Language](https://docs.julialang.org/en/v1/manual/modules/#Summary-of-module-usage-1).

Since you don’t define a package, just a module that you include, you need a `.` in front, so probably something like

```julia
include("CVHMetric.jl")
using .DVHMetric

```

You can also set it up like a proper package and load it with just `using DVHMetric`.

---

<div class="post-metadata">

**Author:** ![samantp](https://avatars.discourse-cdn.com/v4/letter/s/f475e1/32.png) [@samantp](https://discourse.julialang.org/u/samantp)\
**Post date:** [February 10, 2020, 2:17pm UTC](https://discourse.julialang.org/t/importing-functions-from-module/34413/3 "2020-02-10T14:17:56Z")

</div>

Thank you! the . was the issue in my case. I am not quite sure how to set it up like a proper package so this will do for now 🙂
