I have just started to learn Julia. I am having difficulty defining function input type. Consider this 3 files:
#Mymodule.jl
module Mymodule
export getP, point
mutable struct point
x::Int32
y::Int32
end
function getP()::point
return point(1,2)
end
ende here
#Mymodule2.jl
module Mymodule2
include("Mymodule.jl")
using .Mymodule
export mut1,mut2
function mut1(a)
a.x = -1
end
function mut2(a::point)
a.x = -3
end
end
#test.jl
include("Mymodule.jl")
using .Mymodule
include("Mymodule2.jl")
using .Mymodule2
a = getP()
println(a.x)
function mut3(a::point)
a.x= -2
end
mut3(a)
mut1(a)
mut2(a)
Even though mut3() and mut1() works; mut2() does not. and gives the following error message:
ERROR: LoadError: MethodError: no method matching mut2(::point)
Closest candidates are:
mut2(!Matched::Main.Mymodule2.Mymodule.point) at /home/saadmahmud/Documents/Halite/testjulia/Mymodule2.jl:11
Stacktrace:
[1] top-level scope at none:0
[2] include at ./boot.jl:317 [inlined]
[3] include_relative(::Module, ::String) at ./loading.jl:1044
[4] include(::Module, ::String) at ./sysimg.jl:29
[5] exec_options(::Base.JLOptions) at ./client.jl:266
[6] _start() at ./client.jl:425
in expression starting at /home/saadmahmud/Documents/Halite/testjulia/TestMain.jl:12
The only difference between mut1() and mut2() is that I defined the input type. What am I doing wrong?