Package in Julia
Say you wrote an ingeneous julia function
magic(x) = incredible(x)
And you want this to be available to other people. Then the first thing to do is to create a file called Magic.jl
with the follwoing content
module Magic
export magic
magic(x) = incredible(x)
end
And put this in a Directory /some/path/to/Magic/src
somewhere.
When you do
using Magic
magical = magic(24)
julia
looks for a module Magic in the environment variable LOAD_PATH
. In a julia session you can either do
push!(LOAD_PATH,"/some/path/to")
in every julia session and simply do using Magic
. Or as discussed in this post, you can put this line in ~/.julia/config/startup.jl
...
push!(LOAD_PATH,"/some/path/to")
...
And now the module Magic
is available to import
or using
in any julia session.