Got a looping of "warning: replacing module myModule"

Hi. I have a folder with four .jl file. One is the module file with name myModule.jl, the second one type.jl is the file with all the type definitions, the third one gen_csv file is the file of function definitions, the forth one example.jl is the main file I’d like to test. In the module myModule.jl, I export myFunction.

Now, in the example.jl, I put
include(“myModule.jl”)
myFunction(myParameter)

this function myFunction is defined in the file gen_csv.jl.

But I got an error, saying that
UndefVarError: myFunction not defined.

I was deeply confused. :((( Any help please?

The other concern is, I’m using Atom to run the file. After keeping running it, I got an error, saying that "warning: replacing module myModule. I do not know why. Could anyone please help me?

Could you please provide a complete Minimal (Non-)Working Example of what you’re trying to do? And also quote your code?


That being said, I think what you are missing is a statement which imports your module (cf. Modules, such as

using MyModule

When you only include("myModule.jl"), you make Julia load all the code it contains (and therefore it is aware of the existence of the module). But you have to also “import” the module, i.e. tell Julia that you actually want (some of) what it defines to be brought into your current scope.

@ffevotte, here is a toy example.
file main.jl

push!(LOAD_PATH,“\home\devel\Desktop\123\myModule”)
using myModule
a=add1(2)
println(a)

file myModule.jl

module M
export add1

include(“myFunc.gl”)

file myFunc.jl

function add1(x)
x+1
end

I run the main file main.jl and got an error, Argument error, module m not found in current path.

1 Like

@ffevotte I’m using atom, if that’s helpful.

Something like this should work:

/some/path/MyModule.jl:

module MyModule

export add1

# Put your function here or in a separate file as you'd like:
# this is not what's causing the problem here...
function add1(x)
    x+1
end

end

main.jl:

push!(LOAD_PATH,"/some/path/")
using MyModule

a = add1(3)
println(a)

However, instead of manually fiddling with your LOAD_PATH, you would probably be better off creating your own project. When you activate a project, you don’t have to tell Julia where modules are: the standard files layout helps it find your source code.

1 Like

@ffevotte, thank you so much. I’m using Julia 0.6. Does it still work with a this project layout?

@ffevotte it works. but i think there should be a better way to do it, beside the project method you mentioned.

I’m not sure, but I would think it does not work the same way in v0.6: as far as I know, the packages / modules evolved considerably in v0.7 & v1.0…