Rename just one of imported names with "using"

I would argue that the import/using-as syntax should be preferred because not all exported variables are const, and their reassignments are reflected by imported names, not variables assigned in other modules. The difference doesn’t matter in this specific case because the exported Point is const.

julia> module A
         export x
         x::Int = 0
       end;

julia> x::Int = -10; # let's make a name conflict

julia> using .A  # non-conflicting names would be imported fine
WARNING: using A.x in module Main conflicts with an existing identifier.

julia> using .A: x as xA  # rename for import
 │ Attempted to find missing packages in package registries but no registries are installed.
 └ Use package mode to install a registry. `pkg> registry add` will install the default registries.


julia> const xA2 = A.x ; xA3 = A.x ;

julia> @eval A x+=1; # increment x in module A

julia> A.x, xA, xA2, xA3 # only the import links the names
(1, 1, 0, 0)
1 Like