The code for Julia packages (also called libraries) is contained in a module whose name starts with an uppercase letter by convention, like this:
# see the code in Chapter 6\modules.jl
module Package1
export Type1, perc
include("file1.jl")
include("file2.jl")
# code
mutable struct Type1
total
end
perc(a::Type1) = a.total * 0.01
end
This serves to separate all its definitions from those in other modules so that no name conflicts occur. Name conflicts are solved by qualifying the function by the module name. For example, the packages Winston and Gadfly both contain a function plot. If we needed these two versions in the same script, we would write it as follows:
import Winston
import Gadfly
Winston.plot(rand(4))
Gadfly.plot(x=[1:10], y=rand(10))
All variables defined in the global scope are automatically added to the Main module. Thus, when...