Issue: no way to include only once.

https://github.com/JuliaLang/julia/issues/30597

Hi all!

After the last reply I still cannot just import without include.
And include several times (per each Storage.) going into the same.

Also, is there a way to have modules with the same name in a project in different subdirectories?

Note that this is exactly what issue#4600 is about so no, not for now. And from the way you’ve described it, i.e. “import without include” I hope it’s clear that this is a feature that belongs to import, not include. So include once really isn’t what you are looking for. It’s not even well defined and has no way to know anything about namespace. (If you make it namespace aware, it won’t be include anymore…)

In general, include is the function to organize code at a lower level since julia doesn’t enforce a 1-1 correspondence between file and module. import is the feature to, well, import names between namespaces (module).

The current way to do this is to figure out a correct way to include all code that satisfies your dependency requirement. Compared to python, this gives more flexibility, which is useful sometimes (certainly not always). You can recreate a python like nested structure by creating a tree-like include structures, see for example the DataStructures.jl → heaps.jl → heaps/*.jl include tree. It’s certainly not as automatic (#4600 will change that) but I’ve also have experience that when not keeping track of dependency in python explicitly, I’ve run into more import loops than I wish that are solved mostly by falling back to a global import order…

1 Like