Structuring Julia Project

Hi Community,

I’m trying to structure my Julia Project but failing to import modules from one dir to another dir. Below is my Project Structure

|--Algorithms
    |-- src
       |--Algebra
             |-- algebra.jl
             |-- Testalgebra.jl
       |-- maths
             |-- maths.jl
             |-- Absolute.jl
    |-- Algorithms.jl

I’m trying to import Module Maths defined in maths.jl to TestAlgebra.jl, But I’m having no clue. Getting below Error Message.

WARNING: could not import Algebra.Maths into Algebra

Note: I don’t want add include in TestAlgebra.jl as I’ve already added in Algorithms.jl

The contents can be found in this link.

Thanks
Akhil

Here is the code peiced together with the includes removed

module Maths
	function abs_value(x)
    	return x>0 ? x : -x
	end
end

module Algebra
	import ..Maths
	function add_value(x)
    	return Maths.abs_value(x)+5
	end
end

print(Maths.abs_value(-98))

Notice that ive changed .Maths to ..Maths because its in a parent module

1 Like

See also the documentation here.

Thanks Graham, for the solution.

Is there a better way or standard Julian way to write Imports.

In Algorithms.jl File, the code doesn’t speaks from where module - Algebra got imported:

include("maths/maths.jl") # Maths Directory
include("Algebra/algebra.jl")
print(Algebra.add_value(-98))

Code maintainence will be an issue if codebase becomes larger. How can I address this ?

For most projects I try not to use sub modules. I divide projects into separate files or even folders, but generally they are usually just all included in one single module. But that’s just me.

1 Like