Importing Functions from module

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

module DVHMetric
using SpecialFunctions: erf

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

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

        function NTCP(EUD,D_50,m)

        function TCP(D,V,D_50,γ_50)
        end # function
export probit, EUD, NTCP, TCP

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.


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


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

You need to load the module with using (or import), see

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

using .DVHMetric

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

1 Like

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 :slight_smile: