Passing data as function arguments

The first solution is to pass the required data as a function argument. Suppose that the payment function from the Mortgage sub-module can take a days_per_year keyword argument, then the Calculator module can just pass the value as follows:

# Calculator.jl
module Calculator

const days_per_year = 365

include("Mortgage.jl")
using .Mortgage: payment

function do_something()
return payment(1000.00, 3.25, 5; days_per_year = days_per_year)
end

end # module

Hence, the Mortgage sub-module does not really need to reference the days_per_year symbol from Calculator anymore, reducing any unnecessary dependency.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.191.157.186