Cant use module normally

martin_sanchez
Thu, 08 Aug 2024 20:24:36 +0000
General Usage

In This tutorial they even have an online code executer in which they set the example of using a module. They first have a file mymodule.jl in which they write:

`module MyModule

export sum_function, resta

function sum_function(a, b)
return a + b
end
function resta(a,b)
a-b
end
end # end of module definition`

And a main.jl file in which they write:

include("mymodule.jl")
using MyModule

result = resta(2, 3)

print(result)

When I try to mimic this same structure in my files, I have a file called cont_stoch_proc.jl in which I have a toy example:

module ContStochProc
export f

function f(x, y,z...)
    value=x*y
    for i in z
        value+=i
    end
    return value
end
end # module ContStochProc

And a file called prueba.jl in which I have:

include("cont_stoch_proc.jl")
using ContStochProc
f(2,3,1,1,1,1,1)

But when I run it, it shows me an error, signaling I do not have that module in my path

ERROR: ArgumentError: Package ContStochProc not found in current path, maybe you meant `import/using .ContStochProc`.

First question would be why does it work on the web but not in my project? I also realized that it works only if I write

using Main.ContStochProc

So why only in my project I need to use the “Main.” module path to run it? (this also happens if I try to use import ContStochProc.f as is used in the example

5 posts - 4 participants