Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Import a module and use it in julialang

Tags:

julia

Since in http://julia.readthedocs.org/en/latest/manual/modules/ there's no much info about modules, I would like to ask the following.

I want to try two modules via ijulia. Both modules are in my working directory as name-of-files.jul. I will call them generically module_1.jul and module_2.jul.

module_1.jul uses module_2.jul and I load it with

using module_2

On ijulia session, if I try

using module_1

gives an error. I also tried

include("module_1.jul")

This last sentence, when executed, rises an error because the module_1.jul cannot find variable "x" that I know is contained in module_1.jul (in this case I "loaded" the module using include("module2.jul") inside module_1.jul

like image 484
user2820579 Avatar asked Mar 25 '14 23:03

user2820579


1 Answers

Julias module system assumes some things that aren't necessarily obvious from the documenation at first.

  1. Julia files should end with .jl extensions.
  2. Julia looks for module files in directories defined in the LOAD_PATH variable.
  3. Julia looks for files in those directories in the form ModuleName/src/file.jl

If using module_1 fails then I'm guessing it's because it's source files fail one of the above criteria.

like image 69
Jeremy Wall Avatar answered Oct 02 '22 14:10

Jeremy Wall