# User defined functions in Julia

**URL:** <https://discourse.julialang.org/t/user-defined-functions-in-julia/19426>\
**Category:** New to Julia\
**Created:** [January 9, 2019, 1:08pm UTC](https://discourse.julialang.org/t/user-defined-functions-in-julia/19426 "2019-01-09T13:08:18Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Aquaman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aquaman/32/6586_2.png) [@Aquaman](https://discourse.julialang.org/u/Aquaman)\
**Post date:** [January 9, 2019, 1:08pm UTC](https://discourse.julialang.org/t/user-defined-functions-in-julia/19426/1 "2019-01-09T13:08:18Z")

</div>

Dear All,

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

for example: [GitHub - blademwang11/Topopt: Topology optimization by Julia](https://github.com/blademwang11/Topopt)

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,  
Yaakov

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [January 9, 2019, 1:10pm UTC](https://discourse.julialang.org/t/user-defined-functions-in-julia/19426/2 "2019-01-09T13:10:41Z")

</div>

`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.

---

<div class="post-metadata">

**Author:** ![Aquaman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aquaman/32/6586_2.png) [@Aquaman](https://discourse.julialang.org/u/Aquaman)\
**Post date:** [January 9, 2019, 6:54pm UTC](https://discourse.julialang.org/t/user-defined-functions-in-julia/19426/3 "2019-01-09T18:54:40Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![aaowens](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aaowens/32/12101_2.png) [@aaowens](https://discourse.julialang.org/u/aaowens)\
**Post date:** [January 9, 2019, 7:11pm UTC](https://discourse.julialang.org/t/user-defined-functions-in-julia/19426/4 "2019-01-09T19:11:01Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [January 9, 2019, 7:11pm UTC](https://discourse.julialang.org/t/user-defined-functions-in-julia/19426/5 "2019-01-09T19:11:09Z")

</div>

> [@Aquaman](#):
>
> If I want to use many files, in MATLAB, I can put all funcs in the same folder, but how in JULIA?

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](https://docs.julialang.org/en/latest/manual/modules/#Modules-and-files-1). (This will have one top-level file `MyModule.jl` that incorporates the other files via `include`.)
