To start off, I should first mention my agreement with @stevengj 's previous post. It is highly likely that you would benefit overall by creating an actual package to house your new code.
Having said that, I noticed there being much confusion regarding the differences between
import. I think it is worth explaining these differences so you can avoid pitfalls like the one your issue has hilighted.
include(): What does it do?
Applying terminology typical programmers seem more familiar with: we could almost say that:
causes Julia to “compile”
some_file_with_code.jl — inline with said call (i.e. at the location/time the compiler reaches your call to
However, if I am to use more accurate terminology, I believe you should say that the Julia parser “parses” that file, and performs code lowering in order to store various symbols, modules, functions, etc. into a complex tree of data structures… Because what is technically known as the “compilation process” actually happens at a later time.
Point being, the code you
include() is available for use immediately after the call. Upon
inclu-sion, Julia generates the appropriate symbols, and makes them available to your current scope…
And if you are wondering, calling:
from the Julia prompt makes the newly “lowered” code available in the module named >>
using: What does it do?
In the case where we are dealing with pure modules (not full-blown packages),
using SomeModuleSymbol gets Julia to import a symbol (here: your module’s name) into the current namespace.
Note that it would also automatically import any symbols that have been marked for exporting using "
export statements" (had you included any inside your module).
“Ok. So what’s wrong with my code?” (paraphrasing)
First off, when you:
include("name_module.jl"), Julia does the whole code-lowering thing, and makes “
name_module” available in your namespace.
Then, when you call:
Julia tries to re-import “
name_module” that is already available in said namespace.
So what do I do to fix this?
There is simply no need for the “
using .name_module” command in your example.
Instead, you can immediately start using the module that was made available by calling “
include("name_module.jl")”, as done here:
#using .name_module #Nope: Will re-import already existing symbol
#Just start using the module that is now available:
# rest of the code