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
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
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.
# Put your function here or in a separate file as you'd like:
# this is not what's causing the problem here...
a = add1(3)
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.