Using a module defined in REPL

julia> module A
       a = 1
       b = 2
       end
Main.A

julia> a
ERROR: UndefVarError: `a` not defined

julia> A.a
1

julia> A.b
2

julia> using A
ERROR: ArgumentError: Package A not found in current path, maybe you meant `import/using .A`.
- Otherwise, run `import Pkg; Pkg.add("A")` to install the A package.
Stacktrace:
 [1] macro expansion
   @ Base .\loading.jl:1766 [inlined]
 [2] macro expansion
   @ Base .\lock.jl:267 [inlined]
 [3] __require(into::Module, mod::Symbol)
   @ Base .\loading.jl:1747
 [4] #invoke_in_world#3
   @ Base .\essentials.jl:921 [inlined]
 [5] invoke_in_world
   @ Base .\essentials.jl:918 [inlined]
 [6] require(into::Module, mod::Symbol)
   @ Base .\loading.jl:1740

why is it wrong?

you need to use a dot:

using .A

see this section of the manual.

To load a module from a package, the statement using ModuleName can be used. To load a module from a locally defined module, a dot needs to be added before the module name like using .ModuleName .

5 Likes

and write export a, b if using .A is supposed to bring the names a and b into the current global scope. Alternative to unspecific using accessing the export list, you could also specify any names even the unexported ones: using A: a, b.