What is the preferred way to use multiple files?

EvgeniyMist
Mon, 04 Nov 2019 08:35:07 +0000
General Usage

I wanted to structure my code by dividing it into several files. But I ran into some problem. So, in its simplest form, I have 3 files:
main.jl

module main

include("structs.jl")
include("functions.jl")


first_point = structs.Point(1.5, 1.5)
print(functions.distance(first_point))

end

functions.jl

module functions

include("structs.jl")

export distance


function distance(point)
    return (point.x^2+point.y^2)^0.5
end

end

structs.jl

module structs

export Point


mutable struct Point
    x::Float64
    y::Float64
    Point(x, y) = new(x, y)
end

end

And when i try to run main file I get this error:
ERROR: LoadError: MethodError: no method matching distance(::Main.main.structs.Point)
Closest candidates are: distance(::Main.main.functions.structs.Point)
So what’s the problem?

16 posts - 9 participants