Issue with Wildcard Import in Julia Module

Daniel_S
Thu, 14 Mar 2024 11:55:33 +0000
New to Julia

I’m encountering an issue with wildcard imports (“import .ModuleName: *”) in Julia. Specifically, when attempting to import all symbols from a module using the wildcard syntax, the symbols do not seem to be available in the importing file.

Here’s an example:

Module definition:

# Module file: ModuleA.jl
module ModuleA
export *

function functionA(arg1::AbstractString, arg2::AbstractString)
    # Function A implementation
end

function functionB(arg1::AbstractString, arg2::AbstractString)
    # Function B implementation
end

end

Main file:

# Main file: main.jl
include("ModuleA.jl")
import .ModuleA: *

functionA("arg1", "arg2")  # Error: functionA not defined

When I attempt to import all symbols from the “ModuleA” module using “import .ModuleA: *”, the “functionA” function is not recognized in the main file, resulting in an error. However, when I specifically import the “functionA” function using “import .ModuleA: functionA”, it works as expected.

I want to use the wildcard import to keep the code more readable and avoid listing individual functions. What could be causing this issue?

I use Juliav1.6 in VS-Code.

Any help or insights would be greatly appreciated. Thank you!

5 posts - 4 participants