But in a larger project I may want to wrap all the consts in another module M.
# Opening a new julia REPL
julia> module M
const m = 0
end;
julia> import .M: m
julia> m
0
julia> module M # redefine
const m = 1
end;
julia> import .M: m # update
WARNING: ignoring conflicting import of M.m into Main
julia> m # update fails
0
.
I wonder if the m should be updated after the second execution of import .M:m?
PS I know that I can use M.m directly, but that’s anything but convenient—that’s not the desired style of usage.
In a larger project, the recommended workflow is to create a package and use Revise.jl. It works really well, and should (among other benefits) speed up your execution over include-based workfows. using M.m should work fine and be updated automatically if M is a package.
Import statements aren’t assignments and currently cannot replace a previously imported variable. When you redefined module M, which is actually a const reassignment for the variable M, you threw away the only convenient reference to the old module which you could have reassigned m: @eval M const m = 1. As mentioned, Revise makes these reassignments easier for packages and includet files by processing source code changes. If you’re evaluating everything by hand in the REPL so Revise isn’t applicable, you can still save some typing by REPL.activate(M) entering the module M in the REPL and typing the direct line const m = 1.
It would be interesting if redefining modules could change the old module’s variables’ imports into other modules as part of world age, even without manual reimports, but that’s a much more difficult problem. For example, what happens to Main.m if we had instead redefined M where M.m is not assigned?
module M
const n = 1
end
Does Main.m become undefined? Do Revise’s extra reevaluations attempt to evaluate things with the undefined Main.m, which errors? Should we even introduce undefining of variables like this? As far as I know, no language that allows dynamic redefinition/reloading of modules firmly specifies answers, but in practice, reloading modules risk a mixed state between the old and new modules, so it’s heavily discouraged compared to other dynamic global data.
❯ julia
_
_ _ _(_)_ | Documentation: https://docs.julialang.org
(_) | (_) (_) |
_ _ _| |_ __ _ | Type "?" for help, "]?" for Pkg help.
| | | | | | |/ _` | |
| | |_| | | | (_| | | Version 1.12.5 (2026-02-09)
_/ |\__'_|_|_|\__'_| | Official https://julialang.org release
|__/ |
julia> import Random, JuMP
julia> Random.seed!(hash(50))
Random.TaskLocalRNG()
julia> import Pkg, Revise
julia> Pkg.activate("EM")
Activating project at `~/cems/texworks/cems13/EM`
julia> using EM
Info Given EM was explicitly requested, output will be shown live
┌ Warning: Module JuMP with build ID fafbfcfd-a7cd-70ee-b656-ce8a47bd8b3d is missing from the cache.
│ This may mean JuMP [4076af6c-e467-56ae-b986-b466b2749572] does not support precompilation but is imported by a module that does.
â”” @ Base loading.jl:2641
? JuMP
? EM
[ Info: Precompiling EM [dd2b80ec-7e5f-4d2f-a2dd-434f86dd1972] (cache misses: wrong dep version loaded (2))
┌ Warning: Module JuMP with build ID fafbfcfd-a7cd-70ee-b656-ce8a47bd8b3d is missing from the cache.
│ This may mean JuMP [4076af6c-e467-56ae-b986-b466b2749572] does not support precompilation but is imported by a module that does.
â”” @ Base loading.jl:2641
┌ Info: Skipping precompilation due to precompilable error. Importing EM [dd2b80ec-7e5f-4d2f-a2dd-434f86dd1972].
â”” exception = Error when precompiling module, potentially caused by a __precompile__(false) declaration in the module.
Info Given Gurobi was explicitly requested, output will be shown live
┌ Warning: Module MathOptInterface with build ID fafbfcfd-ecc6-dab2-1e48-bf33002016d5 is missing from the cache.
│ This may mean MathOptInterface [b8f27783-ece8-5eb3-8dc8-9495eed66fee] does not support precompilation but is imported by a module that does.
â”” @ Base loading.jl:2641
? Gurobi
[ Info: Precompiling Gurobi [2e9cd046-0924-5485-92f1-d5272153d98b] (cache misses: wrong dep version loaded (2), wrong source (2), incompatible header (10))
┌ Warning: Module MathOptInterface with build ID fafbfcfd-ecc6-dab2-1e48-bf33002016d5 is missing from the cache.
│ This may mean MathOptInterface [b8f27783-ece8-5eb3-8dc8-9495eed66fee] does not support precompilation but is imported by a module that does.
â”” @ Base loading.jl:2641
┌ Info: Skipping precompilation due to precompilable error. Importing Gurobi [2e9cd046-0924-5485-92f1-d5272153d98b].
â”” exception = Error when precompiling module, potentially caused by a __precompile__(false) declaration in the module.
What do they mean?
Edit: Maybe due to that I’ve mixed two environments.