# \`import\` can’t load just-defined modules? Can’t re-\`export\` in-module functions?

**URL:** <https://discourse.julialang.org/t/import-can-t-load-just-defined-modules-can-t-re-export-in-module-functions/4168>\
**Category:** New to Julia\
**Tags:** question\
**Created:** [June 9, 2017, 2:38am UTC](https://discourse.julialang.org/t/import-can-t-load-just-defined-modules-can-t-re-export-in-module-functions/4168 "2017-06-09T02:38:57Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![fasiha](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fasiha/32/1146_2.png) [@fasiha](https://discourse.julialang.org/u/fasiha)\
**Post date:** [June 9, 2017, 2:38am UTC](https://discourse.julialang.org/t/import-can-t-load-just-defined-modules-can-t-re-export-in-module-functions/4168/1 "2017-06-09T02:38:57Z")

</div>

I’m making a little Julia app: in `foo.jl` I have,

```julia
println("Hi!")

```

Then I realize I have some more functionality to add and I want it to be in its own module for code reuse. So in this directory, I create `bar/src/bar.jl` and in there I put the following:

```julia
module bar

function bar1(n)
  return n + 1
end

export bar1

```

Then back in `foo.jl` (my script/app) I add

```julia
push!(LOAD_PATH, ".")
import bar
println(bar.bar1(10))

```

Running `julia foo.jl` I am happy to see:

```julia
Hi!
11

```

So far so good.

(Foreshadowing: the problem starts here.)

Now I realize I want to add some more functionality to module `bar` and but I want this new functionality to be in its own file-level module. Again, for code reuse—it’s probably my Node.js background, we made `leftpad` a module. So I make `bar/src/baz.jl` and in it I put:

```julia
module baz

function baz1(n)
  return n * 2
end

export baz1

end

```

Back in `bar/src/bar.jl`, I replace the `export` line with the following:

```julia
include("baz.jl")
import baz # <-- error 1
export bar1, baz.baz1 # <-- error 2

```

1. I can’t `import baz`, even though I’ve just defined it through `include`. Julia suggests I `Pkg.add("baz")`, complecting modules and packages.
2. The second, more minor, point, is that `export baz.baz1` is a syntax error—I can’t have `.` in export lines.

I can fix both these problems like this:

```julia
include("baz.jl")
baz1 = baz.baz1
export bar1, baz1

```

I can successfully use `bar.baz1` in `foo.jl`. This tells me Julia knows about module `baz` after I `include` its source file, so, why can’t I `import` it? I’m a pro-`import`-anti-`using` partisan, because I like being able to know, in any given file, which module any non-base function/type comes from (blame my Python background, `from numpy import *` is a no–no), so I’d like that `import baz` there.

**Question 1** Is there a way to `import baz` here? _ **Edit: yes, `import .baz`!** _

**Question 2** Are there historic reasons for why `export baz.baz1` is a syntax error (`LoadError: syntax: extra token "." after end of expression`)? I would love to be able to re-export functions without having to create local shadows of them, i.e., `baz1 = baz.baz1; export baz1` as I had to do above.

---

<div class="post-metadata">

**Author:** ![fasiha](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fasiha/32/1146_2.png) [@fasiha](https://discourse.julialang.org/u/fasiha)\
**Post date:** [June 9, 2017, 2:43am UTC](https://discourse.julialang.org/t/import-can-t-load-just-defined-modules-can-t-re-export-in-module-functions/4168/2 "2017-06-09T02:43:36Z")

</div>

Ah. Reading the [modules docs](https://docs.julialang.org/en/release-0.5/manual/modules/#relative-and-absolute-module-paths) more closely, I see I can solve my question #1 with:

```julia
import .baz # notice the dot 😄!

```

Great!!! I’ll leave this question open to get insight into my #2, why I can’t `export baz.baz1`.

---

<div class="post-metadata">

**Author:** ![yuyichao](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yuyichao/32/20_2.png) [@yuyichao](https://discourse.julialang.org/u/yuyichao)\
**Post date:** [June 9, 2017, 3:11am UTC](https://discourse.julialang.org/t/import-can-t-load-just-defined-modules-can-t-re-export-in-module-functions/4168/3 "2017-06-09T03:11:18Z")

</div>

> [@fasiha](#):
>
> I would love to be able to re-export functions without having to create local shadows of them

No. the thing you export will always be a field of the module which is a global variable in the module. So in your case `baz.bar1` has to exist which means `bar1` has to be in module `baz`. Convenient syntax for reexporting/conditional (sub)modules are the kind of related features we want. Changing how export / name resolution work doesn’t seem to worth doing unless there are very convincing cases where it can’t be done otherwise.

---

<div class="post-metadata">

**Author:** ![fasiha](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fasiha/32/1146_2.png) [@fasiha](https://discourse.julialang.org/u/fasiha)\
**Post date:** [June 9, 2017, 3:14am UTC](https://discourse.julialang.org/t/import-can-t-load-just-defined-modules-can-t-re-export-in-module-functions/4168/4 "2017-06-09T03:14:32Z")

</div>

Thanks for weighing in!

> [@yuyichao](#):
>
> So in your case baz.bar1 has to exist which means bar1 has to be in module baz.

Am I reading this to mean `export baz.baz1` should work? Because in my example, `baz1` _is_ in the module `baz`, but that syntax was unacceptable. Am I missing something?

---

<div class="post-metadata">

**Author:** ![yuyichao](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yuyichao/32/20_2.png) [@yuyichao](https://discourse.julialang.org/u/yuyichao)\
**Post date:** [June 9, 2017, 5:25am UTC](https://discourse.julialang.org/t/import-can-t-load-just-defined-modules-can-t-re-export-in-module-functions/4168/5 "2017-06-09T05:25:43Z")

</div>

`s/baz/bar/`
