# Passing functions as default arguments to functions in sibling modules

**URL:** <https://discourse.julialang.org/t/passing-functions-as-default-arguments-to-functions-in-sibling-modules/58769>\
**Category:** New to Julia\
**Tags:** question, module\
**Created:** [April 7, 2021, 3:42pm UTC](https://discourse.julialang.org/t/passing-functions-as-default-arguments-to-functions-in-sibling-modules/58769 "2021-04-07T15:42:09Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![MattWillFlood](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mattwillflood/32/20722_2.png) [@MattWillFlood](https://discourse.julialang.org/u/MattWillFlood)\
**Post date:** [April 7, 2021, 3:42pm UTC](https://discourse.julialang.org/t/passing-functions-as-default-arguments-to-functions-in-sibling-modules/58769/1 "2021-04-07T15:42:09Z")

</div>

Hi Guys 🙂

Is there a way to pass a function from a submodule (saved in a separate file) as a default argument to a sibling function? 🤔  
As an example, say that my module is structured as follows:

```julia
module Parent

import A: a 
import B: b 
import C: c 
import Child: foo

export bar, a, b, c, other_objects

# Do some stuff here
end

----------------------------

# Child.jl
module Child
export foo

function foo(MyFunc::Function=Parent.a, x::Int=1, y::Float64=1.234)
# Do some other stuff here
end

end

```

Ultimately, I want to be able to

1. call submodule functions, e.g. `Parent.a()` / `Parent.b()` / …
2. call `Parent.foo()` with default arguments,
3. pass sibling module functions as arguments, e.g. `Parent.foo(MyFunc=Parent.b)`

I want to avoid `importing A: a, B: b, ...` within `Child.jl` if posssible.  
When I try to use this format, `Child` fails to precompile when I load `Parent`… 🙄

Any help would be greatly appreciated!  
Thanks 👍🏼🙏🏻

---

<div class="post-metadata">

**Author:** ![Henrique\_Becker](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/henrique_becker/32/15443_2.png) [@Henrique\_Becker](https://discourse.julialang.org/u/Henrique_Becker)\
**Post date:** [April 7, 2021, 6:02pm UTC](https://discourse.julialang.org/t/passing-functions-as-default-arguments-to-functions-in-sibling-modules/58769/2 "2021-04-07T18:02:03Z")

</div>

I use `import` with the number of dots equal to the number of steps back in the hierarchy it needs to go minus one (i.e., `.Module` for a module defined inside the current one, `..Module` for the parent module or a sibling module, and so on).

```julia
julia> module Parent
           const p = 1;
           module FirstChild; const fc = 2; end;
           module SecondChild
               import ..Parent
               f() = Parent.p; g() = Parent.FirstChild.fc
           end # SecondChild
       end # Parent

julia> Parent.SecondChild.f()
1

julia> Parent.SecondChild.g()
2

```

I am not aware this has any precompilation problems. Have you this installed as a package? If so maybe you are messing with precompilation because you are loading the package from withing the package, instead of loading a module by a path in the current module hierarchy.
