I have a quick question about sub modules and scope. I have tried to search for similar questions but have not found an answer, so sorry if this has been asked before:
I have created a project directory with the following modules
module Calculator
export interest, rate, plusone
include("Plus_one.jl")
"""
interest(amount, rate)
Calculate interest from an `amount` and interest rate of `rate`.
"""
function interest(amount, rate)
return amount * (1 + rate)
end
"""
rate(amount, interest)
Calculate interest rate based on an `amount` and `interest`.
"""
function rate(amount, interest)
return interest / amount
end
end # module
~
and the Plus_one.jl is here:
#Plus_one.jl
module Plus_one
export plusone
plusone(x::Int) = x +1
end #module
~
From my understanding, include(“Plus_one.jl”) is the equivalent of copy and pasting that code into my Calculator.jl. I export plusone from module Plus_one into the Calculator scope, and then I export it again from there into the scope of whatever uses Calculator.
However, when I start a Julia Project in this directory and “use Calculator” I get unexpected behavior. interest and rate are exported as expected. If I type either “interest” or “rate” into the repl it recognizes it as a function. However if I type plusone into the repl I get an error. It recognizes Calculator.Plus_one.plusone, however, I don’t understand why plusone is not getting exported into the global namespace?