With or without module prefix?

I see codes like

using Plots
x = range(0, 2π; length = 100)
y = sin.(x)
plot(x, y)

and also codes like

julia> using Random


julia> using Random: seed!


julia> seed!(1234);


julia> rand(2)
2-element Vector{Float64}:
 0.32597672886359486
 0.5490511363155669


julia> seed!(1234);


julia> rand(2)
2-element Vector{Float64}:
 0.32597672886359486
 0.5490511363155669

In the first case, we write simply ‘plot’ not ‘Plots.plot’, but in the second case, we have the extra line

using Random:  seed!

to write simply ‘seed!’ instead of ‘Random.seed!’.

Why?

You need to pull seed! explicitly because it is not exported.

julia> using Random

julia> seed!
ERROR: UndefVarError: `seed!` not defined
1 Like

I recommend reading Modules · The Julia Language

In general, the “default” is that you must use the module prefix. however, if the module has chosen to export a name then it will be available after using ThePackage

1 Like

Adding onto the previous responses: if you using more than one package that both export the same name and you intend to use one of them, then you’ll either have to specify the full PackageA.exportedname at each usage or using PackageA: exportedname to eliminate the ambiguity.

1 Like