I work on a numerical code solving two closely related problems. The following seems a good code structure to me:
module Problems
common_function(i) = println("Solving problem ", i)
module Problem1
solve() = common_function(1)
end # module Problem1
module Problem2
solve() = common_function(2)
end # module Problem2
end # module Problems
Unfortunately, it doesn't work: running Problems.Problem1.solve() results in ERROR: common_function not defined. Can this be fixed?
Remark: I have more than just one function per module such that replacing the Problem1 module with a problem1_solve() function would not be a very nice solution.
In version 1.0, you have to import from the relative path to the parent:
module Problems
common_function(i) = println("Solving problem ", i)
module Problem1
import ..Problems: common_function
solve() = common_function(1)
end # module Problem1
end # module Problems
This also works with using ..Problems.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With