Confused about intent of using/import (docs)

I was reading the (new v1.7) docs on modules (Standalone using and import):
https://docs.julialang.org/en/v1.7-dev/manual/modules/#Standalone-using-and-import

Specifically:

Possibly the most common way of loading a module is using ModuleName. This loads the code associated with ModuleName, and brings

  1. the module name
  2. and the elements of the export list into the surrounding global namespace.

I understand the two points, but I find the first two sentences confusing. I’m guessing they are probably incorrect.

Confusion

Is the above statement this really the intent? I ask because I know there is talk of changes to allow using and import to recognize files in the source tree:
relative using/import should search current directory · Issue #4600 · JuliaLang/julia · GitHub

AFAIK, the current solution allows the use of using and import to load packages (not modules).

At the moment, I thought non-package modules were already loaded (otherwise, Julia wouldn’t recognize the symbol), and so:

  • import moda basically does nothing (symbol already available),
  • import moda.submodule makes submodule symbol directly available, and
  • using moda makes all exported symbols from moda available in current scope.

I am not entirely sure what is your point. using may be used to load modules that are not packages. Example:


module Outer
    module Inner
        f(a) = 2*a
        export f
    end
    using .Inner
    g(a) = f(a) * 2
    export g
end

@Henrique_Becker: My issue is a question of using precise (correct) words to avoid confusing the reader.

The using .Inner statement you use here does not actually load module Inner. That module was loaded when the Julia interpreter read through your code.

The only thing that the using .Inner statement does in your case is “import” symbols that module Inner “export”-ed. That’s the 3rd point I made in my first entry:

Why so pedantic?

I think it is imperative to use precise words for this document on modules & packages, because many of these concepts can be somewhat tricky and (possibly) unique to Julia. I have recently been reading several questions from new (and sometimes seasoned) Julia users who appear to have a confused mental model of the module/package system.

So my question is mostly to understand if I should make a PR to correct this statement, or find out if I am truly mistaken in my own understanding of the using & import statements.

3 Likes

I want to applaud this goal of language precision. Equivalents (or not) of modules, packages, namespaces, etc are among the important basic distinguishing features of programming languages. Variable scope is another that inspires posts here.

For example, many languages have a import keyword. Learning a new language and assuming the semantics of import are equivalent is fraught with peril.

I also praise your dedication on being precise, but I really did not understood what exactly you were reaching for; if it is “permission” to do a PR I think you should just go for it. Six days ago I did see minor imprecision in a eval/scope phase of the documentation, opened a PR just to change the ending of the phrase, and Stefan just approved and merged it right after. I think that if it is clear to you what should be amended, just open a PR and let the maintainers give a look at it.

1 Like

That’s probably the easiest thing to do @Henrique_Becker.

I don’t like the idea of potentially undoing someone’s work, but I guess you are right: someone with more insight will probably intervene if my changes are inaccurate. Thanks.

1 Like