User defined functions in Julia

Dear All,

I would like to ask, how can I call functions in main file using Julia.

for example:

if I write top(60,20,0.5,3,3), the solver does not know that there is a function which is the so called top.

Kind regards,

include("top.jl") first and then execute the function. Julia doesn’t work like MATLAB where the presence of a file means a function with the filename exist in the namespace.


If I want to use many files, in MATLAB, I can put all funcs in the same folder, but how in JULIA?

e.g. in main file I call A, B,C,D,
in A file, I call D,E,F
in C file, I call E,F
and in F file, I call A,D,E,F

Julia won’t know anything about functions in a folder unless you explicitly include them using include("A.jl"). It’s not anything like MATLAB.

I would include all the files containing the functions you need at the top of your main file. Then you can use them from main, and the functions will know about each other too.


In Julia (not all caps, BTW), you don’t need to put one function per file, and normally you should not.

If you have so much code that you are breaking it into multiple files, normally you would define a module in Julia. (This will have one top-level file MyModule.jl that incorporates the other files via include.)